Re: Blocks for scope control
On 01/15/2012 09:57 AM, markspace wrote:
On 1/15/2012 7:50 AM, Arved Sandstrom wrote:
I almost never see anyone else using these things this way.
IMO, I dislike spurious and overused indentation in code, so that's likely why
I shy away from "extra" use of braces.
for( ...some code )
{
do some init
{
do a little work
{
declare a temporary variable
}
{
declare another temporary variable
}
{
declare yet another temporary variable
}
{
declare still yet another temporary variable
{
declare a temporary variable inside
an anonymous block
}
}
}
}
vs. just one level of indentation, I believe I'd greatly prefer the latter,
especially in the long run. And the above is with 3-4 spaces for indenting,
imagine what it would look like with 8.
Since eight-space indentation violates the Java coding conventions it doesn't
deserve consideration. Code that indents eight spaces should be rejected in
code review and brought into compliance.
<http://www.oracle.com/technetwork/java/codeconventions-136091.html#262>
But your larger point is valid, and you can just do this:
for( ...some code )
{
do some init
do a little work
declare a temporary variable
declare another temporary variable
declare yet another temporary variable
declare still yet another temporary variable
declare a temporary variable inside
}
The reason to go with the supposedly "extra" braces is to guarantee that a
temporary variable is not re-used, but if a method is so long that that's a
risk there's a good chance that it's too long.
And again I say, "anonymous block" makes no sense because blocks aren't named
in the first place.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg