The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,565 other followers

Where do you place your unit uses?

Posted by jpluimers on 2019/04/18

Over the years, I have had the question of where to put uses list entries a lot.

Last year, there was one again from a very experienced developer: [WayBack] Where do you place your unit uses? Over the years, I’ve come to preferring to place my uses in the Interface section only, even if its types, constants… – Lars Fosdal – Google+

The answer is really simple, and comes down to this:

  • use only the units you need (Law of Demeter)
  • use the units as close as possible to where you need them (this helps Minimizing Scope which is related to Information Hiding and the Proximity Principle)

Besides these Clean Code and Code Complete arguments, there is another very important argument:

The larger the scope of a unit, the more resources it takes to compile your project.

This gets worse when you have cycles in your unit dependencies.

I think it gets more than progressively worse; I have seen ~5 million line projects use close to 2 gigabytes of RAM during compilation when they had deep/long cyclic dependencies, forcing a full project build with DDevExtensions configured correctly in order to avoid out-of-memory at all.

For the above question, the poll seems to indicate the public at large gets it right:

References

A few tips from the thread:

Just a note: I use the Uses Report in Peganza Pascal Analyzer to identify the candidates for moving to the interface section. The task itself is easily done with Ctrl-Alt-Shift-Up (or Down) from MMX Code Explorer, which moves the unit under the cursor to the other section.
By the way I highly recommend this brilliant expert:
github.com – rfrezino/RFindUnit
+Lars Fosdal Use a proper static analysis tool on a regular basis. The Unit Dependency Analyzer as part of MMX Code Explorer can tell you that pretty fast.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: