Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make a difference if I clean up my uses clause if the removed units are still used in other units?

Personally I like it if my uses clauses are as small as possible, but in many applications the really big units (in terms of bloating the executable) like Forms or VirtualTrees are needed in at least another unit anyway.

So: Does it make a difference if I clean my uses clauses even if in the end no unit is removed from the project? If so: In what way? And: Is cleaning the uses clause something which should be done as soon as possible or can it wait until I find an unused unit by chance?

like image 500
Daniel Rikowski Avatar asked Apr 18 '09 18:04

Daniel Rikowski


2 Answers

If it's used elsewhere in the project, it won't make much of a difference, except to produce cleaner code that's easier to read. There are a few minor things it might affect, though.

Compilation order: The compiler decides what order to compile units in based on which units use which units. If you remove a unit from the uses clause of an early unit, that might cause the used unit to be compiled later in the compile cycle. This may not sound like much, but bear in mind that initialization sections run in the same order as the units were compiled. This really shouldn't make much of a difference to your project, though.

CodeInsight: When you pull up the code completion drop-down, it will offer choices based on all the units currently available. You can reduce the number of choices it has to filter through--and thus the amount of time it takes to pull the bloody thing up!--by reducing the number of units you're using. (No, I'm not bitter. Why do you ask?)

like image 128
Mason Wheeler Avatar answered Sep 24 '22 12:09

Mason Wheeler


Generally no. If a unit is used once, anywhere in the project, it doesn't matter how many more times it's used. Conversely, it doesn't matter how many places you remove a unit from if it's still used at least once somewhere. The compiled program will behave the same, and it will have roughly the same size.

The only difference would be in the order of unit initialization and finalization sections. Unit-usage order affects the order those sections are executed in, although the precise effect has never been documented (so try not to rely on initialization order).

But I still encourage you to clean up your unit lists, for the same reason you're encouraged to clean up your variable lists and your parameter lists. When you get rid of the stuff you don't need, it makes it easier to read the code you've kept because you can be reasonably confident that what you're reading gives an accurate picture of what the code does. If your code mentions a bunch of units but never really makes use of them, then the next time you or someone else looks at the code, there's a good change you're going to spend some time trying to find where your code uses the facilities of those units. (You'll say to yourself, "Hmm, this code includes Graphics, but I can't see where it draws anything. I'd better take another look, because I didn't think this code had any responsibilities like that. Hey, co-worker — can you take some time out of your day to tell me where this unit draws things?")

like image 32
Rob Kennedy Avatar answered Sep 22 '22 12:09

Rob Kennedy