Thoughts from Learning Clojure
I invested about 10 hours this weekend learning Clojure. It feels like a solid chunk of time. Between working on my Bittorrent client learning project and doing some reading of Chas Emerick’s Clojure book, I feel like I understand Clojure just tiniest bit more now.
Here are some thoughts so far:
Function Name Readability: I really don’t see the need for the language to use abbreviations like
str
anddoseq
. As I learn this language, I almost want to create a fork of Clojure with longer method names that are more self explanatory. The core library documentation has been great so far, once I find it. In many cases, I feel like a proper function name would save me a trip to the internet (or at least running thedoc
method in the repl).Overloaded Language: some central terms in Clojure are very similar to central terms I’ve encountered in other programming languages, but it seems like Clojure is going with different names. Maybe Clojure is just following Lisp conventions, and Lisp came first? Who knows. In particular, confusing terms were:
- forms: this loosely corresponds to “functions and expressions” in Ruby, but not quite. I wonder whether this one is worth trying to “translate”.
- vectors: are the same as arrays in Ruby (and arrays in Java). Seeing as how Clojure builds on Java, I really don’t see why this naming difference exists. Again, maybe it’s a Lisp thing? I vaguely remember vectors being a thing in C. I’m sort of curious and want to Google this at some point.
- keywords: are the same as symbols in Ruby…more or less. They’re at least colon-prefixed values that tend to be used as keys for maps.
symbols: are NOT AT ALL like symbols in Ruby. Instead, the word corresponds loosely to something like “defined variable”, but I’m still fuzzy on the precise definition.
…from the Clojure site:
“Symbols are identifiers that are normally used to refer to something else. They can be used in program forms to refer to function parameters, let bindings, class names and global vars”
I guess this means “symbols” in Clojure are variables and methods…identifiers.
Java Interop: is sort of cool…and probably entirely necessary to write Clojure effectively. In other words, tools that I would expect in a language’s standard library are not there. Such tools might be type checkers to see if a string is a numeric digit. Rich Hickey even says in a talk that Clojure programmers should be using Java queues. I don’t have the exact time in that video that he says that, but if you’re reading this then I’m doing you a favor by giving you a reason to watch it in whole.
In doing some research as I wrote this point, I found this excellent StackExchange question about programming languages in general. I recall reading that the Lisp community has historically suffered from fragmentation of dialects and libraries. That answer pointed out something so obvious that I never realized–that Java has the largest ecosystem of libraries. I didn’t realize it when doing Ruby, but I’ve hit system compatibility issues because some gems were developed on a system with a different flavor of C compiler than what ships with OS X.
In other words, I’ve been impacted by C library incompatibility issues as a Ruby programmer.
Interfaces? I’ve yet to write or read any interfaces yet. It may not be a readily exposed or common feature. I’ve implicitly used interfaces in a few different ways. Sequence, map, and function-interfaces remind me of the brief time I’ve worked with Go. I’ve barely scratched the surface of this concept, but it feels like it’s entirely missing in Ruby. More on this later (hopefully).