Taken a step further, a structural editor could prevent incorrect syntax outright, and even allow you to view/edit the structure of your code in ways that simple syntax-highlighted text cannot.
Here's one such experimental editor:
https://github.com/darwin/plastic Edit: I see now that Parinfer refers to Plastic under its Acknowledgements section. :)
I'm wondering what Parinfer would feel like if used when editing the expression to submit in a REPL. (In other words, it could be nice outside of source editors.)
This is a good point. I immediately dismissed Clojure when I played with the in-browser REPL http://www.tryclj.com/. Within moments, I imagined the daily plight of the professional Clojure developer tediously balancing parens like I had to do in that REPL.
Had I known how polished my workflow would be a year later with Paredit + Emacs in-buffer line-by-line code evaluation, or that tool-supported s-expression editing would let me write/refactor/move/nest code much faster than in other dynamically-typed languages, I would've stopped what I was doing and started learning Clojure immediately. But you don't know any of that if you're someone going to http://www.tryclj.com for the first time. Seems like Parinfer could be used in environments where you don't have Paredit available or, perhaps more importantly, where the user hasn't already credentialized in a niche tool for editing s-expressions.
In the Parinfer introduction, 'C Style indentation' is mentioned.
What I can't understand is why 'C Style indentation' isn't the default convention, at least in modern user-friendly Lisps. One of the biggest problems people have with Lisp is the readability of grouped parentheses, but the C Style indentation example shows you can write Lisp without them. I get that it's nice when programs fit in less lines of code, but isn't readability more important than line count?
C brace style has nothing to do with readability. Indentation alone shows the block structure just fine; Python proves this.
The purpose of C brace style is to make editing easier in primitive editors that don't do delimiter matching. In such an editor, selecting where, in a long string of closing delimiters, to insert a new element requires counting the delimiters, which is tedious and error-prone. With delimiter matching, the editor does the work for you, so splitting delimiters across lines is completely unnecessary.
Visual Studio's had delimiter matching for years, and will auto-indent based on levels of depth, will add the trailing delimiter, even with adding new elements, etc. C brace style with autoformatting comes in really handy when editing functions on the fly, because it becomes obvious what block you're working on, with no need to look at one parenthesis among many.
Eh, yes and no. Python at least has `elif` statements.
When execution control depends on the order of nested arguments, I find "c" style to really enhance the following contrived example, even with rainbow parens:
(if true
(whatever this is an (example
that is (kind of hard)
(-> to
(read %))))
(this is an ELSE but hard to figure out))
When it comes to if/else and if you indent with some sanity, then lisp is like Python: if the 'else' branch is too hard to spot or if you forget the context by the time you reach the 'else', then your 'if' branch is simply too many lines long. Or you should flip the condition so that the short branch comes first.
Meanwhile, I can't even write your lisp example as-is in any of the editors I tried it in.
Lisp, has cond which is analagous to Python's elif
Also you have your indentation wrong; (this is an ELSE but hard to figur eout) should be one column to the left, which makes it significantly more readable.
Comments (134) 36 threads
Earlier commentsHere's one such experimental editor: https://github.com/darwin/plastic
Edit: I see now that Parinfer refers to Plastic under its Acknowledgements section. :)
Had I known how polished my workflow would be a year later with Paredit + Emacs in-buffer line-by-line code evaluation, or that tool-supported s-expression editing would let me write/refactor/move/nest code much faster than in other dynamically-typed languages, I would've stopped what I was doing and started learning Clojure immediately.
But you don't know any of that if you're someone going to http://www.tryclj.com for the first time.
Seems like Parinfer could be used in environments where you don't have Paredit available or, perhaps more importantly, where the user hasn't already credentialized in a niche tool for editing s-expressions.
What I can't understand is why 'C Style indentation' isn't the default convention, at least in modern user-friendly Lisps. One of the biggest problems people have with Lisp is the readability of grouped parentheses, but the C Style indentation example shows you can write Lisp without them.
I get that it's nice when programs fit in less lines of code, but isn't readability more important than line count?
Continue this thread — 3 replies
The purpose of C brace style is to make editing easier in primitive editors that don't do delimiter matching. In such an editor, selecting where, in a long string of closing delimiters, to insert a new element requires counting the delimiters, which is tedious and error-prone. With delimiter matching, the editor does the work for you, so splitting delimiters across lines is completely unnecessary.
When execution control depends on the order of nested arguments, I find "c" style to really enhance the following contrived example, even with rainbow parens:
Meanwhile, I can't even write your lisp example as-is in any of the editors I tried it in.
Also you have your indentation wrong; (this is an ELSE but hard to figur eout) should be one column to the left, which makes it significantly more readable.
Also: http://imgur.com/FnXXOXJ
Tell me the above picture is something people have problems understanding the structure of.
All comments shown.
Couldn't load more comments. Check your connection and try again.