Hacker News new | ask | show | jobs
by rafaelferreira 2211 days ago
I've been working with Clojure for a few years now, and the thing I love most about the language is how it nudges developers to write straightforward code. It's maybe closer to a well-structured procedural style than to highly indirect OO or to deeply polymorphic category-theory-inspired typed functional programming. The emphasis on mostly-first-order pure functions composed of other functions, receiving and returning immutable values, makes it easy to untangle even the worst balls of mud, while the well designed set of data-structures (few) and functions operating on them (many) allow for easy and terse expression of everyday data manipulation chores.

If we keep the majority of the code pure and straightforward, we can deal with state and I/O with other constructs, like atoms and records, only where we need to (doing this systematically tends to lead me to some variation of the functional-core/imperative-shell pattern). STM, multimethods, macros and whatnot are cool and have their uses, but after a while I think the really cool thing is how little do we need to resort to fancy stuff and how much is accomplished with just functions and data.

1 comments

> functional-core/imperative-shell

Lol I’ve been learning Clojure for fun these last few days and I had to read this twice because the first time I thought I was looking at a function from a module.

> we can deal with state and I/O with other constructs, like atoms and records

Can you elaborate on what you mean here or link to specific articles? I’m talking about the representing I/O side effects as records part.

There is a component framework that builds dependency tree for stateful modules and does implicit injection of params. It is a beautified pattern(usually you can do initializations in higher levels, but you have to resolve dependiences yourself and for the whole tree) for dealing with things that require state while keeping explicit references(so that you understand where it came from and can inspect(visually) its lifecycle).
Sure, check out Stuart Sierra' (by now famous) blog post Clojure Workflow Reloaded and his Components library: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-r... https://github.com/stuartsierra/component