Live data from Hacker News

Abstract Clojure

juxt.pro

21–30 of 43 posts

Re: Abstract Clojure

#21
post #9

What is Clojure's main selling point?

A really well thought out Lisp-1 that runs on the JVM, in the browser, in node as well as the CLR and BEAM.

It is hard to go back to other languages once you appreciate its simplicity.

Re: Abstract Clojure

#23
"Software design is a well researched and understood problem..."

I got a good laugh out of that one. Honestly that final paragraph should just be deleted. It's just a giant, indefensible claim.

Re: Abstract Clojure

#24

I'm not sure I agree here. There's not too much value in testing these two or three lines of code in the get-article handler. And the passing around of compositions of higher order functions can get confusing. There are cases where an approach like this is warranted but I would say that there needs to be a significant level of complexity before this makes sense. Having a protocol for your data layer and an in memory…

Yes Clojure is all about first-order functions working on simple, concrete data structures.

Pervasive use of protocols and custom, user-defined higher-order functions I would argue is unidiomatic Clojure and creates long-term pain as you end up with opaque functions being passed around that can't be inspected at the REPL and a lot of tricky "fitting functions together" that is made difficult without a static type system. You sometimes need them, but you should reach for them very judiciously.

There's a reason Clojure emphasizes data over functions (and both over macros).

Re: Abstract Clojure

#25

"Software design is a well researched and understood problem..." I got a good laugh out of that one. Honestly that final paragraph should just be deleted. It's just a giant, indefensible claim.

That really sprung out at me too. I don't think the problem is well understood at all, let alone the answers to it.

Re: Abstract Clojure

#26
post #3

I also recommend the book "Grokking Simplicity" by Eric Normand for a longer exploration of functional software design (not Clojure-specific). The linked blog post uses Clojure examples, but this approach to software design is universally applicable (especially in functional programming!).

Thank you for this rec, been thirsty for knowledge in this domain.

Another good one is "Elements of Clojure" (https://elementsofclojure.com/) which I think is a slightly misleading title. It's a generally good programming book, it just happens to use Clojure for it's examples, but I don't think it's required to know Clojure to understand the concepts explained in it. Also been discussed here before: https://news.ycombinator.com/item?id=21090288 and https://news.ycombinator.com/item?id=11306519

Re: Abstract Clojure

#27
post #9

What is Clojure's main selling point?

Not writing Java (although you do have to do lots of interop with Java).

It's true it's "not writing Java", that's true for every language besides Java! But the second part is definitely not true. First, you can very much use JVM Clojure without touching Java, I've done so many times. Secondly, you can use ClojureScript which cannot even do interop with Java since it "compiles" to JavaScript and doesn't run on the JVM. Thirdly, you can use Babashka to run Clojure code with GraalVM and SCI instead.

Many options exists to not having to touch Java when you use Clojure, but I guess it's hard to kill old memes?

Re: Abstract Clojure

#29
> The protocol is another form of abstraction we can use to decouple modules, the approach is more object-oriented than functional

That's not true that the approach is more OO.

People get confused because a lot of OO languages like Java eventually added support for something protocol-like, in Java it was interfaces for example, but for a long time Java, an OO language, didn't have interfaces, you only had Classes and Objects and inheritance.

Protocols and polymorphism is not an OO concept, and doesn't even need to involve Objects at all.

In Clojure for example, you can dispatch the protocol over a map, given two maps based on their metadata the protocol will pick a different implementation for the called protocol function. There are no Objects and Classes involved.

All you need for polymorphism is a sort of metadata over a datatype, it could be type information or it could be something else, like attached metadata like in Clojure.

In an OO language, and in Clojure by virtue of running on the JVM, user datatypes are defined using Classes and Objects, but in a language like Haskell they're not.

So basically you can implement protocol-like polymorphism, basically the idea that you dispatch based on meta-information about the arguments passed to the function with or without object constructs.

I'm pointing this out because it is an argument against OO. The fact that even in most OO language people have over time preferred to use such polymorphism over object inheritance hierarchies is a sign that Objects aren't as useful as ounce thought.

What is very useful though is to be able to define alternate function implementations based on some metainfo about a given argument, such as their type. So much so that all languages, OO and Functional will tend to have such feature.

Re: Abstract Clojure

#30
post #29

> The protocol is another form of abstraction we can use to decouple modules, the approach is more object-oriented than functional That's not true that the approach is more OO. People get confused because a lot of OO languages like Java eventually added support for something protocol-like, in Java it was interfaces for example, but for a long time Java, an OO language, didn't have interfaces, you only had Classes and…

Are you sure about Java? http://titanium.cs.berkeley.edu/doc/java-langspec-1.0/ talked about interfaces in 1996 and I don’t remember any version that didn’t have them.
Post reply on HN