182 points · by yogthos · 7y ago · 265 comments
Less state or immutability means concurrency is easy. Easy concurrency means we can scale[2] applications with ease. I mean ease of development. It takes less work, less mental effort to take something that works for a single thread and make it work in a multithreaded and/or distributed manner over hundreds of thousands of cores. Debugging is easy too. P1 incidents for a microservices written in Clojure takes less time to debug compared to those written in other languages. So no wonder most of our mission critical services are written in Clojure.
For a complex environment where thousands of microservices are deployed on hundreds of thousands of computes, Clojure has been super successful.[3]
[1]: https://github.com/walmartlabs?language=clojure
[2]: http://blog.cognitect.com/blog/2015/6/30/walmart-runs-clojur...
We use Clojure at my work as well, and ya, everything else you said afterwards is true as well. Clojure is a great productive language. It can scale, is very comparable to Java in performance, simple to maintain, has a complete ecosystem, is batteries included, etc.
But most convincing! It's just so much fun!!
Being fun is an undervalued quality of a language in my opinion. That joy you get from using it actually translates in the quality of the work you do. So it's not an intractable thing, the fun is good for you and for the product!
Day job is great but spending more than half of programming time modernising some of the worst PHP I've ever seen gets old after a while.
Kotlin is actually a pleasure to use so I look forwards to using it.
That said, Clojure has to be seen as the sum of its parts. It's the coming together of Lisp, FP and the JVM which truly gives it its strengths.
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
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 ;-)
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).
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.
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.
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
[1] https://insights.stackoverflow.com/survey/2019#technology-_-...
[2] https://insights.stackoverflow.com/survey/2019#developer-pro...
I think Clojure is awesome and have used it for some projects but I also think that causal relationships in the SO survey are often completely misunderstood.
I think in practice most less experienced developers cannot justify investing their time in such a niche programming language as Clojure. It's not like Clojure developers are paid best because they are the most experienced. It's because they could afford the time to master a programming language with very little demand on the job market.
I don’t want to imply that these surveys are rubbish, just that I do not think they give the whole picture
Together, these cover cloud programming, web, embedded, desktop, mobile, OS, networking, games, machine learning, data science and probably quite a few other industries.
The only languages I can think of that see quite a bit of use and that are missing are Lua and TCL; and some of the more obscure ones that would still have been interesting are Ada, some MLs, Haskell, and CommonLisp.
Why do you believe that this list is biased towards web development?
And, out of curiosity, what languages are you working with? By your mention of Emacs, I'm thinking maybe some kind of Lisps?
1) Lexemes have a specific structure.
2) Core data types have a specific syntax (representable with a grammar).
3) The data types used to represent programming constructs also have a specific set of syntactic rules by which they are assembled.
It's a different kind of syntax than the usual - more raw/direct, perhaps - but it's a misconception to say there is an absence of syntax. A big part of the reason I mention this is that the nature of Lisp's syntax is one of its biggest strengths.
Complex syntax introduces a ton of mental overhead, and it's a constant source of weird and hard to debug errors because code often does something subtly different from what you think it's doing. S-expressions enforcing a consistent and explicit syntax frees up a ton of mental space for me.
Arithmetic doesn't even look right in programming languages with infix operators. Go to the "Chalk is still one of the primary tools of mathematicians" article here, and try typing the inequality in Java. Mathematicians aren't writing "Math.floor()" and "% 2" on their blackboards.
I think you're optimizing for the wrong thing. Arguing that we need infix operations for 1% of our programs, so that arithmetic looks like how we entered it on a TI-81 or Apple II, is a false economy. It was a good tradeoff 25 or 50 years ago, but the majority of programming has moved past writing programs in terms of arithmetic on registers.
That said, there is a nifty macro [1] which adds infix support to Clojure, if you really want that. It even supports symbols like "√", unlike any other language I can think of!
It's also pretty easy to add prefix operators in e.g. Haskell or ATS (for something like square root)
I've been spoiled by Scala, but certainly most languages allow a "subject.verb(object)" style for general-purpose code, and that reads a lot better (particularly for those looking from the business domain) than "(verb subject object)".
> It even supports symbols like "√", unlike any other language I can think of!
Heh, again I'm spoiled by Scala, where √ is just another method/operator (there's no distinction) name if you want it to be.
It’s similar to learning declensions in Russian/German/Latin: weird and seemingly pointless to English speakers, and then usually fully internalized after a few months, with better intuition for costs and benefits of syntax vs cases.
I’d argue that the Clojure learning curve is significantly shorter than that also.
The best criticisms of Clojure (and I’ve written a lot in it) have nothing to do with parentheses, but rather the difficulties of grokking other people’s dynamic, untyped code.
Some programmers think types obviate the need for docs. Some programmers think concision obviates the need for docs. Except in the most trivial cases, they're both wrong.
Our whole stack is Clojure/Clojurescript. Clojure has helped reduce bugs and improve stability across the board.
I enjoy writing it everyday and wish more people would give it a shot.
At the same time Clojure benefits from being a hosted language. We don't have to build everything from scratch, instead we leverage two of the biggest ecosystems and reap all the benefits for free.
It's still a very niche language to be sure, but from what I've seen there has been a lot of commercial adoption in the last couple of years. There are new a few consulting companies, such as JUXT and Metosin, that are focusing exclusively on Clojure consulting. A lot of the libraries in the ecosystem are now maintained by these companies as opposed to individuals. There are also efforts like Clojurists Together for funding Clojure projects sustainably. These efforts would not have been possible without growing commercial use with companies willing to donate money.
So more companies using Clojure directly leads to a better ecosystem, and that in turn makes the language more attractive. The state of tooling and libraries is dramatically better today than it was even a couple of years go. I'm excited to see how the ecosystem grows this year.
One of the projects I'm most excited about is https://cljdoc.org/ which aims to provide a one stop shop for polished Clojure library documentation. I just saw a presentation about it at Clojure North, and I was very impressed with where it's at already.
Btw, thank you for all your open source projects and comments on various GitHub repos.
Lisp is used in AI. https://medium.com/ai-society/the-lisp-approach-to-ai-part-1... https://ai.stackexchange.com/questions/2236/why-is-lisp-such...
Oof. So true, I hate this field. But I guess you could say similar of almost anything. Maybe I just hate humanity.
You left out the immediately following bit, "Experienced software developers don't chase the hype". I cringed. But maybe if my interpretation of the overall point is correct, I can agree with a point that Clojure attracts grumpy programmers who have Seen Things and gives little lip service to beginning devs.
Where I work we have 3-4 different ways of accessing our monolithic backend, and on top of that 3-4 different ways of accessing and manipulating application state.
It drives me up the fucking wall.
I'm not sure I agree with the little lip service statement. I feel like the feelings are most likely mutual.
Stable systems that don't need constant heroism and don't diverge much from original choices made at the architecture level don't make for good places for juniors to make mistakes and learn from them.
Agreed. Data storage and transmission formats have the potential to dramatically outlast the modules where they originate. This is in large part because these things represent commitments to others, where the internal design (or implementation language) of a specific module really doesn't. So, these days I tend to be much more interested in the design at the interface level than anywhere else.
This works both for and against languages like Clojure. It works for it, to the extent that fewer people have to care what you use when you're building the innards of something. Against it to the extent that it can put a potentially relatively low bound on the gain that can be realized through the use of better (?) tooling like Clojure.
(There's also something to be said for the fact that languages like Clojure tend to snowball in my experience better than other languages. A single program written in Clojure is nice, but it's in the ecosystem/network effects where it really pays off... and that takes a lot of time to see. More than most people take.)
It's actually a pretty sizable moat. Python broke encodings between 2 and 3 and split the community for at least a decade. Some companies will likely never be able to migrate from Python 2 to Python 3. Now imagine breaking now `dict` works.
https://bytes.yingw787.com/posts/2019/01/26/concurrency_with...
Although there's Luminus web frameworks are generally frowned upon in Clojure-land which concedes mindshare to other languages which recognise the importance of frameworks and killer apps. With so many languages competing for mindshare it is that much easier today for a language, however original and superior, to be sidelined by paying customers. For developers looking for a language which will also help pay the bills Clojure is unfortunately not an option.
The chickens, experienced Clojure devs, don't need a framework, and are easily able to do whatever they want and use Clojure to pay their bills. Thus they're not motivated to build frameworks.
On the other hand, the eggs, devs unfamiliar to Clojure, find it difficult to get anything done in Clojure, and are looking for frameworks that abstract away some of the expertise needed to manage a full Clojure web app. They're hoping they can start using it to pay their bills before they become an expert in it, through the use of a framework.
I'm not sure how the future will unfold here.
Traditionally, web was all about serving static documents, and server side rendering model is a perfect fit for that. However, nowadays we also have web apps that are highly interactive.
This requires moving away from the thin client model. Server-side rendering approach is inherently at odds with that because HTTP is a stateless protocol.
So, the modern way to write web apps is to have a thick client that manages things like views, business logic, and state in one place. With this approach you no longer need a complex framework on the back-end because vast majority of the complexity moves to the client. The server is mostly responsible for things like data governance. The other driver here is horizontal scalability. It's much easier to scale small stateless services than a giant monolith.
Clojure started getting a lot of use in the wild right around the time when SPA model started taking off, and I think that the ecosystem reflects that. We tend to have fairly light weight back-end architecture coupled with a thick client on the front-end.
it already has reached an unprecedented level of adoption for a Lisp used in commercial software. But I agree with you - it would be nice to see it grow faster and bigger.
From technical evaluation - Clojure has an amazing ecosystem. But having technologically superior toolset does not guarantee success, nimlang is a good example.
What Clojure needs today is better marketing. It is fashionable to blame Cognitect (basically for anything), but the truth is - they are not a big company. Even if they really wanted it - they don't have enough people to drive it to wider success.
There are a few large companies using Clojure in production today, companies like Apple, Walmart and Cisco. It would be nice if they recognized the importance of Clojure and put some effort to evangelize for it, support initiatives like ClojuristsTogether, sponsor Clojure events.
> For developers looking for a language which will also help pay the bills Clojure is unfortunately not an option
From my own experience - the reality is the opposite. There are too many people interested in Clojure, but not enough developers with real Clojure experience. And companies using Clojure desperately want experienced Clojurists and often willing to pay more. It's disproportionate - we need more companies using Clojure, willing to hire juniors. We need to improve the funnel, making it easy to get into Clojure and become an expert fast.
if one ignores the 80s / early 90s of the AI boom
And poor startup times, and unhelpful error messages (though I hear there has been some improvement in recent versions).
[1] https://atom.io/packages/proto-repl [2] http://gorilla-repl.org/
Personally, I find maven repos and lein to be one of the better dependency/build ecosystem of any language. So I disagree with your premise. But, if you don't like them, there's a lot of alternatives.
For dependency management, there's now an official one, maintained and bundled with Clojure, called `tools.deps`. It supports multiple providers, currently maven repos, git repos and local folders.
For build tasks, appart from Lein, you can use Boot or Gradle. But there's a new trend now to rely on individual Clojure programs as the foundation for build tasks, which are then packaged and distributed through `tools.deps`. You can see their full list here: https://github.com/clojure/tools.deps.alpha/wiki/Tools
In the ClojureScript world, there are less build options, but `shadow-cljs` has emerged as a replacement for Lein, and gained a lot of popularity, because it integrates transparently with npm.
I'm also not sure what the problem with Leiningen is, it's a hell of a lot better than most build tools I've used. If you want to see brittle, you should take a look at NPM clusterfuck. Yet, people happily use that mess all the time.
Poor start up time is typically not an issue for web applications, which is the primary domain Clojure is used in. Meanwhile, at dev time you're using the REPL, so you're not restarting your app all the time. I often have an instance of the app running for weeks on end as I work on it. For environments where start up time matters we now have ClojureScript on Node and GraalVM.
The error messages are indeed a huge improvement in Clojure 1.10.
Even on Linux I have run into package management issues with lein1/lein2. I should say a build tool should largely be stable, not changing it behavior. On many functions like how you use local jars the features and methods have changed drastically at various points of time in Clojure/lein. This kind of churn has even effects like invalidating much documentation already written, and many stack overflow answers too. Why should an application developer be distracted by issues like these?
Most importantly if Clojure development is essentially depending upon lein, then I feel it should be distributed with Clojure itself. And emacs, cider, nrepl and lein chain has so many parts which are getting version upgrades independently, it breaks frequently for the user, functionality that was working suddenly stop working after an upgrade and you have to debug why it stopped working. Also I wonder how complicated it might be to set up the whole chain on a Windows machine.
Clojure now has dependency management built in with deps.tools that ships with it. It's simpler and less opinionated than lein. So, perhaps that will address the problem with getting started on Windows.
[1] https://marketplace.visualstudio.com/items?itemName=cospaia....
In addition, you do not need to use nrepl. Clojure has a socket repl and a socket prepl as of Clojure 1.10
It's a 4 year old project at this point, and in my opinion the easiest way to get started with cljs for a newcomer. It has sane defaults, and incorporates a ton of effort to "just work", such as with regards to the effortless way that you can pair it with npm or yarn to pull in arbitrary JS libs.
* actually three - if you include CLR
The Clojure system can be treated as a RMDB using the Lisp language, RMDB Schema (Clojure Spec) is a static type, and SQL (LISP) is a dynamic type.
It is an example of the best combination of dynamic and static types.
It's innovation, simple, practical and reliable.
https://github.com/linpengcheng/PurefunctionPipelineDataflow...
Clojure -> DBMS, Super Foxpro
STM -> Transaction,MVCC
Persistent Collections -> db, table, col hash-map -> indexed data
Watch -> trigger, log
Spec -> constraint
Core API -> SQL, Built-in function
function -> Stored Procedure
Meta Data -> System Table
In the latest spec2, spec is more like RMDB. see: https://github.com/clojure/spec-alpha2/wiki/Schema-and-selec...The main development goal of clojure is to write the database. The development idea is actually from the database, not the FP.
With reference to the database, as long as I use spec to strictly define (standardization) the core data model, I can ensure the correctness of the system.
I've turned the traditional work of ensuring code correctness from in-code type system validation to data self-validation. Turn the work into verifying the core data model instead of validating the input and output data types of the function.
Similar to industry, verify that all finished products meet the standards before entering the warehouse. Also similar to databases, verify their compliance before data enters the database.
That is "Data as a service, Warehouse as the core, operates around it".
A system requires only a few core data models, and development is built around the core data model.
Persistent data structures ensure that the modification of the immutable big data model are high performance and memory efficient.
In addition, using my pure function pipeline data stream (https://github.com/linpengcheng/PurefunctionPipelineDataflow) makes debugging, parallelism and extension very simple.
from: https://github.com/linpengcheng/PurefunctionPipelineDataflow...
This seems a tenuous theory. Clojure has been described as a language for data processing, but this isn't the same as basing the design on relational databases. Clojure isn't even relational; its data is generally kept in standard collection types, rather than relations.
I'd describe Clojure as a dynamically typed, functional Lisp that emphisizes open data models and explicit time.
[0] for example, nobody uses the STM implementation
I'm baffled: give people a powerful tool that can simplify and bring enormous joy to work with two, most popular platforms of all time, even making it possible to share code between completely different worlds - they'd still be complaining about it.
https://insights.stackoverflow.com/survey/2019#technology
As much as I love Clojure, it's still a harrowing language for beginners to learn and use. The learning curve is just too high. If you have to learn category theory in other to handle basic programming flows, then there's just something wrong.
Elixir, for instance, has many functional primitives, but isn't dogmatic about it. It can "feel" like traditional OO-style programming without the cruft.
I have worked with several people for whom Clojure was the very first PL they have learned and they were very successful. One thing is nice about Clojure: it stays consistent - the idioms, data structures, conventions don't suddenly change. In most other languages - you pick up a framework, you try to learn it and it feels like you are learning a whole new language.
Yes, Clojure can be very intimidating and confusing for the beginners but its learning curve is not steeper than of Java's, Ruby's or Python's.
I say this as someone who uses CLojure and has at best a very sleight understanding of category theory.
[The Pure Function Pipeline Data Flow](https://github.com/linpengcheng/PurefunctionPipelineDataflow)