English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Developing a Clojure Edge

Tips

Encapsulation (prefer partial application)

[need a good example]


Do data design


Macros

Prefer to use a function.  Syntactic sugar






Direct manipulation of data

goals and constraints

text -> spatial representations

concurrent


Why namespaces are awesome (flexible, democratic, opt-in)

Pitfalls: ugly, multi-syntax (stick with one), conflicts (:refer)


Common mistakes

I want a variable

If you just need a label, use let instead.

If you want something that changes, think if it can be represented as a sequence instead.


I want a data type


map is lazy

(let [v [1 2 3 4]

 (map println v)

 1)

does nothing!

In a REPL on its own line it will force evaluation and print the expected, but as a value it has no effect until examined.

doseq is the correct way to iterate over a sequence for a side-effect.


stack trace is intimidating

Get over it :) look at the file/line of the error and scan down to see where your code is mentioned.


How do I run anything?

Invest some time learning how Leiningen works and finding an editor you feel comfortable with. (see workflow section).


Performance:

Annotations

Holding onto the head

Correct data types (order of operation, vector/set)

Testing for contains with a vector is O(n) where as with a set it is O(logn)



Function definitions appear in a bottom up direction.  You can forward declare but this is rarely done in practise.  If like me you prefer to start at the high level functions, get used to reading and writing source code starting at the bottom of the file and working your way upward.


Web Services


Exposing web services with Compojure

write the functions to expose in a services file

add the dependency

define routes

lein ring server


Consuming web services with http-client-lite



Consuming XML


There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.