by iagooar · 7y ago · 0 comments
Yes, in certain environments Java is king and a ton of people use it, it's battle-proven, etc. But so are other stacks.
Clojure, as a programming language, sparks a lot of joy and is a lot of fun to use and reason about. Yet in reality, when working in a production environment, you're basically fighting the always-memory-hungry JVM.
Just give me Clojure running on BEAM and I'll take it over anything in this world.
Not really. Few if any platforms compete with the JVM on performance and observability (monitoring/management) and ecosystem. It's technologically head and shoulders above pretty much all other runtimes (e.g. BEAM has excellent observability, but loses big time on performance and ecosystem). Also, if you're OK with the JVM running at BEAM speeds, you can give it far less memory.
It's an official dialect: https://clojure.org/about/clojureclr
The JVM and .NET are presently about the same capability-wise, but Java is (or at least, is perceived as) much easier and cheaper to freely experiment with. Unless you need to use C# for some deep Windows integration, this makes Java the obvious choice for anyone without sunk costs in the .NET ecosystem.
I'm curious about this. How do you do it in practice? Doesn't it just crash with OutOfMemory errors when it runs out of memory?
I've been running a simple JVM web app on my own personal server with an allocated 128 MB of RAM and a lot of that is actually unused. You can do a lot with a heap of just 64 MB.
People aren't aware, but when running your average PHP app you need more than that with just a couple of requests done at the same time, whereas my JVM server can easily handle 1000 requests per second. Similarly Ruby or Python apps can be big resource hogs, especially when you end up setting up multiple parallel processes.
I was also surprised to find that compilation to "native" isn't necessarily efficient in terms of used memory. I've built a similar app in Haskell and the used memory ended up being higher and more unpredictable. If something like Go fares better, it's not because it is compiled to native.
All in all the JVM is actually quite efficient in terms of used memory, for a garbage collected language ;-)
This is untrue. The default configuration is just to do it very reluctantly, but this can be changed.
ZGC from Oracle -- but open source
Shenandoah from Red Hat -- also open source
I know of no other managed runtime platform with the GC options and tunability as JVM.
Also JVM has not one, but TWO JIT compilers, C1 and C2. Your JVM byte code starts out interpreted. It is constantly dynamically performance profiled. If it is getting above average CPU use then it is quickly compiled by C1 into native code, and scheduled to be recompiled soon later by C2. When C2 comes along, it takes its time recompiling your code into highly optimized native code.
Suppose that YOUR function A calls MY function B. And C2 aggressively inlined my B function into your A function. Now suppose my code is dynamically reloaded within the running environment. Now your function has a stale version of my code inlined within. JVM will instantly de-optimize your code back to JVM byte code interpretation so that soon, if it is still a cpu hot spot, it will get recompiled again by C1 and C2.
Let me know of any other runtime platform that even comes close to the things JVM does.
Some of the more advanced Lisps would qualify.
As Rich Hickey says: because it has _reach_
The JVM is widely used.
ClojureScript on JS is because JS also has reach.
It's really easy to introduce Clojure into a Java shop, because if things go south, you can throw away a bit of code and replace it with Java. Heck, people on other teams don't even have to know this started as Clojure code.
Asking people to learn both a new way of developing and a new VM? Too much all at once, which is why Clojure spread as far as quickly as it did.
With Clojure being a hosted language, there's nothing stopping it from adopting a new platform or expanding to other platforms or languages. It has actually already done this with Clojurescript (run in the browser or Node.js)[1] and Clojure CLR (run on Microsoft's .NET)[2].
[1] https://clojurescript.org/ [2] https://clojure.org/about/clojureclr
But it's still definitely niche and hardly used anywhere.
Groovy, Scala and Clojure were the early contenders that people were exploring and Clojure seems to have won a lot of mindshare.
The thing about Java isn't the language or the JVM it's the App Servers. Enterprises have invested heavily in the App Server infrastructure for deploying JVM based code from monitoring, training, etc.
Throwing all that away to use a non-JVM language is a REALLY hard sell. Those app servers are very well done.
Running on the JVM made using Clojure, Scala and Groovy possible in places where other languages wouldn't have been. In the early 2000s, it was Java and everything else.
The .NET ecosystem was awful at that time. The programming world was essentially, Java, Perl and PHP 4 in terms of enterprise usage. People said the words "Enterprise Java Beans" without a chuckle.
People were HUNGRY for better options.
Now you've got a solid C# ecosystem, Elixir, Go, a dominant Python ecosystem, significantly more polished PHP, K8's & Docker that make automating the infrastructure around all different languages consistent...it's just a different world.
It still kind of is in a lot of places. My country barely bothers to even teach anything else at a lot of schools, and enterprise is almost entirely dominated by the JVM.
You are exactly right. Having worked in Clojure and talked to a lot of other devs here and across Europe, most everyone got into Clojure or Scala because management and cultural complaints left them stuck with the JVM, and at least it beat building more EnterpriseWidgetFactoryGeneratorPatterns.
Oracle and Java are the new IBM, and just like IBM, no one's really happy with them but management yells if you use anything else.
I love Clojure and hope it gains more mindshare, but I don't think this is accurate. Scala currently enjoys quite a lot more industry use than Clojure does, for instance there are currently roughly 15x as many postings mentioning Scala as there are Clojure (source: Linkedin.ca).
https://snyk.io/blog/jvm-ecosystem-report-2018
https://www.jetbrains.com/research/devecosystem-2018
It's entirely possible that companies tend to hire for Scala via Linkedin a lot more than for Clojure.
This is true, but...
> Groovy, Scala and Clojure were the early contenders that people were exploring
... Jython and BeanShell were much earlier than those three.
Jython, JRuby, Rhino, and Clojure are JVM languages that are syntactic copies of existing non-JVM languages, and it seems JVM developers didn't want these. Clojure has won within that group.
But the other group is what developers really wanted, i.e. languages with a Java-like syntax but with extra features added. Beanshell came first with dynamic typing. Then Apache Groovy cloned Beanshell and added closures, and Beanshell never kept up. Scala had all that but also had inferred static typing, which Groovy later added but was too late to the game to have much impact. Kotlin then came and merged the best features of Scala and Groovy, and became successful on Android.
re: ABCL: this is really a great project. I don't use ABCL very often but when I need it I am grateful to the developers.
Protocols, records, structmaps, chunked seqs, transients, tagged literals, unchecked arithmetics, primitive arrays, custom data readers, transducers, validators and watch functions for vars and atoms, hierarchies, sorted maps and sets.
Clojurescript was much easier to make because it was written in Clojure, not Java. IMO if we ever see Clojure that is hosted on other runtimes it will be written in Clojure and probably still will have to depend on JVM.
IMHO, Clojure's use of the JVM was something of a Faustian bargain. (But net worthwhile).
Reasonable people might disagree, but there is a huge amount of value in having access to a good JIT, GC, and standard library - not to mention the ecosystem around the JVM. Keeping in mind that Clojure started out as a one-person, self-funded project, it was a very reasonable thing to borrow all of this from an existing well-established language. Maybe these things could've been reproduced, but not in the approx. two years that were initially available, and it's not at all clear that building a JIT, GC, etc. would have been the best road to making a useful impact.
My self-interested perspective on Clojure today (as an expert in a couple other Lisp niches) is that I'd be happy to learn Clojure if someone would pay me to, but it's not relatively attractive to me now, in the ways that a Lisp is more attractive than a non-Lisp. (Nor in the way that Rust is in some ways more attractive than C and C++. I've been a senior developer in those, and Rust is sufficiently different, and might open some new doors.)
If we just look at developments of the last 5 years, and in particular serverless, it's been about taking advantage of those short startup times to use in a server context. When you take that into account, these languages become even more in the lead.
I think the next lisp that has a chance to really take of will be one built on wasm.
MRI ruby had always had a fast startup time and was not originally created for the web... it’s more like a “better” Perl cum toolkit for C/unixy stuff- ironically what python became more popular for despite python not originally being written for that purpose.
Also in the old days of the web.. CGI was literally spawning a process per request.
Regardless it’s bizarre to think nodejs pioneered startup time... Ruby, lua, python, and good lord Perl would really like to have a word with you for starters.
Java was really more the exception.
And I’m not sure it’s true that these serverless platforms are spawning a new process per request ... but wow what is old is new again. Sounds like you’re describing inetd (look it up). Nothing of what you’re talking about is 5 years. Try 30-40.
The 2010s the trends changed towards languages that specialized in faster startup times. That led to serverless.
No one said that these are new inventions. Like all trends its cyclical. I'm just pointing out the trends in order to better understand where Clojure fits in.
Like I said the Java (and .NET) were the exception. As far as trends... java and .net dominate enterprise and they still do. The trend is very slow in the grand scheme.
Frankly your comment seems to be conflating language issues with framework issues with “serverless” and even scripting. I don’t think there is a cogent argument to be had about overall trends with all that. Yes lambda and serverless are a thing but half the whole world still runs on JavaEE or ASP behemoths
That already exists: http://try.clojerl.online
It's a community maintained dialect. Its maintainer, Juan Facorro is very active. You can see him giving a talk about it here: https://youtu.be/Ow8o9Mm_N7M
I'm sure all the project is in need of are more adopters to really get it off the ground. Check it out!
Immutability and dynamic typing make it perfectly suited for BEAM.
BEAM is also more suited for Clojure. Less powerful CSP and awkward component would be replaced by the actor and supervision tree.
I know the problem, and I've danced around this same issue in things like Haskell with strictness annotations, and I've run into the same problem in R, but I'd like to just be able to read and parse a ~1GB CSV file without blowing out RAM with a giant list of thunks.
This was many years ago now, so maybe they've fixed it, but I'm tired of fighting that particular battle.
There's now fully lazy as well as fully strict variants of all sequence functions.
What you want to look into are transducers: https://clojure.org/reference/transducers
Also, the lazy operations were made batching. So they are better optimized now in memory and performance.
Isn't it more or less what Elixir is?
Here's the view of someone who went from Erlang to Elixir: https://www.theerlangelist.com/article/why_elixir
1. clojerl language: https://github.com/clojerl/clojerl
2. kapok language: https://github.com/kapok-lang/kapok