Tech behind Tech

Raw information. No finesse :)

Posts Tagged ‘guidelines

Clojure – good coding guidelines

with 6 comments

Naming :

– only lower case letters separated by hyphens except types and protocols should be named in camelcase
– predicates ends with ?
– destructive functions ends with !
– variables that are meant for be re-binding should have earmuffs
– use “_” for names that will be ignored by the code

Code Structure :

– when there is only “then” clause in a conditional statement use “when” instead of “if”
– put all trailing parenthesis in one line
– for dependency use “:only” for “use” and “require”
– use two spaces for indentation
– destructure arg list only when you want to explain the structure of arg to caller otherwise destructure in first let binding

Coding Style:

– try to solve a problem by using function before trying with macro
– be lazy when possible
– use keywords as keys for map entries
– use keyword-first syntax to access properties on objects
– prefer sequence library functions instead of loop/recurr
– only use anonymous functions for short function definitions that fit comfortably on a single line. Otherwise create a private, named function.
– short functions

Written by Siva Jagadeesan

December 9, 2010 at 11:04 pm

Posted in Clojure

Tagged with ,


Get every new post delivered to your Inbox.

Join 147 other followers

%d bloggers like this: