Garth Hjelte wrote: > I'm not sure I agree with this. I think it's fairly possible.
If I write code that maximizes its readability (without comments), it will generate slower code. Code that is maximized for optimum object code generation tends to be ugly to the reader. You simply can't have it both ways. Better to maximize your code for its intended purpose and let the comments do their part. Do the experiment yourself and take a piece of code and maximize it for both ends of the spectrum. > Brandon, you sound like you are experienced in this, so can you > comment on why most programming books (the good ones, the > standards above the standards) advise that you declare variables > as close as possible to the usage? And most of these don't even > debate it - they state the principle and back it up, but rarely > devote anytime to a contrary opinion. People have already stated why they go for this position, but it really boils down to a matter of perspective. Like I have stated before in this thread by asking the question what is more expensive? If you drill down on this question on purely technical basis you would come to the conclusion you should put the DIM in the block, but this point of view ignores the big picture. It is more expensive to make the code harder to read. People in this thread have stated that they think that putting the DIMs all over the place is more readable, but that is from their point of view it is more readable to them and this is circular reasoning. I have given examples why organizing it in certain patterns is better for the brain to understand, otherwise in my table of context example books would have a far different look and feel than they do today and that should tell you something. Let's say your average method is 50 NCSL, is it not a negligible thing to move the DIMs to the top? You are in the scope of the method, so how much closer do you really need to be? In general there would be no measurable speed difference where you declared them. Optimizing by putting the DIMs in blocks is meaningless. Think of what order of magnitude we are talking about here in time to initialize a variable (concept of premature optimizations comes into play). Bottom line, putting your DIMs in the blocks ignores the big picture. There are so many concepts like these that are just fads that keep getting recycled over time. I was once talking to a relative of mine who had been an engineer all his life (he's now in his 80s) and he was telling about all sorts of different things that they used to do and how they got recycled over the years and are still getting recycled today. Most positions like these are reactionary concepts to what once was previously done. Just wait, and you will observe this recycling in action. People like to take positions because it is different from what is currently done because it gives them a sense of something new. I prefer to do things because they work. _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
