On Mon, Jan 07, 2008 at 02:52:57AM -0600, Gabriel Sechan wrote:
It is? I've never heard that. In fact, I frequently hear (and agree with) the exact opposite- put every declaration at the top so that you can easily find the declarations of all variables. As a bonus, you can read the variables used and their types at the begining. Typically, if I know what you're going to be using and the name of the function, I can guess how you're going to do something before you do it. It makes the code far more readable. The only real exception is index variables, like loop counters. This is honestly the first time I've *ever* heard of it being considered bad style.
C++, Java and C# all allow variables to be declared in the midst of a block. C99 also added this to the C language. Someone at least has thought this was useful. I think the guideline comes from Bertrand Meyer's "Object Oriented Software Construction". I don't have the book here, so I can't look it up right now. The idea is that you never create a variable until you have a valid value to put in it. I don't have a lot of code handy to look at, but this certainly seems to be the style of the C# code I do have around. I've found guidelines stating either. I'm also used to functional programming where variables, well, don't vary, and you can't assign them until you have a value to put in them. Dave -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
