Live data from Hacker News

Why I Switched from Python to Clojure (2016)

bradcypert.com

71–80 of 200 posts

Re: Why I Switched from Python to Clojure (2016)

#71
post #4

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.

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.

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)

#72
post #57
post #29

Earlier quoted context omitted.

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

> 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…

> "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)

#73

> ...the “implied self parameter” on python methods turned me off. If I had a nickel for every time I got the "TypeError: random_function() takes 1 positional argument but 2 were given" because I forget the "self" parameter I could buy myself a coffee. Probably a fancy one from the Starbucks even!

It's not implied, it's explicit in Python. you have to put it right there in the method signature! And it's obvious when python passes it in cause you used dot syntax!

Other languages have implied "this" or "self".

  class LiterallyThere:
    def method(self, foo):
      "Literally explicit, self"
Dot operator means apply this method to thing left of dot by executing method with thing on left as first arg.

LiterallyThere.method('foo')

passes the class object LitterallyThere as the first arg

lt = LiterallyThere()

lt.method('foo')

passes the instance of the class object represented by lt as the first argument.

method(something, 'foo')

If you were able to reference method without a dot, you would have to supply two arguments cause method takes two arguments.

You literally, explicitly have to tell the interpreter what you are passing as first parameter and you method signature has to literally, explicitly accept that parameter.

Re: Why I Switched from Python to Clojure (2016)

#74
post #43

I can, and do, appreciate opinions on languages themselves. But my decision to continue using Python over Clojure is much less about the language's syntax and more about the available libraries. How do Clojure web frameworks compare to Django/Flask? What would I use instead of Pandas for data analysis? Are there keras-like deep learning tools? Switching languages based on a comparison of idiosyncrasies between the tw…

Clojure generally has pretty good library support: the JVM has several high-quality web application servers: Jetty, Netty, Tomcat, Glassfish, etc. And, being a Lisp, Clojure can wrap these with a nice interface. The same is true in other areas: you have very nice access to the entire JVM ecosystem and really-well designed interop with the host language's concepts so, to a large degree, you never run into a situation…

Curious if your coworkers have looked Eta, a Haskell on the JVM?

Also curious how your Haskellers and Clojurers are peaceably coexisting? (I ask this lightly but still curious :)

Re: Why I Switched from Python to Clojure (2016)

#75
post #57
post #29

Earlier quoted context omitted.

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

> 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…

> 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)

#76

I don't have a horse in this race but I find it interesting that in my career I've seen a lot of bad code but the worst clusterfucks I've met where all in Clojure while the community seems to be chock full of purists and in general people that takes craftmanship seriously at least at face value. ¯\_(ツ)_/¯

You may not claim to have a horse in the race, but rhetoric like this doesn't point you as non biased.

Clojure has yet to impress me, but most of the poor code in any language I have dealt with stemmed from people trying to redefine the norms of the language they were using. And attempting to solve problems they would be lucky to grow into.

Re: Why I Switched from Python to Clojure (2016)

#77
post #36

Earlier quoted context omitted.

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

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.

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)

#78
post #43

I can, and do, appreciate opinions on languages themselves. But my decision to continue using Python over Clojure is much less about the language's syntax and more about the available libraries. How do Clojure web frameworks compare to Django/Flask? What would I use instead of Pandas for data analysis? Are there keras-like deep learning tools? Switching languages based on a comparison of idiosyncrasies between the tw…

I will admit that there aren't as many direct Clojure libraries, but many of the core things out there; core.matrix works pretty well for elaborate matrix processing, there are several decent web frameworks, as well as parsing libraries.

There's a metric ton of libraries for Java and Scala out there, and as a consequence of Clojure's ability to use Java stuff, you have access to all of it. I admit I've not done a ton of machine-learning stuff, but I've used Spark ML, which works well.

Re: Why I Switched from Python to Clojure (2016)

#79
post #57
post #29

Earlier quoted context omitted.

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

> 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…

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)

#80
post #31

Earlier quoted context omitted.

This is just blaming people for using Clojure's features though. If deep JVM integration wasn't a selling point, you'd use a vastly more mature Lisp, right?

The parent post did not say JVM, they said Java paradigms. Vastly different things. Writing Javaonic Clojure vs Clojuronic Clojure. So, trying to replicate the style/structure/paradigms of Java rather than learning and using the Clojure styles, structures and paradigms.

Yes, I understand, and I contend that being able to do this, and leverage Java libraries bidirectionally in impure Java-y ways is an explicit, deliberate and fundamentally useful feature of Clojure. Unless you're trying to say that things like protocols are fundamentally un-Clojurey because they smell of OO or something in which case I just disagree.
Post reply on HN