Skip to content

Instantly share code, notes, and snippets.

@brycemcd
Last active February 1, 2020 23:32
Show Gist options
  • Save brycemcd/23fc2ed83911fb5e0614b3a68d6f9653 to your computer and use it in GitHub Desktop.
Save brycemcd/23fc2ed83911fb5e0614b3a68d6f9653 to your computer and use it in GitHub Desktop.
Five Tips For Thinking in Clojure

5 Tips for Thinking in Clojure

Sent by the Pragmatic Programmers, LLC. • 9650 Strickland Rd Ste 103-255• Raleigh NC 27615 - Feb. 21st, 2018

  1. Rely on your REPL. Clojure (like other LISP languages) intends to provide a "live" development experience where you are actively manipulating and testing the program while you develop the code. To take full advantage of Clojure, it's essential to work in a development environment that allows you to interactively evaluate parts of your code while you develop. We are fortunate to have a variety of tool choices in Clojure that can satisfy those demands.
  2. Maps, not Objects. Developers coming from object-oriented languages are likely to look for the ability to create classes or objects to hold their data. Clojure takes a more direct and flexible approach to data, primarily storing information attributes in heterogenous maps. Rather than providing class-specific interfaces, Clojure provides a single generic data interface for creating, accessing, and transforming attribute-oriented information. The result is that modeling data and managing the evolution of data over time is generally much more generic and immediate than the equivalent operations in object-oriented languages.
  3. Collections, not Loops. Imperative languages encourage you to write loops that manipulate data elements one-by-one. In Clojure, you instead think primarily in collections, not loops. When transformations need to be applied, you use a functional approach to describe the transformation from one collection to another, which may involve mapping, filtering, or otherwise transforming data at the collection level.
  4. Isolate State. Clojure is not a pure functional language - it has constructs readily available to create and manage state, perform I/O, etc. However, most Clojure developers minimize the number of functions that work with these kinds of constructs. As much as possible, Clojure functions tend to be small and pure, just simple transformations of data to data. Clojure's model for all state manipulation is to describe stateful change as a function from prior state to new state. Stateful change thus becomes little more than the application of pure functions to data.
  5. Have Fun! Many people find Clojure to be one of the most enjoyable languages they've ever used. There is very little ceremony in the code, a literal syntax to easily represent data, a huge library of functions available for transforming data, and access to all of the existing functionality of the underlying host platform via either interop or libraries. Clojure gets out of the way and lets you get to work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment