Gustav Brock
gustav at cactus.dk
Tue Jul 8 11:56:55 CDT 2003
Hi Arthur
His message is clear, that every standard or rule that may lead to
more understandable code should be applied.
However, those examples are bad. Quite often a loop is nothing more
than a loop and it's quite obvious that x is nothing more than a
counter.
More importantly, and what is not clear, is: why 0 To 10?
Where do these numbers come from?
Thus you should write:
Const clngMonthThirdFirstStart As Long = 1
Const clngMonthThirdFirstEnd As Long = 10
Const clngMonthThirdSecondStart As Long = 11
Const clngMonthThirdSecondEnd As Long = 20
...
For x = _
clngMonthThirdFirstStart To _
clngMonthThirdFirstEnd
...
<do stuff>
...
Next
...
It may look long-winded but it does pay off when you some day have to
look at that old code which you _did_ forget everything about ...
I prefer type-prefixes too. They prevent hitting reserved words or
names of objects; in fact when I look at some of my oldest code not
using prefixes it appears sloppy, and quite often I have to read back
to be sure of a type of some variable. Intellisense doesn't change
that.
/gustav
> The following excerpt comes from
> http://www.vbcity.com/forums/faq.asp?fid=30&cat=General&#TID30570. If the
> subject interests you, I suggest you visit there. Here is a preview:
> <article>
> What are coding standards?
> Coding Standards can relate to all areas of programming. In this FAQ we are
> concerned with trying to convey information about an object by using a
> naming convention. Naming your objects in a predefined way means you can
> tell more about an object purely by the way it is named.
> Lets take a standard Looping variable. If I call my variable 'X' it is not
> obvious what it does :-
> Code:For X = 0 to 10
> ...
> Next X
> If we change the name of 'X' it becomes obvious what it is doing :-
> Code:For Index = 0 To 10
> ...
> End Index
> Although 'X' is quicker to type, it is unclear what it is doing. This
> becomes more obvious when we have loops in loops:-
> Code:For X=0 to 10
> For Z=0 to 100
> ...
> Next Z
> Next X
> For ParentIndex = 0 To 10
> For ChildIndex = 0 To 100
> ...
> End ChildIndex
> End ParentIndex
> The second version is a lot clearer and explains what is happening in the
> loops purely by using 'Explanatory Names'. You may be tempted to save typing
> by using Letters or short names. Resist this temptation and Cut and Paste
> the name while using it.
> </article>
> This does not apply to Access, except in narrow areas like creation of types
> or classes, but it's an interesting point nonetheless. Like many other
> listers, I have habitually created all my variables with type-prefixes.
> Given intellisense, this may be obsolete.
> What do you think?