Live data from Hacker News

Why Clojure?

blog.cleancoder.com

151–160 of 202 posts

Re: Why Clojure?

#151
post #94

The response to "but is it slow" is pretty disappointingly bad. > No. Clojure is not slow. Oh, look, it’s not C. It’s not assembler. If nanoseconds are your concern than you probably don’t want Clojure in your innermost loops. You also probably don’t want Java, or C#. But 99.9% of the software we write nowadays has no need of nanosecond performance. I’ve built a real time, GUI based, animated space war game using Clo…

The biggest thing keeping me from ever seriously learning Clojure is the JVM. Slow startup time means I'd never use Clojure for "scripts", and I certainly don't want to have to manage the JVM in production scenarios, so when would I use Clojure? If there was a native version that could produce static binaries like Go/Nim/Rust I'd be much more interested to learn it.

I found managing production JVM is amazing. In fact, little other runtimes come close in my opinion. What don't you like about it?

For scripting, there's a lot of ways to script efficiently with Clojure, it's actually great for it as well. So, for most my scripts, I don't really mind waiting 1 second for them to start. That said, if you wanted them to start faster, using ClojureScript takes you under 100ms. And using Joker (https://github.com/candid82/joker) takes you under 50ms.

When I need even faster startup for scripts and also need performant runtime, I've been using GraalVM to compile to native binaries, those start in under 10ms, and execute much faster than ClojureScript and Joker. That's a good strategy if you want to write things like a grep tool, or ls, or a linter, code formater, etc.

Re: Why Clojure?

#152
post #104

Earlier quoted context omitted.

You're right, one is a language with a data-structure-centric approach to problem solving and an emphasis on pure transformations of immutable nested trees and lazy sequences, and the other one forces you to learn the word Monad. Edit: Joking aside, I do think you're right in terms of the ideological foundations and organizational structures of the two languages (clojure's emphasis on practicality, curation and evolu…

Your flippant comment is not constructive, nor is it very accurate in my experience. The last Clojure team I worked with decided to add “rop” to our project. The documentation in this library seems to go to great lengths to avoid using the word “monad”, despite the fact that the entire idea being encouraged by this library is monadic composition, but specialised to the Either monad. I mean come on, this library even…

I'm not sure I follow your complaint about "rop" (which is a library I'm not familiar with), and I suppose my jokiness obscured the point I was trying to make, so I'll try reiterating, since it seems like you're talking past it (I will also try to address the points you raise).

First, to be clear, haskell's type system is powerful and interesting and useful, and clojure's lack of good static analysis tools IMO represents a serious [comparative] deficiency in the ecosystem (and spec is obviously no substitute). I don't think that it will ever be possible for clojure to get even close to the sort of compile-time checking/guarantees that haskell offers, nor do I think clojure is particularly well-suited for the powerful higher-level abstractions that you see in e.g. lens or recursion-schemes (or, honestly, even Control.Traversable). My personal experience (both as a hobbyist and professionally) has been that there are some practical advantages from clojure's dynamism such that it probably makes sense (in a cost/benefit sense) to eschew static typing in some/many circumstances, but I really only have anecdotal evidence plus some intuition backing that up.

