coding style -- parentheses placement

Started by dukester, August 28, 2007, 06:41:53 AM

Previous topic - Next topic

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....
duke

HPW

#1
There is no law of style.

And there are different tastes and opinions:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1023&highlight=formating">http://www.alh.net/newlisp/phpbb/viewto ... =formating">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1023&highlight=formating



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=indent">http://www.alh.net/newlisp/phpbb/viewto ... ght=indent">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=indent
Hans-Peter

dukester

#2
Quote from: "HPW"There is no law of style.

And there are different tastes and opinions:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1023&highlight=formating">http://www.alh.net/newlisp/phpbb/viewto ... =formating">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1023&highlight=formating



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=indent">http://www.alh.net/newlisp/phpbb/viewto ... ght=indent">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=indent


Thanks for the references! This is good news indeed! I'm loving newLISP  more and more as I get more acquainted with it. L8r....
duke

Jeff

#3
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.


(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 :(
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#4
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">//http://intricatevisions.com/index.cgi?page=nlcode) for some ideas!