On Mar 6, 5:20 am, Paul Drummond
<
paul.drummond.webm...@googlemail.com> wrote:
> When looking at boot.clj, I can't help but feel the positioning of
> meta data and the affect it has on the style and indentation of the
> rest of the definition makes the code difficult to read. \
Agreed. See the discussion here:
http://groups.google.com/group/clojure/browse_frm/thread/fa84dc8f785a9c32/d6dee9c1a79f953d?#d6dee9c1a79f953d
> Take the
> first definition in boot.clj for example:
I think it is important to avoid the first few definitions in boot.clj
as examples, as during this part of the bootstrap process many aspects
of Clojure do not yet exist - no defmacro, no defn, many functions are
not yet defined. Things here are inevitably going to be uglier than
elsewhere. For instance :arglists is created by defn and normally
never seen in the source.
> I just wanted to start a discussion about this and determine whether
> you are up for suggestions Rich but I understand if it's low priority
> right now or if you are sticking with the style for good reasons. I'm
> sure I *will* get used to it if it's here to stay :)
>
As discussed before, I have gone ahead with putting in the docs and
some other metadata so we can all get some experience with it, but it
will change.
> At the very least, moving the name above the meta data would be a
> major improvement because the reader (as in person reading the code)
> would see the name immediately after the def and then everything
> regarding the definition would be indented correctly below:
>
As suggested in the prior discussion, this is the most doable. Having
lived with it a bit, I most miss the name at the start of the defn, so
I know what the rest is about.
> However, IMO a far better approach (and more radical change) would be
> to promote doc strings to make them part of the def as I believe they
> are important enough to stand out from the meta data.
> And a function would look like this:
>
> #^{:tag Boolean }
> (defn nil? [x]
> "Returns true if x is nil, false otherwise."
> (identical? x nil))
>
As Marko mentions in a subsequent message in this thread, putting the
args before the docstring doesn't work for fns overloaded on arity.
I'm not sure I like having the other metadata precede the line with
the name, again burying it, but there is some precedent as you say,
albeit in language without a reader and code-as-data.
I also think using an editor with good highlighting/folding changes
the story, sometimes dramatically. That's not an argument for the
status quo, but there will be limits to what indentation and order
alone can do.
I'm open to suggestions and may have some time to work on this. One
thing I'd like to remind everyone is that even though these attributes
end up being metadata on the vars, they need not be expressed as
metadata on the source forms. Using metadata on the name form in the
first cut was just a convenience, and has some nice properties for
macros, but if the data-to-become-the-metadata ends up inside the defn
form, it is just part of defn's syntax, which is already composed of
ordinary forms and order dependencies and could have others.
Rich