At 12:54 AM 5/2/2007, you wrote:

>My experience is with variable declarations at the top so I haven't
>gotten used to declaring them later in code, but I can see some value
>in doing so. However, the one aspect that confuses me is how do you
>"undeclare" a variable? Can you? I mean, how else would the variable
>only be good for that block?
>
>For instance, say I'm going to use a throw-away "i" variable as a
>loop counter somewhere in my code. It does make sense to declare it
>just before the loop. But how does my code know I'm done using it?
>Once I've declared it, isn't it still usable elsewhere in the
>subsequent code? And if that "i" is alive at any point after I've
>declared it, maybe I'll use it elsewhere...

You just inadvertently gave examples of why dimming at the top isn't 
such a bad idea. The point being: how granular should our idea of "scope" be?

Dimming at the top essentially says "the smallest scope we are going 
to deal with is the subroutine scope". I personally prefer that, and 
respect others prefer something else.

This is a crude way of saying it, but if you are going on a trip, you either:

-Pack everything you need at home, carry a large suitcase, satisfied 
that you have everything you need and don't have to stop at stores 
for necessities, you have less worry, and that you have the 
flexibility of using something before you first thought you needed it.

OR

-You want to travel lighter, and "pay as you go" as far as things you 
need. You loose some flexability and need to think as you go, but you 
move faster and lighter.

I think both approaches are valid.

Or, put another way:

In RB I like dimming at the top. I get a chunk of code where I see 
everything I'm going to use in this subroutine. But in C++, I like this syntax:

for (long i = 0; i < thisSize; i++) {
...
}

A loop counter just isn't useful anywhere besides within a loop. And 
I feel this is a clean way (inline) to dim something while not adding 
intrusive lines of code.

OR

if (BigValue > 99999) {
         int workvar = BigValue + SUPER_CONST;
         ...
         BigValue = workvar - OTHER_CONST;
}

For some reason C++ (or related to the IDE I use) feels streamlined 
to me using some (not necessarily all) variables in finer scopes then 
the subroutine scope.

But even in C++, with the Dimming not automatically initing a 
variable, it's especially crucial for me to put the variables up top, 
so i can easily see that I am initing them properly.

The issue is the same - I like the way it looks. And if I'm happy, I 
write happy code.

All programming guidelines aren't, and shouldn't be, so subjective. 
But I think this one is.

* * * * * * * * * * * * * * * * * * * * * * * * * * *
| Garth Hjelte                                      |
| Customer Service Representative, President        |
| Chicken Systems, Inc, Rubber Chicken Software Co. |
| 714 5th Street SE                                 |
| Willmar, MN 56201 USA                             |
|                                                   |
| 800-8-PRO-EPS    Toll Free Order Line (US Only)   |
| 320-235-9798     Tech Support, Sampler Questions  |
|                  International Line               |
| 360-838-7689     Fax                              |
| Product Sales:   [EMAIL PROTECTED]             |
| Product Support: [EMAIL PROTECTED]           |
| Sampler Q+A:     [EMAIL PROTECTED]                |
| Web Page:        www.chickensys.com               |
* * * * * * * * * * * * * * * * * * * * * * * * * * *

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to