TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DANIEL JONES
from: AARE TALI
date: 1997-08-06 09:37:00
subject: Sunir ventures into C++

 > AT>  > As for declarations, why shouldn't I be able to
 > AT>  > declare a variable where
 > AT>  > I use it?  I especially like for(int i = 0; i < 100;
 > AT>  > i++) type
 > AT>  > declarations.  It makes it quite clear that i is
 > AT>  > simply a placeholder.
 > AT>    I don't like the idea too much. When you find some variable in th
 > AT> the program, you can't find declaration in few logical steps (the co
 > I'm not sure I follow you here.  When you find a
 > variable, the
 > declaration should be right there.  No steps are
 > necessary.  No paging
 > back to the top of the page or function.
    void foo()
    {
        int i;
        for (i = 0; i < 5; i++)
            do_something(i);
        for (int j = 0; j < 5; j++)
            do_something_else(j);
        if (i < 5)
            not_everything_was_done_with_i();
        if (j < 5)
            not_everything_was_done_with_j();
    }
   Simple example. When you see the first 'if' with i you go to the top of 
the compound statement and you find the declaration. If block would be 
nested, you probably have to go to the beginning of the outer block, and so 
on, and if everything else fails, look at the globals. Simple, there are few 
well determined steps to find the declaration (except the global variable 
list). Second 'if' - you have to go back all the way to the top of the 
function looking at the _every_ code line to see if j was declared somewhere 
in the middle of nowhere. And if you miss it in the 'for' statement few 
times, you'll search global variable list next, and later you would put the 
declaration into place where it should be (read: where you can find it) - at 
the beginning of the block.
 > You must scan backwards to the beginning of the
 > function (or at least
 > the beginning of the block) in C because all variables
 > must be declared
 > there. In C++, you shouldn't have to scan back at all.
   In C you have to _go to_ the beginning and look around there, in C++ you 
have to _scan_ looking around all the way. Unless you write 5-line-functions 
where you can't put declaration smore than 5 lines away from the line where 
you used the variable last time.
 > AT>      and the for (int i...) is not so obvious
 > AT> to be noticed at the first pass.
 > I suppose that's a matter of what you're used to.  I
 > find it quite
 > obvious.
   OK with me, but i usually don't look at assignments, for, do or while 
statements when i try to find variabler declarations ;)
---
---------------
* Origin: A point in the middle of nowhere (2:490/31.3100)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.