Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.unit0.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.16.MISMATCH!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!zen.net.uk!hamilton.zen.co.uk!shaftesbury.zen.co.uk.POSTED!not-for-mail Date: Fri, 07 Oct 2011 12:20:39 +0100 From: RedGrittyBrick User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: in praise of [loosey goosey] type checking) References: <4e8ed97f$0$2921$fa0fcedb@news.zen.co.uk> In-Reply-To: <4e8ed97f$0$2921$fa0fcedb@news.zen.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 42 Message-ID: <4e8ee082$0$2553$da0feed9@news.zen.co.uk> Organization: Zen Internet NNTP-Posting-Host: 8cda7474.news.zen.co.uk X-Trace: DXC=hSIVZIAaeXTHb On 06/10/2011 07:33, Roedy Green wrote: >> I changed the result of a widely used method from boolean to int. The >> neat thing was the compiler (actually the Intellij syntax checker) >> made sure I fixed up every invocation of that method. It would not let >> me forget even one. >> >> Imagine a language with loosey goosey type checking where it was >> entirely up to you entirely to ensure all the invocations were >> corrected. You could never be sure. > > The problem might not arise. Depending on which language you mean and > how you apply your knowledge of the language to the intended use of the > method. > > For example, in Perl, if I changed a method so that it returned an > integer instead of a boolean I would do so in such a way that any > existing code calling that method could continue to function unchanged. > Perl can quite happily treat any integer as a boolean, I would just have > to ensure that I return an integer value that will be treated as (say) > false under circumstances where the original method would have been > expected to return false. To illustrate: Let's say I have an object "store" and I have a method "contains()" that takes an argument and returns boolean telling us if the store contains a matching element. I might use it thusly in a zillion places if ($store.contains($APPLE)) { $store.sell($APPLE); } else { die "Out of $APPLE!"; } Now lets say I change contains() to return a count instead of a boolean. My zillions of places treating the return value as boolean still work unchanged. Hurrah for loosey goosey! -- RGB