Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.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:46:47 -0700 (PDT) Organization: http://groups.google.com Lines: 39 Message-ID: <6394928.1369.1319910407533.JavaMail.geo-discussion-forums@prfk19> References: <29cla79dh934epr5n27cghvupjk77mpuqr@4ax.com> <4eaab738$0$5147$e4fe514c@dreader17.news.xs4all.nl> 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 1319910512 24748 127.0.0.1 (29 Oct 2011 17:48:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 29 Oct 2011 17:48:32 +0000 (UTC) In-Reply-To: <4eaab738$0$5147$e4fe514c@dreader17.news.xs4all.nl> 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:9304 Jaap Droogers wrote: > schreef Roedy Green: >> I wonder if anyone has ever looked at the byte code and/or the hotspot >> code generated by code like this: >> >> final int count = lines * 3 + ( b1 ? 2 : 0 ) + ( b2 ? 2 : 0 ) ; >> >> vs: >> >> int count = lines *3; >> if ( b1 ) count += 2; >> if ( b2 ) count += 2; >> >> I wondered how clever it is. This is just curiosity. This is not >> critical code. >> >> Which style do you prefer? > > The second: clean code! > I don't like code that I don't understand at the first glance. > Always use curly brackets: If you don't understand the ternary operator at first glance, the programming world should not use you as the bellwether of readability. > int count = lines *3; > if ( b1 ) { > count += 2; > } > if ( b2 ) { > count += 2; > } > > Don't try to do the optimizing work for the JIT compiler, she can handle > it herself very good. Good advice. -- Lew