Board index » delphi » Question about the advantage of small Units

Question about the advantage of small Units

I'm a bit confused.

I was reading in one of my old text books about creating a unit.  The
question asked you to remove the Set statements from a program and put
them into a unit call Setunit.pas.

My question is this:

What is the purpose or advantage of placing something as short as the
following into a unit?  Then calling that unit from within the current
program.  

      AlphaUpper : set of 'A'..'Z';
      AlphaLower : set of 'a'..'z';
      Space : set of ' '..' ';

Maybe I totally missed the point of the question or I failed to use the
Set commands effectively.

Thanks for your time on this matter

Bill Luchsinger

 

Re:Question about the advantage of small Units


Quote
Bill Luchsinger wrote:

> I'm a bit confused.

Aren't we all?

Quote
> I was reading in one of my old text books about creating a unit.  The
> question asked you to remove the Set statements from a program and put
> them into a unit call Setunit.pas.

> What is the purpose or advantage of placing something as short as the
> following into a unit?  Then calling that unit from within the current
> program.

>       AlphaUpper : set of 'A'..'Z';
>       AlphaLower : set of 'a'..'z';
>       Space : set of ' '..' ';

> Maybe I totally missed the point of the question or I failed to use
> the Set commands effectively.

I think that this is mostly an issue of preference. It certainly doesn't
have anything to do with the use of sets particularly. I have at times
put commonly used definitions into ridiculously small units just because
I had so many programs which used identical definitions.

The set definitions above seem to me to  be generic enough in nature to
warrant such usage if the programmer uses these sets (in Case
statements, for example) in many different programs. Properly defined,
unused definitions will be stripped from the final code by the smart
linker.

Using units this way makes coding easier by making it easier to recall
where the definitions are. It is much easier to remember to include
COMMON.TPU in all your programs than to recall where you last used a
particular declaration and then finding/copying/pasting the declaration
into the current code. In many cases, it helps with program readability
as well.

AME

Other Threads