New blog post: About Clojure's syntax


#1

So yeah, about Clojure’s syntax…

Feedback welcome!


#2

Reminded me of https://github.com/shaunlebron/ClojureScript-Syntax-in-15-minutes


#3

This is more general feedback, not necessarily about your blog post. But I’ll take the opportunity to give my 2 cents:

IMO, to convince “non-clojurians” to not be scared of CLJ syntax is not just show them how it all makes sense, but much more importantly:

Show them how to efficiently edit CLJ syntax.

In the vast majority of programming language you can do --what I will call-- “Lines of code editing”. Ie, if you need to move code, you can easily select a few lines of code. That selection is frequently syntactically valid. And then you move it somewhere else. This all works since a block of code which often end with braces/parentheses end on a single line of code where no other block ends.

This all brakes down when you enter any LISP for the very first time. “LOC selection editing” doesn’t work at all anymore. And if you’re new you’ll, either:

  1. Select code manually on the starting/ending parentheses. Frequently missing the right pair and making your syntax invalid.
  2. Write non-LISP style code, having only ever one closing parenthesis on a single line. You can frequently see this on some stackoverflow questions from beginners.

Copy&Paste is --IMO-- still one of the most common commands to use when editing source code. So the first problem to teach new users: How to select blocks of code efficiently and with always keeping the parens balanced? This is super easy in Cursive: Just teach the “grow selection” command. I use it all the time:

After this, you can teach two ways: 1. Paredit or 2. Parinfer.

IMO, when teaching a new user paredit you should start with only one command: Slurp. Don’t overload him/her with dozens of command which aren’t all that crucial (you can get around many other commands (like “barf”) with select-cut-paste).


#4

That’s an interesting perspective, but it seems to me most complaints are about LISP syntax being hard to read… so isn’t ease of editing a secondary concern to these people?


#5

Maybe my intuition of reading Lisp is related to touching & messing with it.

In other languages, I feel I’m doing surgery when refactoring code — cutting & moving a logical chunk can involve indentation (Python), punctuation (oops SQL now wants a comma), context-sensitive conventions… In contrast, a Lisp “chunk” is something you just grab with an IDE keystroke.

Also, when confronted with an unreadable Clojure amoeba (“just read it inside-out!”) I can try a simple IDE hand-incantation to use ->> or whatever, which often clears it right up.


#7

For beginners LightMod seems to solve all the problems. Repl, parinfer, examples, figwheel… Everything setup and running after clicking 1 install :slight_smile:

https://sekao.net/lightmod/


#8

This was touched on in https://lambdaisland.com/blog/29-12-2017-the-bare-minimum-clojure-mayonnaise, albeit I think a live demo or coding example with an actual workflow using the tools is what would really highlight to people how powerful clojure development is.