<div class="gmail_quote">On Tue, Oct 19, 2010 at 12:23 AM, Jürgen Hestermann <span dir="ltr"><<a href="mailto:juergen.hestermann@gmx.de">juergen.hestermann@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Reimar Grabowski schrieb:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
for (int i = 0;...)<br>
Can't see anything wrong. I use declaration of variables inside blocks quite often in Java and C++ but have never missed it in pascal. Please enlighten me. What is so bad about creating temporary variables inside blocks instead of the beginning of a function in a language that supports it?<br>

</blockquote>
<br></div>
I never thought about doing such declarations in Pascal.<br>
Although I would not be against it in general (provided<br>
that all identifiers have to be different)</blockquote><div><br></div><div>That seems like an arbitrary restriction, given that Object Pascal *already* allows multiple variables to have the same name *and* be declared somewhere other than the top of the function. Think of exception handlers. I don't know about everyone else, but my exception variables are all always named e.</div>
<div><br></div><div>I could understand disallowing variables from *shadowing* other local variables of the same name (it's legal in C, but better compilers warn about it), but I see no reason for the language to require variables from different local scopes to have unique names. Write that into your local coding guidelines and enforce it in code reviews, not the language spec.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> I see one (small) disadvantage:<br>
<br>
If you want to know the number of bytes pushed to the stack<br>
(i.e. in a recursive function) then you don't have the declarations<br>
at one place anymore but they are spread over the code which would make it hard to get an overview.</blockquote></div><div><br></div><div>Definitely small. It's already hard to do since you don't know how much stack the compiler will allocate for temporary variables. (If the function's small enough that you *can* predict the compiler's temporary usage, then it's probably also small enough that you can count all the variable declarations no matter where they appear.)</div>
<br>-- <br>Rob<br>