by brundolf · 3y ago · 0 comments
But, I've always been turned off to Clojure by the lack of static typing (I know spec exists, but it's not really the same thing). I did a little project once to try it out, and even there I found myself spending time debugging basic issues like passing the wrong number or wrong kinds of arguments to functions
Can somebody sell me on it? I feel like I'm the target audience
Some advice I would give myself when I started learning Clojure:
Think not in types, but in data. It's a different model that requires an 'aha' moment, but it's revelatory when you do get it.
If you come from an OO language, think not in objects (Elephant), but in information about objects (elephant's record, a map).
Clojure is best served REPL driven.
You can technically compile and execute, but this is not how the language shows its power. Here's how I use it:
I evaluate code in the REPL as I write it, reload definition on every change. Inside a `comment` block, I call the function I'm writing with the required arguments. I can quickly test how my function behaves in corner-cases. You then construct another function, which calls the first. You evaluate/execute the function as you write it.
So your program keeps growing, while you keep running/changing individual parts of it.
Once you get the hang of immutability and working with maps/collections, this process becomes very engaging because of the short feedback loop between thought and result.
It’s like having a conversation with your program while you are developing it.
Also, in case of Clojure you usually handle FP code with no side effects, written in a REPL-driven, interactive style. This combination is not as prone to typing errors in my opinion than "traditional" dynamic languages like Python and JS.
Another aspect might be the one being touched in the 'Maybe Not' talk: Static types operate on a closed-world basis, where the sum of all relevant code is available at the same time. While this is common for certain kinds of programs, it is not really true of systems which have to interoperate with services owned by different companies alltogether, having to support many different versions of other interfaces at the same time. In that case you want to be liberal in what you accept, and arguably, dynamic types are better fit for this job. I am not 100% sold on this part, mostly just reiterating what I've seen others claim, notably Oilshell's author is a big proponent of this thought.
I'm not sure how being liberal in what you accept is at odds with static typing. Static typing is about encoding the rules and shapes of the data that your program *knows* how to work on. It's not preventing some other data that you don't care from existing alongside.
Even if I'm missing something, that doesn't change the fact that in most static typed languages you can fallback to some sort of "any" types. Seems to me it's better to have option to use static or dynamic types in the same program, instead of being forced to do *everything* in dynamically typed way.
You'll get over that pretty fast. The bigger issue is looking at some code and wondering "just what in God's name is in that 10-level map and why?"