On Sun, Jun 1, 2014 at 9:36 AM, Glen Mailer <glenja...@gmail.com> wrote:
> Hi everyone, I'm looking to get some opinions on code style. > > Specifically, I like to write my code in a top-down. > > What I mean by that is that within a file the highest-level functions sit > at the top, and are implemented in terms of lower-level functions further > down. > ... > The problem now is because of the single-pass nature of clojure's > evaluation - simply writing code like this doesn't actually work. > > There's a few approaches i've seen from reading other's code: > > 1. Have an "impl" namespace which contains all of the helper functions for > the public "interface" > 2. Make use of (declare) forms where necessary to improve forward > readability > 3. Don't worry about source order, just have the api functions further > down the file and live with it > 4. Put your helper funcs ("defn-" stuff) in helpers.clj, without a call to ns at the top, then (load "helpers") at the top of the file that uses them. You still get the effect you're looking for, with a one line "preface" that tells the reader where to look for more info. Seems to work in a little test app (lein new app topdown): ;; in topdown/core.clj: (ns topdown.core (:gen-class)) (load "helpers") (defn -main "I don't do a whole lot, but I do call an internal function that lives in another source file." [& args] (hello)) ;; in topdown/helpers.clj: ;; internal topdown helper fns (defn- hello [] (println "Hello")) HTH Gregg -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.