Skip to content

Instantly share code, notes, and snippets.

@otijhuis
Created June 25, 2014 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otijhuis/4315a2ea74a3710b9acd to your computer and use it in GitHub Desktop.
Save otijhuis/4315a2ea74a3710b9acd to your computer and use it in GitHub Desktop.
The things I remember most when learning Clojure
For me the toughest part of learning Clojure for me has been the switch to functional style thinking. Probably took me 6 months of doing Clojure in my spare time. I’ve used quite a few languages but all of them were mostly object oriented. You basically have to throw a lot of stuff you know out of the window and start from scratch. Clojure is probably far easier to learn for someone who doesn’t have an object oriented background.
The things I remember most when learning Clojure:
- forcing myself to use higher order functions instead of using a loop whenever possible. Coming from an imperative style you have to force yourself to think differently about problems
- brushing up on recursion. You use it all the time in functional programming
- being amazed at how little mutable state you actually need. We have a piece of Clojure software in production that contains no mutable state at all
- how handy lazy evaluation is. Creating infinite sequences is so much easier to reason about. No need to worry about how many items you need upfront
- it finally clicked when I thought of everything as a pipeline. You pass something in, goes through all kinds of steps/transformations, and comes out at the end in the format you want. No mutable state needed
- taking the Clojure cheat sheet and try new functions each time. You tend to find some gems that really make things a lot easier once you know them (juxt for instance)
- because you work only with a few data types 99% of the time you tend to use the same Clojure functions over and over. In java for instance everything is a class and each have their own methods. So basically everything has its own API. You basically need a java IDE because every object is different. There’s no consistent interface. Because Clojure and almost all Clojure libraries use the same data types you can actually remember the functions you have to use. It also makes things far more general and easier to reuse
- coming from java and having a REPL now really makes you dislike the java recompile/run stages
- solving 4clojure problems and then checking the solutions of others. You quickly notice who think functionally and who still try to do the imperative style (too many for loops and such). Look at the best answers and keep comparing your solutions to theirs. When I had solutions that were very similar I knew I was on the right track
- the -> / ->> operators make tihngs a LOT easier for reading the code
The syntax of Clojure was easy. Much easier than most other languages. And the parenthesis you get used to really quickly, although I’d hate to have to edit them without something like paredit though.
I guess it is best to find out at what level the team is in general. What I do believe though is that most people learning Clojure struggle with the functional style or with setting up a good Clojure environment, not so much with the language itself.
@otijhuis
Copy link
Author

Also the abstractions you use are very very different. A lot of the boilerplate stuff and design patterns you are used to using, with java for instance, are just not needed anymore.

Reading the source of complex Clojure apps built by others is sometimes tough though. Mostly because most of the functions are tiny and are so generic that they can be used in all kinds of situations.

I you only get to know 1 Clojure library it should be core.async imho. It makes life SO much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment