14 ms·
Why I Switched from Python to Clojure (2016)
- deleted 8y ago[deleted]
- o10449366 8y agoI notice this was written in 2016, but I wonder if the author's opinion has changed since dataclasses have been implemented in Python.
- benatkin 8y agoPython's async support also seems to be getting better. There's a flask clone called Quart (http://pgjones.gitlab.io/quart/ http://pgjones.gitlab.io/quart/) and an async postgres client (https://github.com/MagicStack/asyncpg https://github.com/MagicStack/asyncpg). It works very similar to JavaScript, with async and await keywords. I think it should provide speed and comfort especially if you're a regular JavaScript user.
- Waterluvian 8y agoI wrote a pretty substantial experiment using asyncio for 100k websocket client connections across a massive theoretical fleet of robots. It's not open source but the general result was that I used to hate async in Python and now I love it. The syntax makes blending sync and async easy. And the cooperative multitasking paradigm is very easy to reason about. No locks!
- deleted 8y ago[deleted]
- simple_phrases 8y agoIf you did a write-up or went into more detail about your experience, I'd read it. Big fan of Python and am heavily invested in its ecosystem, but I currently prefer async programming in modern JavaScript compared to Python. Did you make use of third-party async libraries?
- Waterluvian 8y agoI'm going to ask my boss to open source it and then do a write up.
- j88439h84 8y agoPython is even better since it has http://trio.rtfd.org http://trio.rtfd.org which provides structured concurrency.
- Scarbutt 8y agoThe author switched to kotlin from clojure, kotlin's interop with java is leagues ahead of clojure.
- zeroDivisible 8y agoI do not have experience with Kotlin and it's interop with Java. Do you maybe have examples or articles which you'd recommend on the subject?
- Scarbutt 8y agoThe official reference: https://kotlinlang.org/docs/reference/java-interop.html https://kotlinlang.org/docs/reference/java-interop.html
- fgonzag 8y agohttps://kotlinlang.org/docs/reference/java-to-kotlin-interop.html https://kotlinlang.org/docs/reference/java-to-kotlin-interop... https://kotlinlang.org/docs/reference/java-interop.html https://kotlinlang.org/docs/reference/java-interop.html https://developer.android.com/kotlin/interop https://developer.android.com/kotlin/interop
- Per_Bothner 8y agoMay I suggest Kawa (https://www.gnu.org/software/kawa https://www.gnu.org/software/kawa) if you're open to Lisp-style syntax (Kawa is a Scheme dialect)? Kawa has great Java interoperability, Java-like performance (with the help of optional type declarations), a nice REPL, full documentation, maturity (continuous development since 1996), and many neat features. It doesn't require special tools or workflow. (I do suggest using the git version, as it is overdue for a release.)
- iLemming 8y agoKotlin simply is an attempt to fix Scala problems, which in itself is an attempt to fix Java problems. Clojure by design - simply doesn't have those problems.
- bradcypert 8y agoBlog Post Author Here: My opinion has not change as I've never looked back ;) I've found a fun little home in the JVM, but I'll definitely check out data classes in Python! That seems pretty cool :)
- snrji 8y agoI 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.
- omginternets 8y ago> 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?
- blunte 8y agoNot 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.
- istjohn 8y agoOnly 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.
- F-0X 8y agoIt'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).
- 8y ago
- fopen64 8y agoPython is just the best language, why people are so headstrong not to use it everywhere? Speed would come along with investment. Is the perceived arrogance of some Pythonists a factor (that left Node.js/Javascript to become the actual lingua franca)?
- UncleEntity 8y ago> ...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!
- fiddlerwoaroof 8y agoI always thought this made sense: a method, considered as a property of a class isn’t yet bound to any particular instance while, considered as a property of an instance has an implicit parameter of the instance you’re currently operating on: languages like Java hide this “this” parameter from you by passing it automatically while python makes it explicit so you can form a better mental model of what’s going on
- zwp 8y agoThe problem is that Python is the exception here. Those of us that learnt other languages first already have a mental model and find this explicit self parameter weird. And it's more typing. Yegge thinks that "self" is a wart and I agree. The article is a fun read but it's showing its age. I suspect Python might just have beaten Perl by now. https://sites.google.com/site/steveyegge2/tour-de-babel#TOC-Python https://sites.google.com/site/steveyegge2/tour-de-babel#TOC-... I suppose Python's way there's one less reserved word. Are there any other advantages?
- fiddlerwoaroof 8y agoI also like how you can call the method on the class and pass self in explicitly. e.g.: class Foo: b = 4 def foo(self, a): return a + self.b inst = Foo() inst.foo(3) Foo.foo(inst, 3) I haven't written python in a while, but I really like that python makes this possible and obvious and I've found this behavior pretty handy when working in a more functional style.
- fiddlerwoaroof 8y ago
- luckydata 8y agoI 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. ¯\_(ツ)_/¯
- heretoo 8y agoI work with clojure, and love it, but believe the problem is caused by java or equivalent paradigms applied to clojure. The high probability that clojure was someone's first functional language could also contribute to the problem. Your thoughts?
- thom 8y agoThis 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?
- ken 8y agoA lot of us use Clojure despite the JVM, not because of it. Closure has a lot of (other) compelling features.
- fiddlerwoaroof 8y agoI mostly write Clojure because, unfortunately, it's nearly impossible to sell management on Common Lisp: ime, Clojure is a nice language, but it's very uneven because it's well-designed for the sorts of things the core team cares about and everything else is barely passed the MVP stage.
- njharman 8y agoThe 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.
- Townley 8y agoI 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 two seems like moving to a new city based solely on the weather: a valid consideration, but nowhere near sufficient.
- malvosenior 8y agoClojure works on the JVM so you have native access to all of the Java ecosystem. With that in mind I'd say the libraries are actually better for Clojure with the exception of data analysis. I don't think there's a language out there that has as many data libraries as Python (like Pandas).
- vips7L 8y agoAren't there a lot of data libraries for scala?
- fiddlerwoaroof 8y agoYeah, at the very least, there's Spark, which is reasonably nice to use from Clojure via the Java API: https://github.com/finalfantasia/apache-spark-examples-in-clojure/blob/master/src/clojure/apache_spark_examples_in_clojure/spark_sql_example.clj#L37 https://github.com/finalfantasia/apache-spark-examples-in-cl...
- malvosenior 8y agoYes but more data engineering than data science (someone else mentioned Spark).
- john2x 8y agoI really don't understand this point about just using Java libraries in Clojure. Why not just use Java? Wouldn't the experience of writing Clojure that fits the Java library's model be horrible?
- Aeolun 8y agoSometimes I read these pieces and I wonder how much of the joy of the new language is just having become a better programmer in the meantime.
- Insanity 8y agoAt least for me, it definitely factors in. Getting a new perspective on problems by using a language with a different toolbox (functional rather than OOP for example) can help with future problems. And it's just good fun to learn a new language just to challenge yourself a bit.
- bradcypert 8y agoBlog Post Author Here: You're definitely right. I had a run in with PolyML in College and I was absolutely terrified of any functional language (nearly failed the class, in fact). Before deciding to switch from Python to Clojure, I had used Clojure briefly a few years before and hated it (was writing mostly Groovy at the time). After some time to grow, I had started caring about different principles in the languages that I used. I had been ruined by mutable state too many times; I got tired of not knowing how to get the number of wheels on your instance of the car class, I got tired of so many things. Clojure was/is a wonderful reprieve from all of these things, but truth be told, I do still struggle with it from time to time. Or at least, it feels like I do.
- hetman 8y agoIt's interesting that the very things that attracted the author to Clojure was what kept me from moving to it from Python. I enjoyed the syntax. Loved the immutability. However, I wasn't able to understand the structure of program data at a glance even when reading my own code. The reliance on lists and maps everywhere meant that the structure of data was encoded in the code of the functions that created it and sometimes you had to go several functions deep just to understand the bit you wanted. In Python if I'm returning a tuple that's more than 2 or 3 elements long, I know that it's time for, at the very least, a namedtuple because I've had to deal with code in the past that has mysterious 5-tuples etc that just becomes too tiring to deal with. To be clear, big collections in Python aren't a problem as long as the type of the contained data remains uniform.
- kevin_thibedeau 8y agoThe fundamental problem with S-expressions is that they are intended for (1950s) machine readability and human ergonomics takes a back seat.
- iLemming 8y agosure, because Sure, because this (taken from React's JSX example page): <DashboardUnit data-index="2"> <h1>Scores</h1> <Scoreboard className="results" scores={gameScores} /> </DashboardUnit>; is more readable than this: [dashboard-unit {:data-index 2} [:h1 "Scores"] [scoreboard {:class-name "results" :scores game-scores]] Please tell me more about Lisp readability.
- lostmyoldone 8y agoI don't really see how JSX informs us about readability of s-expression vis-à-vis Python et al. Disregarding that, and in my opinion, properly formatted JSX might be a bit worse then s-expr for shorter stretches of code, but if/when you have a longer stretch, the visual symmetry in JSX would seem to tip the scale the other way. If there is a point to JSX, I would claim it's mostly that it looks different than the surrounding code that is the point, as it potentially makes it easier to parse and to clearly separate roles between code and design. While I'm frankly not a fan of either of the above-mentioned, I do find some of the arguments around the brilliance of s-expr to be perplexing. The most confusing argument is the one that s-expressions are good because everything looks the same, which to me sound like arguing that the best way to paint is to only use one color, which I vehemently disagree with. I think the easiest explanation of this conundrum boils down to a rather simple fact. Visual regularity is as confusing to some, as the lack of it is to others. People are different, sometimes shockingly so.
- wyclif 8y ago"Why I Switched from Python to [Shiny Newer Language]" seems to be the thing on HN this week.
- banku_brougham 8y agoI don’t agree that Clojure is a new and shiny thing.
- jaabe 8y agoThe really hilarious part about this one is that it’s from 2016, and the author seem to have since switched from Clojure to Kotlin. I think it’s still interesting to read about people switching. I mean, I’ll never understand why people prefer functional languages to OOP. I think it’s just so much easier to maintain OOP in the long run, and you can frankly build most of the advantages of functional languages within OOP if you need to. But then you read an article like this and you get a reminder that freedom can lead to some really horrible stuff and that is especially true for Python in general. I don’t see this as “we should all switch from Python” sort of thing, but rather a “don’t do these things with Python”.
- bradcypert 8y agoI write Clojure, Kotlin, and Scala all on a pretty regular basis. Truthfully, I do write less Clojure now than at the time I wrote this post, but that's predominantly because my current interest (and salary) are centered around Kotlin + Android. I still write Clojure quite a far amount, but I don't blog about it as much as I'm not "exploring" the language as much. Sometimes, I'll find or create something cool and share it, but most likely that'll be Kotlin/Android related right now.
- yingw787 8y agoMy impression of Python is that it's a Fisher Price Little Tikes coupe with a few GE90 jet turbine hardpoints mounted on it. It's a very simple language. Literally when things get made to be complex Guido says do it the simple way, because when unbreakable things break it's just that much harder to fix. This makes it very easy to debug, very easy to fix/patch, very easy to onboard new/junior developers in, and very easy to start using in production. It's literally a baby. But man, you can do some crazy things in Python if you want. You can write C/C++ extensions sure. You can also use things like orchestration with `py4j` and `jpype` in order to execute IPC with a JVM dedicated to the Python process. In that sense all Python in your application becomes a request layer with the JVM or a binary acting as the data layer, and request layers don't require as much in performance because you only need to issue so many requests. Request layers may also need to change faster than data layers/pipelines, and in that Python's great because it's so flexible. Based on some performance testing our team did there's absolutely no reason to simply switch away from Python, though that may also be due to legacy reasons. I'd like to stick to Python and maintain my Python proficiency going forward (though with Guido out as BFDL we'll have to see how the language evolves). I'd like to maybe add Rust or Elixir to my repertoire and see how they extend my capabilities in ways Python/C/C++ may not. But Python will always be my Swiss Army knife turned combat shovel. It gets the job done.
- iLemming 8y agoAre you implying Clojure is not simple? Have you ever watched Rich Hickey's "Simple made easy" talk? If you haven't, I highly recommend it. Disclaimer: It's not about Clojure.
- yingw787 8y agoI haven’t watched it, but I have heard about it. In contrast to the simplicity of a programming language in the happy path, I’m talking more about simplicity in the case where things break. For example, Python doesn’t implement tail call optimization in part to eliminate stack trace collapses. On the other hand, many reasons my current tool stops working is due to the underlying configuration of the JVM. Configuration management is a leading problem in distributed systems, and a fairly significant one given how it took down both Google and Facebook in two days. Clojure is a lisp on the JVM; I doubt it matters how pretty you write your code if you don’t say allocate enough memory on the heap for the process, and if it implements tail call recursion when that happens you may get an incomplete stack trace. This is more speculation, but I do hope it gives some insights into why you may choose one paradigm for a problem over another. Overall I’d say break your problem domain into subdomains and choose the best paradigm for each.
- anentropic 8y ago`__setup__.py` is not a thing it's `setup.py`
- amelius 8y agoNot sure if it's still a thing, but the slowness of starting the REPL was what kept me from moving to Clojure. Python is doing much better in that regard.
- sridca 8y agoI switched from Python to Clojure (because abstractions), and then to Go (static types; efficiency) and then to Elixir (because work) and then to Haskell (no more lame types and stupid nil errors). I feel like with Haskell I have basically achieved perfection, and I'm more prepared to work on the other languages if the situation calls for it.
- doktrin 8y agoWilling to bet money the author switched to something else by 2017. For the overwhelming majority of developers Clojure is this tinker toy we fiddle with for 6 months to a year before getting bored and fed up with its limitations.
- GorgeRonde 8y agoIf you allow me to compare my very limited experience with Python (hacking SublimeText plugins) to my rather extended experience writing Java or Ruby (i.e class-based languages that traditionally newline-&-deindent closing parens rather than aggregating them in a trailing tiger tail like in lisps) ... ... I would say writing programs in Clojure leads me to writing 10 to 20 times less code on average. I recently rewrote 15000 lines of Java (several weeks worth of effort split in several dozen files) down to 500 Clojure lines (in one weekend and one single file). Anyone else with that kind of experience ? To me this is a tremendous advantage and any argument for code readability is really just argumentation about reading code at a small scale (say one file) that unknowingly makes trade off about reading code at bigger scales (say the readability of a whole project).