Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Blocks for scope control Date: Sun, 15 Jan 2012 11:28:38 -0800 Organization: albasani.net Lines: 67 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net KUcHPrVV6S2dRTZailNkFgT6Q8zl9h0iYD2vdvXURtcqHIsXaKkODQkcmIZuj+1a7gKygnT/VARt/nKrWcsyNp6Qrj/3qICnCTA8zooJN5duu7x7y01PixkXvOBW6KD8 NNTP-Posting-Date: Sun, 15 Jan 2012 19:28:40 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="7wWsn92jy8aJQjoQIZ2LvJZOChpPGVR01FThTgFJgoDvhEZS76I8UFRcJzAkOY+8RGoXYdwO+so3obqNporUWs5t270grqsf6kQfiYz85Bq0B/MaoZQ7Oq878wOlleea"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 In-Reply-To: Cancel-Lock: sha1:n4Y5tIWrB2NNbAFnoP4g9SSP0vo= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11361 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. 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