That aside, the point I was trying to get at was that both haskell and clojure encourage you to build complex data representations out of simple, easy to understand, composable, persistent structures, and then build up computations by composing pure transformations on them. Additionally, both languages have reasonable concurrency models/primitives, good tools for creating expressive DSLs (if that's your thing), and powerful interactive development environments. I, personally, find all of these features to be incredibly important for effectively developing software--they shape in a very real way the processes I use to plan and write and debug code--and most languages in common use today lack at least a couple of them (some languages have none of them, in fact).

Re: Why Clojure?

#153

Earlier quoted context omitted.

How long have you been programming professionally? Did you have prior experience with dynamic languages? If so, how much? Did you have prior experience with statically typed languages? If so, how much? I'm trying to see if Clojure requires more fundamental programming intuition and experience to sustain in large projects. I work with tens of thousands of Clojure LOC, I don't feel these issues and can't relate, and lo…

12ish years (more as student & hobbyist), lots (mainly python, javascript and clojure), lots (mainly Java and C++, sadly inly got to tinker with better type systems). I consider myself a clojure developer and have been using it on and off since summer 09. Im using it for a large project now. And yet... I agree with GP. I love clojure, but over time I’m becoming less and less sold as dynamic typing. Spec helps, a litt…

Very interesting, and thanks for answering.

Could I ask what kind of project it is? I wonder if I'm just lucky that Clojure fits perfectly my use case, which is mostly a set of distributed systems of all kinds. So while as a whole there's tens of thousands of LOC. The components have very strong boundaries being as it's a set of services assembled together through RPC, PubSubs and DBs. Maybe that alleviate the lack of a static type checker.

We've adopted Clojure about 3 years ago, team of 10. We've had a few people leave and join throughout. Only one person knew Clojure beforehand. Our stack is about 50% Clojure, 40% Java and 10% Scala. Of all three, Clojure has given us the least issues, has been pretty easy to maintain and generally has fewer defects. Java tend to have the most bugs, almost always related to some shared state. Scala I find the hardest to extend and maintain, but the code base we have for it I think does Scala wrong, it's like the worst mix of OOP and FP.

> I dream of a statically typed Clojure with type inference, spec-inferred types and optional dynamic typing for REPL experimentation and glue code

That's pretty much exactly core.typed: https://blog.ambrosebs.com/2018/09/20/towards-typed-clj.html

That said, the project never managed to get more contributors.

If you're looking for a typed Lisp, I've been keeping my eyes out on Carp: https://github.com/carp-lang/Carp

Re: Why Clojure?

#154

Earlier quoted context omitted.

I've been told that before and respect your experience even if it is very different than mine. Let's talk about writing code in Python. You write a script and either run it through your IDE or via the command line via Python pythonscript.py. With D, I write some code and feed it through the compiler like dmd scriptname.d. With Clojure in addition to all the cruft I have to learn (Emacs, leinegen...etc), I still have…

You can run Clojure without Leiningen and you definitely do not need to learn emacs. I use vim, but Cursive (IntelliJ plugin) is IMHO the most beginner friendly option available (other good options include Nightlight, Atom with clojure olugin, VS Code with plugin). You can run Clojure without learning Leiningen with many of these too.

How does one not use leiningen? Do you just substitute lein for the other build tool provided by cognitect? All the tutorials I've seen have you jack-in to a lein REPL. I guess I could just use the jar file from the download directly as my REPL? I wish more tutorials started that way so I could learn without all the tools that I don't need at this point.

Thanks for helping point this out. Cursive has a trial license and is pretty cheap, but it is still annoying to get a license to something you might not need in my organization if others aren't already using it (probably easier to get visual studio for over $1k than $100 cursive license). VS Code asked me for the leiningen REPL path and I just gave up at that point for the night. I wish the Clojure download zip came with a very simple IDE like Dr. Racket or the GroovyConsole with line wrap, parenthesis matching/highlighting and a pane for the file and REPL and some pre- loaded tutorials. I would have no excuses.

Re: Why Clojure?

#155
post #95

Earlier quoted context omitted.

Not the grandparent, but I realized the other day that I'm at nine years of clojure, so... What's made clojure so great, imo, is its unicorn status as a principled-yet-practical language. That "principled" part is not worthless---it means that a lot of great minds are drawn to it. Before react took over the world, clojure folks were already taking steps in that direction. A lot of other things. The "sequence" as a co…

What is GUI programming like in Clojure? What libraries exist, and what paradigms are used? E.g. is it more like React or is it more like Gtk/Qt?

For frontend Reagent (React but with just Clojure functions and data structures. No classes, no jsx, just one language and immutable data.), and re-frame which does state management and event dispatching better than the competition. Redux is a poor poor imitation.

Re: Why Clojure?

#156
post #109
post #103

Earlier quoted context omitted.

By contrast, one principal reason I started learning Clojure was ClojureScript. Making stuff that can run in the browser or as a browser extension is awesome for cross-platform compatibility.

If you like "functional and runs on the JVM" you might like ScalaJS too. It's a mature transpiler, and the community has rallied to ensure that all the important libraries compile both to the JVM and to JS.

[deleted]

Re: Why Clojure?

#157
post #5

It just breaks my heart to see Uncle Bob seduced by a Java-family language right when C++ is getting increasingly fun. He suffered through the bad old days when C++ was only fast and powerful, and is now missing out on the good new days. I guess he's happy. At least he isn't touting Haskell. Bon Voyage, Bob! But somebody needs to break it to him that Lisp is not a functional language. Or, if it is, so is C++.

> But somebody needs to break it to him that Lisp is not a functional language

Lisp is not a language at all. It's an idea. And if you grok the awesomeness of that idea you can make any kind of language using it: functional, OOP, relational, whatever.

Bob is talking about Clojure. Clojure is a functional Lisp.

Re: Why Clojure?

#158
post #131

Has anyone done both elm and clojure script for Web work? Which did you prefer, which had the best tooling etc? I need to learn Web, as mucj as I don't want to, and love clojure and fp. Also figwheel looks awesome, but how hard is it to setup. I also think maybe to really get the best out of clojure script you also need to learn react?? I'm not sure this is the case with elm. Any other non js alternatives?

Elm's FFI is a bit painful compared to Clojurescript's. With Clojurescript you can target Node, browser or mobile (with something like Re-natal), but it truly shines when you have Clojure on the back-end. Clojure runs on JVM and many people (for all the wrong reasons) don't like that.

You don't need to learn React to start using Re-agent or Re-frame.

IMO among all alt-js languages, Clojurescript is the most practical and production-ready.

Re: Why Clojure?

#159

Earlier quoted context omitted.

You can run Clojure without Leiningen and you definitely do not need to learn emacs. I use vim, but Cursive (IntelliJ plugin) is IMHO the most beginner friendly option available (other good options include Nightlight, Atom with clojure olugin, VS Code with plugin). You can run Clojure without learning Leiningen with many of these too.

How does one not use leiningen? Do you just substitute lein for the other build tool provided by cognitect? All the tutorials I've seen have you jack-in to a lein REPL. I guess I could just use the jar file from the download directly as my REPL? I wish more tutorials started that way so I could learn without all the tools that I don't need at this point. Thanks for helping point this out. Cursive has a trial license…

If don't like or do not want InteliJ with Cursive or vanilla Emacs or VSCode, you can still use Vim, Eclipse, Atom, Spacemacs. The days when Clojure could be used only in Emacs are long gone.

Re: Why Clojure?

#160
post #131

Has anyone done both elm and clojure script for Web work? Which did you prefer, which had the best tooling etc? I need to learn Web, as mucj as I don't want to, and love clojure and fp. Also figwheel looks awesome, but how hard is it to setup. I also think maybe to really get the best out of clojure script you also need to learn react?? I'm not sure this is the case with elm. Any other non js alternatives?

I have about two years of professional experience working with ClojureScript, and about three years professional experience working with Elm.

There’s almost no comparison.

Elm compiles much more quickly.

Elm produces much more performant code.

Elm enables you to write software that works reliably much more quickly because type errors happen at compile time, rather than at runtime like in ClojureScript.

ClojureScript’s error messages are at times incomprehensible. Elm’s error messages are best in class.

Elm is far easier to learn than ClojureScript, and you’re right — you do need to know React if you’re writing a non-trivial ClojureScript application.

Elm is criticised for not allowing a synchronous IO escape hatch. This is a pretty bad criticism I think. Being able to guarantee where effects won’t happen is a pretty great thing. Any effects work and/or JS interop can be done with ports. Ports work just fine.

Elm is also criticised for denying the user a lot of “power features” like typeclasses. I find it mildly annoying sometimes that I don’t have everything I want, but I understand the trade-off. This is to make the language more accessible to your average JavaScript developer who has never tried anything from this family of languages. And I sure as hell don’t find it annoying enough to want to drop the type-checking compiler.

Post reply on HN