Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 10 Jun 2011 11:31:03 -0500 Date: Fri, 10 Jun 2011 09:30:58 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Call by Result References: <95e4uuF3cvU1@mid.individual.net> In-Reply-To: <95e4uuF3cvU1@mid.individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 24 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.199.66 X-Trace: sv3-b8mYj2lNn+VMVZn5ca1Bu9cMrEHpf1PUJ+3UvjOvoGReSKHGsD1o2eQwnNzM0Mf5KEIJJKeJypGrE/l!SokPZu8zMNkGfxLcMJJxpBemRynbrtlHiBZ1fRLi70DAg+sjOC1f4k6nIDRhipXXk5DALZIGbqdQ!3Zrn36Gif3NqVNIm3+S22vN5GZ1QLepIVsFb3oYV2QyjiQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2369 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5188 On 6/10/2011 2:03 AM, Nigel Wade wrote: ... > And a 5th way could be to return the String and throw an Exception if it > did not work. Some purists may argue that failure to work is not > strictly an exception, but if it gets the job done... > My view of this is that a method should not be called "getString", or any variation on that theme, unless its primary purpose is to get a string. In that case, it should return the string it gets. Any failure to get the string is an exception relative to its purpose. Even when programming in C, I regarded the tendency to return a success/fail flag and treat the main purpose of the function as a side effect as an unfortunate but necessary ugliness. In Java, I regard it as pure ugliness, with no justifying necessity. Some people seem to confuse making something an exception in a particular interface with regarding it as a whole program failure. That makes no sense to me. If there is to be any hope of code reuse, method interfaces must be designed based solely on the method's intended function, not the overall program design. Patricia