Live data from Hacker News

Why I like Clojure

sulami.github.io

51–60 of 155 posts

Re: Why I like Clojure

#51

Clojure Help: This is super apropos since I am JUST learning Clojure via the Clojure Koans. Any tips from clojurists on getting the repl (and readline) working fluently? I'm using Leiningen but it's not responding as I'd expect. I would think this would all set up more effortlessly. Tips on getting a new Clojure setup working would be appreciated.

> Any tips from clojurists on getting the repl (and readline) working fluently? I'm using Leiningen but it's not responding as I'd expect. I would think this would all set up more effortlessly.

For me, Boot[1] has completely replaced Leiningen, and I wish it was used by all new Clojure projects, when deps.edn[2] is not enough.

[1] https://boot-clj.com/

[2] https://clojure.org/guides/deps_and_cli

Re: Why I like Clojure

#52
post #37
post #36

Earlier quoted context omitted.

You are absolutely free to decompose computations into more `defn`s, `let` statements, or threading operators. Or mix and match those.

You are 100% right but I am not writing all the code. My job is mostly maintaining other developers' code. And turns out, languages can have great effect on making not-so-good developer write reasonably good code (Go, for example).

One thing I've come to realize is that it is not enough to write code that's merely compilable. That's a low bar. A team needs a consistent style and that has to be enforced automatically. Automatic formatting is a good first step but that's also not enough. Say you don't want too many nested s-expressions. Then write a tool to reject code that has too many of them. Run the tool together with the compiler. Prevent merging if the tool complains unless a special exception is noted.

Tooling is important.

Re: Why I like Clojure

#53
post #32

Need someone to explain why I should use clojure over scala because typelevel seems pretty well developed

Clojure is concise, expressive, not noisy, opinionated (with generally appreciated opinions), dynamically typed, a Lisp, functional with some escape hatches (but not confused with being FP and OOP), and built to solve real problems. Scala is either the opposite of these, or at least not as much of these. IMO, less code is better. Clojure is about as terse as you can get and still be readable (by my opinion). Scala is…

Though Clojure jobs tend to be the highest paying.

https://insights.stackoverflow.com/survey/2019#top-paying-te...

Re: Why I like Clojure

#55

Clojure Help: This is super apropos since I am JUST learning Clojure via the Clojure Koans. Any tips from clojurists on getting the repl (and readline) working fluently? I'm using Leiningen but it's not responding as I'd expect. I would think this would all set up more effortlessly. Tips on getting a new Clojure setup working would be appreciated.

Chapter 2 of Clojure for the Brave and True will get you an Emacs environment set up with minimal effort!

Re: Why I like Clojure

#56

> homoiconicity, meaning code can be represented as a data structure inside the same language > generating strings and passing them into eval like for example in Python Python has become a pinata for language enthusiasts? Python lets you pin a decorator on a function, get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I'm all…

> get the AST (a data structure AFAIK), manipulate it in a sane fashion in Python, compile it, return the result. No string munching eval require I use both Lisps and Python, and especially after learning to use Lisps I've wanted to do this in Python, so I looked for the ability to do what you describe here. While it is technically possible to do this (like most things) in Python, it is quite the effort and nowhere n…

> While it is technically possible to do this (like most things) in Python, it is quite the effort and nowhere near ergonomic.

Indeed! Peter Norvig once made the same observation [1]:

> Python does have access to the abstract syntax tree of programs, but this is not for the faint of heart. On the plus side, the modules are easy to understand, and with five minutes and five lines of code I was able to get this:

    >>> parse("2 + 2")
    ['eval_input', ['testlist', ['test', ['and_test', ['not_test', ['comparison',
     ['expr', ['xor_expr', ['and_expr', ['shift_expr', ['arith_expr', ['term', 
      ['factor', ['power', ['atom', [2, '2']]]]], [14, '+'], ['term', ['factor',
       ['power', ['atom', [2, '2']]]]]]]]]]]]]]], [4, ''], [0, '']]
> This was rather a disapointment to me. The Lisp parse of the equivalent expression is (+ 2 2). It seems that only a real expert would want to manipulate Python parse trees, whereas Lisp parse trees are simple for anyone to use.

The essential property of a Lisp, to me, is that the syntax is the AST. For any language which does not have this property, providing DOM-like access to the AST is neat but simply not practical for the user.

[1]: https://norvig.com/python-lisp.html

Re: Why I like Clojure

#57

Need someone to explain why I should use clojure over scala because typelevel seems pretty well developed

I feel I see Scala brought up in response to almost every Clojure post, but I can't tell why. They seem like polar opposites. Clojure has a simple syntax and dynamic typing and no classes, while Scala has a complex syntax and classes and static typing with inference. Why would someone looking for one be interested in the other?

Is it just because they both run on the JVM? For all my Clojure projects, I picked the language despite that, not because of it. It's merely an implementation detail.

Re: Why I like Clojure

#58
post #29

Earlier quoted context omitted.

Clojure: live repl into running code Scala: Clojure: Explore the problem you are facing with quick prototyping in the repl and see the blind spots, the unknowns, the shape of data received from flaky integrations. Mold and shape your functions as the problem becomes clearer. Scala: Best it can do is write unit tests and the debugger to look at what exactly is happening, devise a bunch of classes to handle them, rinse…

Scala also has a live repl.

Please provide link as I need one.

Ammonite is not it though.

Re: Why I like Clojure

#59
> Clojure is explicitly designed as a hosted language, which I think was a very good move.

I’m not personally a fan of a VM such as JVM. Sure you get some easy benefits, but now you have two things that need tuning. Two things that need periodic updating.

Personally the total encapsulation of first-class static linking (such as Golang) is my preferred future. It must be first class and baked into the language in its design.

Re: Why I like Clojure

#60
I love the language. I’ve never found a language where I found the learning curve so shallow for being able to do so much.

That said, I do find myself pining for the ability to easily compile a static executable (maybe with a small embedded runtime). Some time ago there was an attempt to port Clojure to Gambit Scheme, but that appears to have fizzled.

More recently, I’ve seen Ferret, which compiles a subset of Clojure down to C++. Also Joker, which is a Clojure-ish interpreter in Go.

Then there’s GraalVM, which I don’t trust, because it’s Oracle.

I feel like the relative lack of traction for non-Java / non-Javascript implementations is part of the brilliance and sadness of Clojure. Namely, the JVM is a rocket ship and a boat anchor.

Racket (modulo the uncertainty cast by the Racket2 discussions) and Gerbil Scheme both have a pretty good “distribute an executable” story while trying to introduce some creature comforts beyond plain Scheme. I suppose my ideal, would be something a little more like Clojure in terms of language, and a little more like Scheme in terms of deployment options.

Post reply on HN