Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: About java program. Date: Tue, 18 Jun 2013 00:13:59 +0200 Organization: A noiseless patient Spider Lines: 56 Message-ID: References: <324f929f-772e-4004-81e1-6b454cdae794@googlegroups.com> <19wnriq53qxel.u9rt8wy6z52g.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 17 Jun 2013 22:08:59 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bde5ff8284ca7404af7ed4ef6bf90cf7"; logging-data="12914"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19p9ts28OgO4hcgNLUviWwL" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: Cancel-Lock: sha1:sqYGPj7QEEvPQdPfKHo2t6NHuPY= Xref: csiph.com comp.lang.java.programmer:24443 On 17/06/2013 20:49, Eric Sosman allegedly wrote: > On 6/17/2013 2:32 PM, Joerg Meier wrote: >> [...] >> Personally, I found your example considerably harder to read than the one >> liner, as well as harder to read than what would have been my solution: >> >> private boolean askYesNoquestion (String str){ >> if(str.equals("yes")) >> return true; >> >> return false; >> } > > Or, for even greater clarity: > > private boolean askYesNoquestion(String str) { > boolean yes; > boolean no; > if (str != null && str.equals("yes")) { > yes = true; > no = false; > } else if (str != null && str.equals("no")) { > no = true; > yes = false; > } else { > yes = no = false; > } > return (no != true && yes != false) == true; > } Call me sceptical, but I'm sceptical: I find that one-line return statement kinda confusing. For more clarity, it should be encapsulated: public static boolean isTrue( boolean b ){ boolean ret; if( b == true ){ ret = true; } else { ret = false; } return ret; } private boolean askYesNoquestion(String str){ ... return isTrue( ! isTrue(no) && isTrue(yes) ); } Better, dontcha think? ;) -- DF.