Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: code generation for the ternary operator Date: Sat, 29 Oct 2011 10:50:01 -0700 (PDT) Organization: http://groups.google.com Lines: 30 Message-ID: <11864467.903.1319910601187.JavaMail.geo-discussion-forums@prap37> References: <29cla79dh934epr5n27cghvupjk77mpuqr@4ax.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 216.239.45.130 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1319910601 25710 127.0.0.1 (29 Oct 2011 17:50:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 29 Oct 2011 17:50:01 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=216.239.45.130; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9305 Wanja Gayk wrote: > I personally don't care for the byte code unless it really matters, > which is almost certainly never. So I concentrate on readability and > code style. > Among these two, I'd prefer the first variant for these reasons: > It is obviously very clear that the value "count" won't change later in > the program. It's short, concise and the brackets look like a "capsule" > that wraps the decision being made. > But if the term is getting too long, it might be a good idea to write > this, which I find even more readable: > > final int v1 = b1 ? 2 : 0; > final int v2 = b2 ? 2 : 0; > final int count = lines * 3 + v1 + v2 ; > > Still I would try to find proper names for "v1", "v2", "b1" and "b2", > like for example: > > final int optionalHeader = headerPrinted ? 2 : 0; > final int optionalFooter = footerPrinted ? 2 : 0; > final int count = lines * 3 + optionalFooter + optionalHeader; +1 to all of the above. I'm immersed in style guidance these days, and that is some of the best style guidance I've seen. -- Lew