Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: kensi Newsgroups: comp.lang.java.programmer Subject: Re: toward null-safe cookie cutter Comparators Date: Wed, 16 Nov 2011 12:50:51 -0500 Organization: SICN Lines: 39 Message-ID: References: NNTP-Posting-Host: boE97fIOqjAfikXEhaRruQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (CYGWIN_NT-6.0/1.5.22(0.156/4/2) (i686)) Hamster/2.0.2.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9978 On 14/11/2011 1:55 PM, Daniel Pitts wrote: > I've seen projects where a *core* library had a method "isNull" defined > thusly: > > public boolean isNull(Object o) { > if (o == null) return true; > String s = String.valueOf(o); > if (s.trim().length == 0) { > return true; > } > if ("null".equals(s)) return true; > if ("(null)".equals(s)) return true; > } Shocking, if true, since the above code won't compile. > Obviously, someone was told that "null" and "(null)" were appearing > somewhere and causing problems. Instead of tracking down the source, > they littered the codebase with these "isNull" checks. I should have my > legal name changed to "Null Null", and see how many forms on the web > reject my name :-) Why go to the hassle of changing your legal name? It's not like giving false information to large corporate marketing departments^W^W^W^Wweb forms is an offense under the law or anything. ;) At most it's a TOS violation and the account you create won't last long (cf. Facebook, Google Plus). > Imagine the following: > > // Commonly used library method handleThing. > void handleThing(Thing t) { > AnotherThing at = t.getAnotherThing() > doSomething(at); > } Comment above is wrong, should be // Commonly used Law of Demeter violation HTH. :)