Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Fuschia, President-Elect of the Bright Purplish-Green Council" Newsgroups: comp.lang.java.programmer Subject: Re: Passing a Method Name to a Method Date: Thu, 23 Jun 2011 15:46:16 -0400 Organization: IBM Lines: 45 Message-ID: References: <81h4075t4gfjglji1n033rb20025ebho68@4ax.com> NNTP-Posting-Host: 8VhVVOJhq9kx7Yha7TGFgg.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: Xnews/2006.08.24 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5598 On 23/06/2011 2:32 PM, markspace wrote: > On 6/23/2011 10:42 AM, Fuschia, President-Elect of the Bright >> >> I'll just mention here that functional programming, in this case at >> least, also gives the advantages given by object oriented programming; >> specifically, you can add another parse method by adding another (third) >> parse *function* without changing most of the other code. And generally > > I'll just mention here that this is fairly specious. Wrong. > A proper OO solution, like the ones I gave, you can add another parser > just by adding the appropriate class. The boiler plate is about two lines. 1. package foo; 2. 3. import bar.baz.ParseStrategy; 4. 5. public final class MyParseStrategy implements ParseStrategy { 6. public final Thingy parse (String input) { 7. // The actual implementation goes here 8. } 9. } I count 8 lines of non-implementation code, not 2, and 162 characters, plus eight "extra" characters per line of implementation code to indent it properly. Versus this Clojure code: (defn my-parse [input] (the actual implementation goes here)) ONE line of non-implementation code and 26 characters, plus two indent spaces per line of implementation code. 1/8 as many lines. 1/6 as many characters. 1/4 as many indent spaces per line of implementation code. And probably a shorter & sweeter implementation as well. > The interface is already done, skeleton, imports, etc are already done. > Just add a class with a method. What you gain in Java is type safety, > something not available in the "functional" languages I'm familiar with. Scala also gets you type safety, at a cost of a bit more boilerplate than the Clojure example.