Parens again

7 views
Skip to first unread message

Dan

unread,
Feb 3, 2010, 8:08:30 AM2/3/10
to clo...@googlegroups.com
Once a month, we get a proposal about how to remove the parens so that the language would be more usable for newbies who are afraid of them. Invariably this turns out into experienced clojure users telling that the parens aren't a problem and that they become invisible once you start indenting your code right.

This makes me wonder the following thing: Why isn't there a page on the official website that explains how to indent properly?

.Bill Smith

unread,
Feb 3, 2010, 9:09:23 AM2/3/10
to Clojure
I won't tell you what editor you ought to use, but Emacs in clojure-
mode takes care of the indentation for you. I suspect editors/IDEs
that "support" clojure do as well.

Another data point: the Clojure source code (the part that's actually
written in Clojure) is indented, and it's open source.

Bill Smith
Austin, TX

Dan

unread,
Feb 3, 2010, 9:44:24 AM2/3/10
to clo...@googlegroups.com
I'm not saying it's impossible to figure out, I'm just saying it ought to be on the website. 

Christopher Petrilli

unread,
Feb 3, 2010, 9:42:53 AM2/3/10
to clo...@googlegroups.com

As someone who came to Clojure from Python (primarily), I can tell you
that as the language gains traction, these kind of "little things" can
be amazingly valuable to people getting started who obsess over small
details. I'm an Emacs weenie of 20 years, so I don't really sweat the
indentation issue, but there's a lot of people who aren't, and for
whom there is no familiarity with Lisp. For example, how Clojure
indents is different than how I used to indent INTERLISP for example.

Something like Python's PEP8 [1] would be very useful. This would also
cover naming conventions (recently discussed in the library author's
thread), and things like that. A lot of the Python tools (like Rope
for refactoring) can also move things around to make it "fit" the
style.

Chris

[1] http://www.python.org/dev/peps/pep-0008/
--
| Chris Petrilli
| petr...@amber.org

CuppoJava

unread,
Feb 3, 2010, 11:56:09 AM2/3/10
to Clojure
As trivial as it seems, proper indentation was also my most
significant hurdle when learning Clojure. I finally was only able to
"get" s-exps after realizing:

1. That indentation is *extremely* important.
2. That it's not straightforward ( relative to C-languages ).
3. You're not expected to easily indent code manually.

After realizing those things, spending a couple of minutes to figure
out auto-indentation was all it took to overcome that hurdle.
-Patrick

Laurent PETIT

unread,
Feb 3, 2010, 12:11:17 PM2/3/10
to clo...@googlegroups.com
I think there are also several ways of identing clojure code, depending on what the tools provide out-of-the-box, and of devs personal preferences:

 * do you see a reindenter like something that will just correctly change the number of beginning spaces of each line, or also something that could reformat the whole line as well (removing extra spaces, ...)
 * which algorithm for the identation ?
   a. totally predictive by following rules not dependent upon a special (subject to be update from IDE to IDE and clojure version to clojure version and project specificity to project specificity) "syntax symbols list"
   b. stable across relaunch if the list mentioned above did not change
   c. unpredictive but more accurate by completing the list with information available e.g. from a connection of the IDE with a live REPL ?

For cross-IDE and cross-clojure versions of projets, I guess I would prefer a., but maybe it's too "strict" ?



2010/2/3 CuppoJava <patrick...@hotmail.com>

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Dan

unread,
Feb 3, 2010, 12:21:32 PM2/3/10
to clo...@googlegroups.com
On Wed, Feb 3, 2010 at 12:11 PM, Laurent PETIT <lauren...@gmail.com> wrote:
I think there are also several ways of identing clojure code, depending on what the tools provide out-of-the-box, and of devs personal preferences:

 * do you see a reindenter like something that will just correctly change the number of beginning spaces of each line, or also something that could reformat the whole line as well (removing extra spaces, ...)

It reminds me of gofmt. Code submitted to the go project will invariably be formatted by the gofmt app that defines the canonical way to format go code. If you disagree with gofmt, you shouldn't correct it by hand, you either are wrong or should file a bug against gofmt.

It's a gutsy move on their part to declare a canonical one-true-way to format code but I like best practices delivered as code. Beside, it's not as if anyone was forced to use it.

I'd totally be behind a tool that formats clojure code. It would make a good contrib.

ataggart

unread,
Feb 3, 2010, 12:52:41 PM2/3/10
to Clojure
We should note that formatting the code means more than just
indentation. E.g.:

(map vec
(partition 2
(map foo
(filter bar? baz))))

vs.

(->> baz
(filter bar?)
(map foo)
(partition 2)
(map vec))

The algorithm used is identical, but the structure of the code is
quite different, perhaps being more or less readable. It may be worth
including such details in addition to where one sticks whitespace.

Dan

unread,
Feb 3, 2010, 1:33:47 PM2/3/10
to clo...@googlegroups.com

The algorithm used is identical, but the structure of the code is
quite different, perhaps being more or less readable.  It may be worth
including such details in addition to where one sticks whitespace.


I think it should be in a different tool but a Clojure lint is an awesome idea. 

Dan

unread,
Feb 3, 2010, 2:11:22 PM2/3/10
to clo...@googlegroups.com

Timothy Pratley

unread,
Feb 3, 2010, 9:26:58 PM2/3/10
to clo...@googlegroups.com
On 4 February 2010 03:56, CuppoJava <patrick...@hotmail.com> wrote:
>  1. That indentation is *extremely* important.
>  2. That it's not straightforward ( relative to C-languages ).
>  3. You're not expected to easily indent code manually.

This is insightful and succinct advise which would be a great FAQ or
pre-amble to a resource on formatting styles/options.

Reply all
Reply to author
Forward
0 new messages