Page 1 of 1
coding style -- parentheses placement
Posted: Tue Aug 28, 2007 1:41 pm
by dukester
Hi all....
Is it "good" style to write:
(set 'counter 1)
(map (fn (i)
............(println "Element " counter ": " i)
............(inc 'counter)
..........)
..........(sequence -5 5)
)
instead of:
(set 'counter 1)
(map (fn (i)
...........(println "Element " counter ": " i)
...........(inc 'counter))
...........(sequence -5 5))
NB. I'm using ........ above to preserve spacing
TIA....
Posted: Tue Aug 28, 2007 1:54 pm
by HPW
Posted: Thu Aug 30, 2007 3:07 am
by dukester
Thanks for the references! This is good news indeed! I'm loving newLISP more and more as I get more acquainted with it. L8r....
Posted: Thu Aug 30, 2007 12:11 pm
by Jeff
I personally feel that it's more intuitive and easier to read to indent to the last open paren. Just like curly-brace-loving languages are easier to visually parse when the scope is indented, I indent once (two spaces, soft tabs) for scope and then to the first atom in the last unclosed list.
Code: Select all
(define (foo x y)
(+ x y))
(map println '(foo bar baz
bat)) ; bat should be lined up with the first char of foo
; although you can't tell with variable width fonts :(
Posted: Tue Sep 04, 2007 1:40 pm
by cormullion
I'm no coder - but I use both these ways of formatting (and some more, besides :-). While I'm starting work on something i'll use your first style more. For one thing, it can help getting the syntax right. Also, it's slightly easier to add or remove (or comment out) lines if they're each on their own line. After that I probably tend towards your second style: a more compact presentation (sometimes it matters if you're writing about code rather than just writing it). And a very Lisp-y look too, with all those parentheses holding on for dear life at the end of a function definition...
If you want to format your code automatically, have a look at Fanda's code analysis tools (
http://intricatevisions.com/index.cgi?page=nlcode) for some ideas!