At today’s thoughtbot dev discussion in Boston, @benorenstein talked to us about Clojure and ClojureScript. Ben drew from the slides used in Stu Halloway’s Clojure in 10 Big Ideas. My notes follow.
Clojure:
- Integrate tightly with host platforms
- JVM
- JavaScript
- Dynamic typing. Optionally will type check?
- commas are whitespace (and optional)
- typically read from bottom up (must be defined before used)
Clojure In Ten Big Ideas
- edn (Eden)
- Looks like JSON
- has data structures
- list ( )
- vector
- map { }
- set #{ }
- clojure programs are written in edn. “Written in Data”
- programs that write programs.
- programs that modify programs
- built in tags
- formats : dates, uuid
- can define their own formats (call this function)
- Persitent Data Structures
- immutable
- Structural sharing
- return new versions, reusing same parts
- maintain performance
- Unified Succession model
- common way of handling mutation
- like git history
- change is encapsulated by constructors. Build new things using
new
- atoms for atomic updates
- Sequences
- almost everything is a sequence
- first, rest, cons
- take, drop
- higher order functions: every? not-every? not-any?)
- map, filter, reduce
- sequences are lazy and often infinite - iterated, cycle, repeat
- Protocols
- Interfaces
- can extend interfaces, namespaced - like Refinements but they work.
- ClojureScript
- Outputs JavaScript
- JavaScript is tailored for minification via Google Closure (no relation)
Compiler - Can get a ClojureScript repl in the browser
- Reducers
- Composing sequences
- Not certain of the differences between lazy sequeces and reducers
- Reducers: Lazy, unordered, and parallel. That might be the difference?
- Datomic
- Datalog is the query language
- Lazily load the entire database.
- Query the database, not the connection
- Can query and join across databases.
- When transactions return you get the new database, the old database and
the diff. - can travel in time in the databse.
- Core.async
- in ClojureScript gives you what looks like blocking threads in the
browser.
My Thoughts
I found Clojure to be more readable than I had anticipated. That may be because I’ve been becoming more familiar with the functional programming paradigm because I recall looking at a Clojure program a couple of years ago and running away scared. The smaller programs we looked at were plagued by ))))))))))))))
, but Ruby just has a different version of that noise in the form of several consecutive end
statements.
The programs themselves being just another bit of data that the program could operate on was interesting. I found Datomic to be of the most interest and wouldn’t mind playing around with that some.
If you’re comfortable with object oriented programming and looking to expand your horizons a bit, I think picking up a functional language such as Haskell or Clojure would be very beneficial - even if you never get paid to program in one of those. Clojure’s immediate usefulness via ClojureScript make it a really good candidate for this type of interest, I think.