Live data from Hacker News

Why Clojure?

blog.cleancoder.com

51–60 of 202 posts

Re: Why Clojure?

#51
post #12

Can anyone give a pro/cons analysis of a ML variant versus of a Lisp variant. Let's say F# versus Clojure? One of the general arguments in Lisp vs the world is that lisp is more concise. F# is really concise. It has datastructures as intrinsic part of the language syntax (just like Clojure, i.e in F# [|,,,|] is an array and in Clojure [...] is a vector, so more or less the same thing). Furthermore, the type inference…

Honestly ml feels like typed (basic) lisp excluding parenthesis.

So I think it does come down to if you like static types or not.

Re: Why Clojure?

#52
post #7

Having disagreed with Uncle Bob for years, now I'm starting to see some reasoning in his thoughts :) .

His book Clean Code is pretty good. Not in the sense that everything is agreeable in it (though some not so great programmers would benefit themselves and those around them from following it religiously) and a decent chunk of it is covered much more briefly with one chapter of The Practice of Programming but you can actually see the book as the artifact of a reasoning mind taking certain principles and articulating them. It lacks the usual polite qualifiers like "I think..." or "In my opinion..." or "Obviously not in all but in many cases generally speaking..." before every assertion which annoys some people. A fair number of his blog posts are like that too. Where Uncle Bob gets an unfair reputation is when people take things out of context from the larger works and (sometimes willfully) misinterpret them -- he doesn't say you should never ever have comments, for instance. Of course some of it is his own doing from occasional tweets that are by necessity of the medium less well thought out or conveyed.

Re: Why Clojure?

#53
post #12

Can anyone give a pro/cons analysis of a ML variant versus of a Lisp variant. Let's say F# versus Clojure? One of the general arguments in Lisp vs the world is that lisp is more concise. F# is really concise. It has datastructures as intrinsic part of the language syntax (just like Clojure, i.e in F# [|,,,|] is an array and in Clojure [...] is a vector, so more or less the same thing). Furthermore, the type inference…

My previous startup (CircleCI) was written in Clojure, my current one (Darklang) is written in OCaml. I decided not to use Clojure again because it's not statically typed, and my number one frustration when I coded in the CircleCI codebase was that it was very very hard to know what shape a value had, and whether it could be null.

OCaml certainly has a lot of flaws, and is not nearly as "nice" a language as clojure, but the productivity of static typing (in the statically typed functional language sense, not the C++/Java sense) is huge. Knowing you can do a big refactor and the type system has your back is massive.

We sponsored core.typed to add types to Clojure, but there were flaws at the time (they have have been fixed since), and we didn't end up sticking with it.

So Clojure I wouldn't use again. OCaml I would, despite having significant flaws (every language has significant flaws).

Re: Why Clojure?

#54
post #3

Clojure is by far the best programming language I've ever used. Rich Hickey's Sermons On The Mount changed the game of programming once and for all. With Clojure you could finally have your Lisp cake and eat it. Witness the sheer chutzpah of the guy when he basically told Ruby devs they were doing it wrong at Rails Conf in 2012 ( https://www.youtube.com/watch?v=rI8tNMsozo0 ).

I agree. In 2014.

It's 2019. Nobody gives a shit.

Re: Why Clojure?

#55
post #50
post #48

This is all nice and exciting until you start to 1) Debug code, the high density of clojure code means that this is really painful. 2) Read code you wrote a while back. The high density of clojure code means that this is really painful.

High density?

you can accomplish a lot in a few lines of clojure

Re: Why Clojure?

#56

