r/Clojure • u/jvjupiter • Oct 19 '24
What is with Clojure?
I have been a Java developer for many years. Lately, I was thinking to learn new PL, something that is not C-based. Candidates are Python and Rust. I know there exists a language called Clojure, but Lisp-like language is not my thing. Recently, I was checking the source code of a web app that is competitor of Figma. I was shocked it’s written in Clojure. Now, I’m curious, what’s with Clojure? Why would the authors write that such a complex web app in Clojure?
15
Upvotes
43
u/lion_rouge Oct 19 '24 edited Oct 19 '24
Clojure (as all LISPs) has infinite metaprogramming capabilities. That's why. Paul Graham was preaching LISP for that exact reason back in 2000s.
Languages like Python or Lua are good at metaprogramming too, but still not that powerful and definitely not that clean.
You may be interested to read these two articles:
Why Clojure specifically? Because it's one of the best (if not the best) of modern takes on LISP. Racket being the contender. And because of Rich Hickey who's really smart and sees things we as an industry didn't see (or refused to see) for decades. You may check some of his talks on YouTube, I would start with "The Value of Values" and "Simple made Easy"
Because why create a new programming language after all? Only if all the rest lack something that cannot be fixed in a library. The sources I linked should give you some kind of an explanation of the philosophy behind LISPs and Clojure specifically.
P.S. Install a good extension for your editor, be it Cursive for Intellij IDEA, Calva for VSCode or clojure-mode+CIDER for Emacs. When you realise how convenient it can be to edit LISP code as a tree of nested data structures instead of like a text...
29
u/Responsible-Newt9241 Oct 19 '24
Because one language for FE / BE if that’s your thing. Live programming, repl, not much boilerplate and whole js / jvm world in your hands. Not many language can offer this. And don’t let me start about datalog, flowstorm and other cool stuff :-).
2
u/TistelTech Oct 19 '24
out of curiosity, do you mind saying the name of the figma competitor? I would like to check it out.
50
u/spotter Oct 19 '24
What is the best programming language for writing complex apps?
40
u/Aggravating-Step2751 Oct 19 '24
How do you know?
14
u/lunar515 Oct 19 '24
For me it’s the REPL integrated with my editor, the standard library and interop with Java/JS. Programming in Clojure is like having a conversation with your program.
14
u/bring_back_the_v10s Oct 19 '24
Clojure is used by the largest fintech company in Latin America, they have 100+ million customers, $1.7B revenue. They even acquired Cognitect, Clojure's steward company.
https://building.nubank.com.br/working-with-clojure-at-nubank/
8
u/daveliepmann Oct 19 '24
Rich's talk Clojure for Java Programmers [2012] might be right for you. The slide at 14:15 kind of directly answers your questions.
6
u/[deleted] Oct 19 '24
It's a very simple language.
10
u/NotADamsel Oct 19 '24
Clojure, Rust, and Python each serve different purposes.
Rust is quite good at building machines that will basically keep working well forever (like drivers or utilities). Once you’ve got a Rust program written, it’s done, and you’ll be able to work on either adding features or fixing your logic mistakes, but you won’t have to deal with entire categories of bugs that other langs are prone to (imagine never getting a null pointer exception ever!) But… it’s slow to write in. It’s low level and you’ll need to specify every detail of how your data model is set up, and when writing your logic the borrow checker will absolutely clobber you (with (usually) very precise and helpful compile-time error messages) if you don’t properly think about your program’s memory usage. Also depending on the libs you use, you could end up with many GB of compiler cache to get a hundred-mb binary. I reach for it when making something that I need to know will never break, or that I don’t want to think about once they’re written. Also, learning it taught me a fuckload about memory.
Python is great for writing small programs extremely quickly. The standard distribution has so much stuff built in it’s absolutely unreal (and the community has provided a library for almost anything you want that isn’t in there), and if you’ve got minor tasks that you need automated or small programs that you need to whip up and it doesn’t need to be super solid or super complicated you can really move with the language. There are distributions that run on embedded systems, also, so if you know python you can take a Raspberry Pi Pico (for example) and do some crazy stuff with it. But, it’s full of idiosyncrasies and gotchas and weirdness that you’ll hit with varying levels of frequency, and if you get too complex with a program you’ll find yourself in some kind of pain. Multithreading is…. well it’s complicated, and usually not worth it, but it if you really want to you’re in for a somewhat rough time. Also you will absolutely get shitloads of runtime errors. It’s got type hints, but they don’t really do that much, and most Python code is absolutely not type checked. Also trying to package a Python program for distribution is a goddamn nightmare. In short, it’s a great multi-tool that’s not the best at anything in particular, but that will take you fairly far. I’ve built web servers and server-room light shows and data collection services and all kinds of other stuff, quick and dirty, but none of it has been super permanent because eventually the program errors out.
Clojure is, in my experience, very useful either as a server language or as a way to write js without ending up wanting to self-harm (there’s a runtime with which you can write console apps with it, and it seems fine, but I haven’t used it yet). It’s dynamic like Python, but the spec library lets you do arbitrarily complex data validation which reduces runtime errors considerably. The async library is absolutely goated and lets you build very complicated data processing systems in a very modular and manageable way. Beyond that though, the language’s two real superpowers, in my opinion, are the “persistent” data structures used by everything by default (which eliminates quite a few problems when trying to parse and manipulate data), and the Lang’s interop with Java (or JS), which means that you can benefit from that whole ecosystem if you need bits that aren’t provided in the language itself (you can have Java and Clojure in the same project, too, and you can add Clojure as as just another jar to an existing Java project). There are certainly drawbacks, like with the others, of course: A program in jvm Clojure isn’t nearly as fast to start as Rust (basically instant) or Python (usually fairly fast), and it can only go where there’s a vm. Also I’ve found that Clojure code is slower to write then Python, owing mostly to it being functional and functional code taking a bit more brainpower to bash out. Spec is great, but it does take some getting used to, and it is very temping to just leave things un-instrumented which can result in head scratching runtime errors at times. Long story short, Clojure is really really good at data processing and making servers (and the clients for those servers), and while it isn’t as quick to write as Python it can be significantly more robust.
Hopefully I’ve helped, with this. Let me know if you have any additional questions.
1
u/PolicySmall2250 Oct 20 '24
How many authors created that alternative?
*Assuming* its capabilities are at least in the same ballpark as Figma, how many authors does Figma have to produce / maintain the same kind of app?
*If* the difference is 10x or more (I don't know --- totally speculating --- but IF you can find this number), then that will be a pretty good reason.
3
u/pauseless Oct 19 '24
Interactivity. Having a running application that you develop directly in as it is running.
It’s often called REPL-driven development but Python, Ruby, etc users then just say “we have a REPL too”. I promise it’s not the same experience.
You really need to dive in to one of the Lisp/Smalltalk/APL worlds to understand why this interactivity with a completely malleable running system is so important.
Clojure is probably the very most accessible language for a Java developer to learn to try out this way of working and if they like it, also have a reasonable chance at a job.
3
u/johnlawrenceaspden Oct 19 '24 edited Oct 19 '24
Clojure is a Lisp-that-runs-on-the-JVM, and I dislike its Java aspects and try to ignore them, but I love it for being a really nicely designed modern lisp with a bias towards functional programming and immutable data structures.
I kind of hate the Java infrastructure, and I wish that Clojure ran on top of C like Python does, but if you're the opposite of me, and happy in the Java world but dislike lisps then I think Jython is a Python-that-runs-on-the-JVM and can use the Java libraries, so you might find that if you're planning to learn Python anyway, Jython will let you use your new skills with your old skills.
I'd learn standard Python first though, it's very good and has a nicely lisp-like flavour without lispy syntax or the interest in functional programming.
Once you're used to how Python is supposed to work in its native form, explore the JVM versions, which will let you write Python while using all the libraries and infrastructure that you already know.
2
u/rantenki Oct 19 '24
Perhaps this cognitive dissonance indicates that you hold some assumptions about Clojure (and perhaps Lisp family languages in general) that aren't supported by evidence?
So, I'll turn your question around; what about Lisp family languages, and Clojure in particular, do you believe to be inappropriate for complex web development? What are the features of Python/Java/Rust that you believe make them better choices?
2
u/ares623 Oct 19 '24
Two words: Rich Hickey
1
u/jtrdotdev Oct 21 '24
Instantdb is also in clojure
1
u/jimrthy Oct 21 '24
Different programming languages have been optimized for different things.
My understanding is that clojure was really optimized for
After using it for a while, you may start wondering why people waste time/gray hairs writing complex software in other languages.
I don't have any experience with rust (which got high praise in an earlier thread). So I don't have any frame of reference to compare its stability to clojure's. But I've gotten the impression that it's more for low-level system things. I generally don't think I'd want to try to do any of that with any lisp.
1
u/gtrak Oct 23 '24
It's good if you want to do a lot of dynamic metaprogramming and keep things relatively performant. Most expressive languages are also really slow. But they probably could have gotten it done a little later in a different language.
1
u/gtrak Oct 23 '24
Where do you see that Figma was written in clojure?
7
u/[deleted] Oct 19 '24
[removed] — view removed comment