I've seen discussions over time suggesting that Clojure's readability is enhanced by having more bracketing characters in play that just parentheses. I agree with that.

I recall Chouser (corrections welcome) noting that in Clojure code, parentheses are used primarily for "forms" (applications of special forms, macros and functions) and perhaps a good goal would be to avoid using them elsewhere. Doing so would more strongly enforce the close association between parentheses and "calls".

I experimented with this in an "ns" form and found that because of the coolness of the seq abstraction, it appears that all uses of lists in an "ns" form can be replaced by vectors and still work the same.

Here's an example:

Currently the canonical form for ns is a mixture of lists and vectors within its clauses:

        (ns clojure.contrib.miglayout.internal
          (:import (java.awt Component))
          (:use (clojure.contrib
                 [except :only (throwf)]
                 [fcase :only (fcase)])))

If we reserved parentheses only for the ns form itself, this could become:

        (ns clojure.contrib.miglayout.internal
          [:import [java.awt Component]]
          [:use [clojure.contrib
                 [except :only [throwf]]
                 [fcase :only [fcase]]]])

The ns form is an interesting case because Rich has expressed a vision that it will be parsed and used not only by Clojure itself, but also by tools/IDEs to determine what a source file contains and what it depends on. As such, its "acceptable syntax" is governed (even more than elsewhere in Clojure code) not primarily by "what works in Clojure", but rather by "what is its canonical, documented syntax".

Should we consider changing the canonical form for ns to use vectors for all of its sequential sub-forms?

Benefits:

        - canonical form would be easier to describe
                - less to remember and get right than with the current mixed 
syntax
        - makes it clear that (:use ...), for example, is not a "call"
        - supports the "parentheses imply form application" notion

Downside:

- Nested uses of square brackets are arguably less readable than a mixture.
                - matching brackets by eye is easier when there's a variety

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to