Can someone explain me why they always (OK let's say almost always) use math formulas to show what you can do with a programming language ? I'm a desktop application programmer, not a mathematician. I don't need to print the first 25 squares of integers or Fibonacci whatever. In fact I think the hardest math I did at work was using modulo to get even and odd numbers ... Show me how you parse a csv file, how do you co…

Here is an example to massage/manipulate CSV data.

Stolen from the README page for a clojure CSV parsing library (https://github.com/clojure/data.csv)

    (defn read-column [reader column-index]
      (let [data (read-csv reader)]
        (map #(nth % column-index) data)))
    
    (defn sum-second-column [filename]
      (with-open [reader (io/reader filename)]    ; Read in the CSV file (streaming / lazily)
        (->> (read-column reader 1)               ; Convert to just the first column of data.
             (drop 1)                             ; Drop the first row (the CSV header)
             (map #(Double/parseDouble %))        ; convert each string in this column into double
             (reduce + 0))))                      ; sum the result

Because it's lazy, this code should work regardless of how large the CSV file.

Re: Why Clojure?

#57
post #35

Earlier quoted context omitted.

> by far the best programming language I've ever used Would love to hear why? What is that make Clojure such a good experience for you?

Not original poster, but my take is: - Immutable data-structures with concise literals for lists, vectors, maps, and sets. Having pure functions and immutable data-structures makes code easier to reason about, easier to test, and thread-safe. (But clojure doesn't "force" you to be pure. The idea is that you write as much of your code in pure functions as you can, and push the IO and impure parts to the extremities. I…

The above posters point on Homoiconicity is a big one, here is a quick (and silly) example for anyone unfamiliar with the term.

Take the following clojure:

    (+ 1 2)
     => 3
Here the ( ) delimits, a list, and as the blog post says most lists are function calls. In this case the function is + and it's params are 1 and 2.

It means if we do this

     (1 + 2)
We get an exception that 1 isn't a function...

However, we can tell Clojure to treat this code as data by quoting the list using the '

    '(1 + 2)
    => (1 + 2)
 
THis is now a list. Where the first item in the list is a number and second is a symbol + and the last item is a number.

WHat if we write a function to swap the first two items in a list?

    (defn swap [x]
       (list (second x) (first x) (last x)))

    (swap '(1 + 2))
     => (+ 1 2)
We have to quote the parameter (1 + 2) as clojure evaluates arguments to functions (mostly..), by quoting it we are saying don't evaluate, instead treat it as data.

So you can see

     (+ 1 2)
Looks like Clojure code, even though it's a list.

We can eval it:

    (eval (swap '(1 + 2)))
    => 3
It's inconvienent to have to remember to quote the params and call eval.

Up steps macros, macros are evaluated before compile time and don't evaluate their arguments. So we can rewrite swap as a macro

    (defmacro swap [x]
 (list (second x) (first x) (last x)))
   
Now we can call

    (swap (1 + 2))
 => 3
 
This lets us essentially extend the compiler and create DSLs specific to your domain problem. Creating new language constructs is incredibly easy.

Re: Why Clojure?

#58

> I saw the CARs and CDRs and CADDADDRs and thought it was all just academic baloney; interesting but not truly useful. car and cdr are accessors for the fields of a basic data-structure; nothing academic about that. The very origin of the names is rooted in systems work, not academics. (caddr x) provides a shorthand for (car (cdr (cdr x))), which is a pragmatic thing. You know, like #(* % %) instead of (lambda (x) (…

He didn't say they are academic, he said he thought they were academic.

Re: Why Clojure?

#59
post #3

Clojure is by far the best programming language I've ever used. Rich Hickey's Sermons On The Mount changed the game of programming once and for all. With Clojure you could finally have your Lisp cake and eat it. Witness the sheer chutzpah of the guy when he basically told Ruby devs they were doing it wrong at Rails Conf in 2012 ( https://www.youtube.com/watch?v=rI8tNMsozo0 ).

It's a lot of fun but as projects got larger and larger for me (thousands of lines, or even tens of thousands), I found the dynamic typing taking up more and more of my time. I've since moved on to statically typed systems where the compiler takes a big load off the cognitive requirements of maintaining and debugging software.

Re: Why Clojure?

#60
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++.

There is nothing "Java-family" about Clojure. Merely the run-time.
Post reply on HN