News for hackers. Stuff that matters.
Re:Why I Switched from Python to Clojure (2016) by snrji on Sunday March 24, 2019 @03:19PM (#19478191)
I have considered multiple times switching from Python to other alternatives. However, I instantly discard any language with a Lisp-like syntax. I just cannot work with it. Being a Haskell hobbyist, I would like Python to be statically type and have better support for pure functional programming, but Python has the libraries that I need.
Re:Why I Switched from Python to Clojure (2016) by jhhh on Sunday March 24, 2019 @06:19PM (#19479107)
Every person that I've talked to that seemed to have a strong negative opinion about parens never used it. They just think they won't like it but wouldn't take the minimal amount of time to give it a try with something like paredit. I was also in this camp for a long time until I figured I would give it a serious try instead of disparaging something I had not used. You might consider that creating and editing code with balanced parenthesis doesn't actually require you to insert them manually when you have an editor that will always keep the code data-structure balanced and makes structural editing simple.
Re:Why I Switched from Python to Clojure (2016) by dkersten on Monday March 25, 2019 @01:20AM (#19480451)
I used to hear the exact thing about Python, incidentally. People would complain about how horrible significant whitespace is and how it causes all these problems, yet everyone I spoke to that used Python said the same thing: that it fades away into the background very quickly and ceases to be an issue. This was also my exact experience with significant whitespace.

Lisp parentheses are the exact same way, in my experience. You hate them until you spend a few weeks writing a Lisp and then they just fade into the background, never to bother you again. Then once you learn paredit, it becomes painful to use other languages again! (And now with parinfer, I think about them even less still) Incidentally, in my experience, Clojure typically has the same amount of parentheses as typical OO languages, in some cases fewer, its just that the opening paren is moved one word to the left.

Also, to anybody new to Lisp: try an editor with rainbow parentheses.

Re:Why I Switched from Python to Clojure (2016) by Fice on Sunday March 24, 2019 @06:30PM (#19479152)
For me the ability to edit code structurally (rather than in terms of plain text) in a uniform way is a great advantage of Lisp syntax.
Re:Why I Switched from Python to Clojure (2016) by Syzygies on Sunday March 24, 2019 @10:15PM (#19479886)
I've been using Scheme as one of my languages for a decade. (Haskell, Python, Ruby, Bash are the main others.) I generally use a preprocessor for each language. The Haskell preprocessor treats indented as code, flush as comments, also supported by my syntax highlighting. Comment characters feel to me like a thousand Hitchcock birds shat on my car. They're so easy to avoid. It also introduces here docs; no language should be so full of itself that it can't embed multiple lines of another language verbatim.

I've gone through several period of straight Lisp parens, and several periods of using a preprocessor. I believe in committing to muscle memory before deciding; I've oscillated back and forth between Querty and Dvorak, for example. I'm more committed to psychological experiments than anyone who claims the parentheses haters are newbies who haven't tried.

Study counting in higher mammals: One finds that "one, two, three, many" is core to all of us, and higher systems are strapped on like the multiple layers of vision mechanisms. Humans can't deal with the tiger tails at the end of lisp expressions. But machines can? Yes, but machines can also handle inferred parentheses. The complainers about parentheses complainers want off-the-shelf support. Real programmers write their own support.

Lisp looks best with indentation to help infer parentheses. Use a pipe "|" to open a parenthesis that auto-closes at the next ")" or the end of the line. Use a dollar "$" (borrowed from Haskell) to open a parenthesis that auto-closes when the indentation returns. Lisp written this way is stunningly beautiful poetry, cleaner than any of the dozens of languages I've programmed in. The remaining parentheses actually matter, so one pays attention to them.

I've spent years each way, back and forth. Inferring parentheses is better, and one can write any tool to follow this syntax.

Re:Why I Switched from Python to Clojure (2016) by jiyinyiyong on Monday March 25, 2019 @12:34PM (#19484021)
You would be interested in my old project using `$` as a way for reducing parentheses: http://text.cirru.org/ .
Re:Why I Switched from Python to Clojure (2016) by GorgeRonde on Monday March 25, 2019 @09:20AM (#19482192)
Would you mind sharing some example code on Gist, please ?
Re:Why I Switched from Python to Clojure (2016) by omginternets on Sunday March 24, 2019 @03:35PM (#19478292)
> I just cannot work with it.

Can't or won't?

I'm not being facetious, here. I just can't imagine any reason one _couldn't_ work with it, once the syntax is learnt. There's nothing about lisp-like syntax that's inherently hard to learn.

Why is lisp special?

Re:Why I Switched from Python to Clojure (2016) by blunte on Sunday March 24, 2019 @05:51PM (#19478997)
Not only is it not inherently hard to learn, it's arguably one of the easiest syntaxes to learn. ( fn-name param1 param2 ... ) is the syntax.

Once the brain grasps this, a whole layer of complexity just vanishes. Furthermore, not having to use punctuation between items is just heavenly. There's so much less noise compared to Python, and Python isn't even a particularly noisy language.

Re:Why I Switched from Python to Clojure (2016) by istjohn on Sunday March 24, 2019 @06:02PM (#19479039)
Only if you don't consider a forest of parens to be noise. I do. I'm sure I could get used to it after a while, but at first glance, Python code is definitely cleaner than Lisp.
Re:Why I Switched from Python to Clojure (2016) by freshm087 on Sunday March 24, 2019 @11:10PM (#19480066)
"Forest of parens" can be intimidating for sure, but if it's really a forest, then it usually means there's too much nesting. Which is a problem for any language/syntax. Overnested Python code is hard to grasp, and wide fields of whitespaces doesn't make it better than deep forests of parens/curlies, or mounting slabs of begin/end pairs.
Re:Why I Switched from Python to Clojure (2016) by mschaef on Monday March 25, 2019 @06:07AM (#19481316)
Maybe. As someone with a Lisp background moving to Python (day job), all the semantics hidden behind whitespace makes me just a bit nervous. The parens, for me, make structural editing easier and also give a means of keeping the syntax around even when the whitespace gets damaged by whatever editing operations are happening.

(But whitespace sensitivity has always struck me more as a way to enforce specific whitespace conventions than anything else, and even as far back as Pascal I've been religious about maintaining indention in code. It's easy to do with a decent editor (or not) and helps the readability immeasurably.)

Re:Why I Switched from Python to Clojure (2016) by F-0X on Sunday March 24, 2019 @06:07PM (#19479058)
It's not a "forest of parens" any more than any language with C style syntax is, they're just in different places (the correct places) and there's no need to distinguish with braces (which you shouldn't need to).
Re:Why I Switched from Python to Clojure (2016) by holografix on Sunday March 24, 2019 @07:00PM (#19479254)
That’s not true. When you’re passing functions to functions inside functions that return functions... it’s a nested mess.

I studied Lisp and Scheme at university and that’s where it had to remain for me: academically entertaining mind puzzles in data structures and algorithms. It’s just not productive or easily graspable from one coder to another.

Re:Why I Switched from Python to Clojure (2016) by sooheon on Sunday March 24, 2019 @08:55PM (#19479620)
Tasteful macros can alleviate this, and Clojure's std lib has a few which are just delightful.

The following does exactly what you'd expect, and there are even cooler ones like `some->` or `as->`.

    (->> some-nums
         (map square-root)
         (filter even?)
         set
         count)
This is what lisp buys you, dead simple rules for syntax, with the option to add syntax with macros. If you made a mistake in syntax design, deprecate the lib and make a new macro, it need not be a feature of core language for all eternity.
Re:Why I Switched from Python to Clojure (2016) by mschaef on Monday March 25, 2019 @06:10AM (#19481322)
And then you use a threading macro to assemble a middleware stack, only to find out that the middleware is applied in reverse order of what's listed as an inbound request comes in... (The outermost middleware being listed last in a threading form).

There's a reason for it, for sure, but it's surely a part of the learning curve.

Re:Why I Switched from Python to Clojure (2016) by sooheon on Monday March 25, 2019 @03:53PM (#19486145)
Yep, it's always possible to have a mismatch in assumptions. That one definitely bit me as well. What's important is that the learning curve is not due to arbitrary rules, it's a faithful application of the logic of the macro.

Remember that what is being passed through the threading macro is not the request, but the handler function itself. Each middleware takes the old handler, wraps itself over it to do things before and after the old handler. The threading macro is not a representation of the path your request will take, it is a way to build up a chained function that represents your final handler, which will then receive the request. Suddenly the ordering makes perfect sense :P

Re:Why I Switched from Python to Clojure (2016) by taeric on Sunday March 24, 2019 @08:15PM (#19479503)
Only if you insist on inlining all of the functions. Do yourself a favor and name a few of them. People that come after you will appreciate it, too.
Re:Why I Switched from Python to Clojure (2016) by nothrabannosir on Sunday March 24, 2019 @07:31PM (#19479362)
Yes, Python looks cleaner, Lisp thinks cleaner.
Re:Why I Switched from Python to Clojure (2016) by michaelvmata on Sunday March 24, 2019 @07:39PM (#19479387)
Editor tooling matters. Formatting, traversing, matching, and highlighting parenthesis made all the difference for me.
Re:Why I Switched from Python to Clojure (2016) by thom on Sunday March 24, 2019 @06:00PM (#19479030)
I've programmed for 10 years in Clojure and have many regrets, but I've grown to just accept that Lisp syntax is correct. On day one you need to understand one thing. Years later, you need to understand one thing. And sure, in Clojure they happen to use three types of brackets for brevity but even that's optional. But other languages have dozens if not hundreds of little syntactical edge cases. I personally find that inconsistent mess repulsive.
Re:Why I Switched from Python to Clojure (2016) by Scarbutt on Sunday March 24, 2019 @06:08PM (#19479062)
What are those regrets? ;)
Re:Why I Switched from Python to Clojure (2016) by thom on Sunday March 24, 2019 @06:50PM (#19479226)
Oh, so many things.

The parallelism isn't actually that powerful, and in 2019 there's very little to set it apart. The building blocks are great, e.g. immutability everywhere, but few of the built-in primitives are actually usable (hidden unconfigurable thread pools etc). Stack traces still regularly horrible. Libraries are regularly abandoned. ClojureScript integrating with npm etc is more stress than you'd like. Core development is haphazard and proudly so. Types are nice, and spec is still up in the air, and slow, and not widely implemented, and will probably be rewritten several more times before being abandoned. Hiring is harder than a dozen other languages.

All that said, there is still amazing stuff happening. I hold out some hope that Dragan's work might spark a bigger stats/ML community on top of Clojure, for example:

https://dragan.rocks/

Every day I can still write code and think "yay, that's cute", and be thankful for the dynamism and clarity it can enable. But I wouldn't recommend it to anybody, for anything really, and I feel sad realising that.

Re:Why I Switched from Python to Clojure (2016) by fiddlerwoaroof on Sunday March 24, 2019 @07:24PM (#19479341)
I had lots of pain dealing with CLJS but, since switching to http://shadow-cljs.org as my compiler, I've generally found that things "just work": instead of complicated messing with externs, you just npm install the package and then add `["vega" :as vega]` to your namespace's list of requires.

As far as the stack traces go, I have a hard time understanding why tooling like Cider's stacktrace filtering isn't wider spread: in Cider, when a stack trace pops up, it's one or two clicks to hide most of the things I don't care about and, yet, that information is still available for people working on the compiler or with Java interop.

Re:Why I Switched from Python to Clojure (2016) by thom on Sunday March 24, 2019 @08:45PM (#19479587)
Thanks for this, shadow-cljs looks very promising.

In terms of stack traces, it's not just the location in your code that you care about, it's the nature of the error. In lieu of spec being ubiquitous or anybody really checking their arguments ever, you're still left looking at 20 lines of stack beyond your own code to realise you've passed the incorrect type or structure somewhere. And even with spec you need additional libraries to actually yield human error messages in a lot of cases.

Re:Why I Switched from Python to Clojure (2016) by pmoriarty on Sunday March 24, 2019 @04:56PM (#19478724)
"I instantly discard any language with a Lisp-like syntax. I just cannot work with it."

I feel the opposite. I avoid any language without a Lisp-like syntax, since its absence is a serious handicap which unnecessarily complicates code and makes it less readable.

I also much prefer the Lisp idiom of using meaningful function and variable names, vs the one-letter names and crypitic operators that are so common in Haskell, OCaml, and SML.

Re:Why I Switched from Python to Clojure (2016) by tombert on Sunday March 24, 2019 @08:33PM (#19479551)
I agree; once I beat the initial scariness of Lisp, I found it hard to go to any non-Lisp language.

Macros, while easy to abuse, are kind of a game-changer; the ability to add new semantics to a language make it borderline impossible for me to go to any language that doesn't have a good macro system.

I started with Clojure, which I still really enjoy, but due to how much I grew to love the `define-syntax` system in Chicken Scheme, that's become my latest weapon of choice.

Re:Why I Switched from Python to Clojure (2016) by endgame on Sunday March 24, 2019 @06:53PM (#19479238)
Bear in mind that often the reason Haskell code uses one-letter names (and this is possibly true for the other MLs) is that your types can be so generic that you can write useful functions without knowing what you're working on. In such situations, `x` is just as good as `thing`, as far as names are concerned.

As for the operators: they are a visual language. We do not speak our punctuation aloud in English, and we use small marks to guide the reader's eye. Often, Haskell operators as similar, and there is a definite pattern.

f $ x means "f applied to x"

f <$> x means "map f over x"

In general, the <> around an operator lifts it to work over a structure. Similarly:

x & f means "f applied to x"

x <&> f means "map f over x"

For the applicative operators like <star>, star> and <star (where "star" should be an asterisk but I can never work out the formatting on this forum), the operators "point" at the values being retained. And so on.

Re:Why I Switched from Python to Clojure (2016) by sooheon on Sunday March 24, 2019 @09:00PM (#19479637)
It's cool, and I wouldn't be sad to work with Haskell by any means, but I still think there's an elegance to lisp syntax that can't be beat. There are very few language level rules, everything is composable building blocks.
Re:Why I Switched from Python to Clojure (2016) by moomin on Sunday March 24, 2019 @04:07PM (#19478461)
I far prefer Haskell to Clojure myself but I will say: once you get half-decent at paredit, no syntax even comes close to Clojure’s.

Indeed, if you really want fun, try Hackett: a Haskell variant implemented in and for Scheme.

Re:Why I Switched from Python to Clojure (2016) by dorkusmagnus on Sunday March 24, 2019 @03:42PM (#19478339)
Just think of the parenthesis as loving warm homoiconic hugs.
Re:Why I Switched from Python to Clojure (2016) by anon4242 on Sunday March 24, 2019 @04:38PM (#19478609)
Hehe, when teaching my 8yr-old programming (in Python) I call (function call) parenthesis a hug to explain that a function "hugs" all arguments to it. She seems to get that :).
Re:Why I Switched from Python to Clojure (2016) by rsyring on Sunday March 24, 2019 @05:50PM (#19478990)
This is a fantastic analogy, thank you for sharing! I found myself really struggling to communicate how a function's arguments got passed to it to my daughter and I'm going to try this the next time I need to explain it.
Re:Why I Switched from Python to Clojure (2016) by VladimirGolovin on Monday March 25, 2019 @04:59AM (#19481116)
I'm teaching my 12-yr old daughter Python right now, and this looks like a neat analogy -- I'll try it in a few minutes.
Re:Why I Switched from Python to Clojure (2016) by rhizome31 on Sunday March 24, 2019 @04:55PM (#19478718)
I haven't got much experience with Lisp, but I can imagine that, similarly to Python's significant indentation, it's a shallow weirdness that can be overcome easily after a little while. In both cases a little help from the editor will probably be needed.
Re:Why I Switched from Python to Clojure (2016) by blunte on Sunday March 24, 2019 @05:55PM (#19479013)
You will shoot yourself in the foot less often with Lisp parens than you might with Python whitespace. Most modern editors handle the closing parens anyway.

Plus, many editors without any plugins can jump between matching braces; so moving around the code is very quick compared to Python (unless you have a Python plugin that has block movement shortcuts).

Re:Why I Switched from Python to Clojure (2016) by andybak on Sunday March 24, 2019 @07:10PM (#19479288)
> You will shoot yourself in the foot less often with Lisp parens than you might with Python whitespace.

I'm not letting that stand ;-)

In my experience Python's whitespace generally removes sources of scope/block errors compared to parenthesis and curly-based languages

> unless you have a Python plugin that has block movement shortcuts

Not sure what this means. The only support I need in an editor is the ability to use tab and shift tab on blocks of text to change the indentation level. It's visually obvious when code is correctly indented.

Re:Why I Switched from Python to Clojure (2016) by darkpuma on Sunday March 24, 2019 @07:50PM (#19479418)
> "It's visually obvious when code is correctly indented. "

Not when the beginning of the code block isn't on screen.

And more to the earlier point, configuring your editor to jump to the beginning from the end or the end from the beginning of a particular block of code going to be trickier than the equivalent in even vim for lisp, which is simply %

(And vim isn't even a particularly good editor for lisp, but out of the box unconfigured, it's better at lisp than it is at python.. % isn't even lisp specific functionality, lisp just happens to use balanced parenthesis which is something nearly every serious text editor happens to handle in a reasonably robust way, because balanced parens are generally useful in many languages, including python!)

Re:Why I Switched from Python to Clojure (2016) by misterdoubt on Sunday March 24, 2019 @09:49PM (#19479791)
> Not when the beginning of the code block isn't on screen.

The length of your code blocks terrify me. :)

Re:Why I Switched from Python to Clojure (2016) by darkpuma on Sunday March 24, 2019 @10:16PM (#19479889)
It doesn't take more than two dozen or so lines depending on the window arrangement. Nothing truly excessive. Alternatively, viewing the entire code block might mean scrolling up.

If you want scary, check out GNU's implementation of `cat`. I think they hit ten nested indentation levels. Though, because that's C, you can at least jump between the beginning and end of each level by having your editor jump to the matching {}.

Re:Why I Switched from Python to Clojure (2016) by kbp on Sunday March 24, 2019 @08:01PM (#19479457)
> Not sure what this means. The only support I need in an editor is the ability to use tab and shift tab on blocks of text to change the indentation level. It's visually obvious when code is correctly indented.

In Emacs you can use C-M-f and C-M-b to move back and forth over / select paren/bracket/brace delimited blocks, or in vi you can use %, both with 0 configuration in a language-unaware state. If you're editing C or Lisp or whatever, these generic commands are useful. Editors don't tend to have move-to-next-less-indented-line (and similar) commands outside of Python modes or similar, in my experience, and even if they did, they'd need a bit more work than that to work properly because of indenting subexpressions.

Re:Why I Switched from Python to Clojure (2016) by dkersten on Monday March 25, 2019 @01:34AM (#19480499)
> It's visually obvious when code is correctly indented

Not always, in my experience. I’ve lost many hours to debugging only to realise some piece of code was misindented. It doesn’t happen often and usually when code is being moved around, but when it does, its been painful.

Re:Why I Switched from Python to Clojure (2016) by alain_gilbert on Monday March 25, 2019 @03:40AM (#19480854)
The worst I have seen is: There is a merge commit (fixing conflicts) and then, a "if" condition get accidentally de-indented (compared to what it should be), and now this bug is completely invisible and the code will run just fine... (until you figure out what's going on)
Re:Why I Switched from Python to Clojure (2016) by taeric on Sunday March 24, 2019 @08:20PM (#19479515)
Having seen many instances of someone not pasting the full function on a move, the "whitespace defines otherwise invisible changes of scope" is not something that endears me to the language.

I almost buy that it encourages simpler blocks, since complicated ones are impossible to parse out rather quickly. But my later reviews shows it doesn't remove them.

Re:Why I Switched from Python to Clojure (2016) by swlkr on Sunday March 24, 2019 @04:37PM (#19478606)
You could try parinfer, it effectively turns lisp (clojure) into a whitespace significant language like python.

You still get the great “execute this block of code in the repl” with the parens too.

Re:Why I Switched from Python to Clojure (2016) by smnplk on Sunday March 24, 2019 @04:54PM (#19478714)
Hey look it's the coast guy :)
Re:Why I Switched from Python to Clojure (2016) by pletnes on Sunday March 24, 2019 @03:37PM (#19478304)
Python can be statically typed with mypy and type annotations.
Re:Why I Switched from Python to Clojure (2016) by iLemming on Monday March 25, 2019 @01:37AM (#19480507)
Yeah, there are people who simply can't read Lisp syntax. Where I see structure and beauty, they see "murder of parens" (or whatever demeaning collective noun they use to describe it). I call them dyslisplexics.
Re:Why I Switched from Python to Clojure (2016) by bradcypert on Monday March 25, 2019 @09:40AM (#19482303)
Blog Post Author Here:

It's really not that bad! Here are some insights into the parens!

1. I've converted Java code over to Clojure and found that it has less parens per file.

2. They're still there, they're just in a different place. `System.out.println("")` vs `(println "")`

3. There are some great tools to help with the Parens. If you're using Intellij, Pareninfer and Rainbow parens are two extremely helpful tools.

Re:Why I Switched from Python to Clojure (2016) by coliveira on Sunday March 24, 2019 @06:22PM (#19479121)
I have considered Python many times, but I cannot work with a language that considers whitespaces as required syntax. I just cannot work with it.
Re:Why I Switched from Python to Clojure (2016) by njharman on Sunday March 24, 2019 @07:45PM (#19479406)
Whitespace is not any more significant in Python than most languages.

Indentation is significant.

Just replace '(' with space/tab and ')' with "deindent". Done.

Re:Why I Switched from Python to Clojure (2016) by coliveira on Sunday March 24, 2019 @08:38PM (#19479568)
Have you done indentation with anything else other than whitespace?

I prefer to let this idea of required indentation to FORTRAN.

Re:Why I Switched from Python to Clojure (2016) by lsh on Sunday March 24, 2019 @06:59PM (#19479250)
the downvotes are funny because this was exactly the criticism Python got before it became popular. Probably still gets it.
Re:Why I Switched from Python to Clojure (2016) by endgame on Sunday March 24, 2019 @06:49PM (#19479220)
That's a shame. I use Haskell but wish it had paren syntax. I'd rather have strong types than sexps so I stick with Haskell.
Re:Why I Switched from Python to Clojure (2016) by garyrob on Sunday March 24, 2019 @10:58PM (#19480020)
Lately I've been playing with Coconut [1], a functional language that is a strict superset of Python 3. It transpires to Python and can use all of Python's libraries. I've been playing with it lately and quite like it.

[1] http://coconut-lang.org

Re:Why I Switched from Python to Clojure (2016) by black-tea on Sunday March 24, 2019 @05:26PM (#19478873)
Try, it's wonderful. The best. I write C and Python for a living.