For instance, in Java ...

tmpString = JOptionPane.showInputDialog("What is your foobar?");
finalFoo = Double.parseDouble(tmpString);

instead of ...

finalFoo = Double.parseDouble(JOptionPane.showInputDialog("What is
your foobar?"));


I translate this into Clojure as something like ...

(def final-foo
  (. Double parseDouble
    (. javax.swing.JOptionPane showInputDialog "What is your foobar?")))


Obviously this a contrived example, and I didn't compile it to make
sure it works. Still, you can easily imagine more complex code having
many more levels of indentation.

How would I break up the Clojure version in a Clojure-esque manner?






On Sat, Sep 12, 2009 at 4:42 PM, Sean Devlin <francoisdev...@gmail.com> wrote:
>
> Could you post an example?  It'd be easier to comment on it.
>
> On Sep 12, 6:32 pm, Terrance Davis <terrance.da...@gmail.com> wrote:
>> Commonly, I break down complex lines of code into several easy to
>> follow simple lines of code. This results in many temp variables that
>> are not intended to be used anywhere else in the code. Sometimes I see
>> a method reusing common primitives and objects (like ints and
>> Strings), so to prevent verbosity (meaning many unnecessary variable
>> definitions), I define variables named something like 'tmpString' or
>> 'tmpInt' with a local scope and reuse them locally.
>>
>> This is all to prevent verbose hard to read code. I can read through
>> the simplified code ignoring variables with the visual tag of 'tmp'. I
>> also benefit from the simpler code that does not "chain" several
>> commands in one line.
>>
>> What is the best practice in Clojure? How do I properly break down
>> chained commands? Am I completely missing the zen of FP? ;-)
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to