newLISP Fan Club

Forum => Anything else we might add? => Topic started by: dukester on August 28, 2007, 06:41:53 AM

Title: coding style -- parentheses placement
Post by: dukester on August 28, 2007, 06:41:53 AM
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....
Title:
Post by: HPW on August 28, 2007, 06:54:52 AM
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/viewtopic.php?t=893&highlight=indent
Title:
Post by: dukester on August 29, 2007, 08:07:52 PM
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/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....
Title:
Post by: Jeff on August 30, 2007, 05:11:11 AM
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 :(
Title:
Post by: cormullion on September 04, 2007, 06:40:52 AM
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!