
Why I'm Productive in Clojure - islon
http://yogthos.net/blog/49-Why+I%27m+Productive+in+Clojure
======
dj-wonk
> What matters to me in a language is whether I can use it without thinking
> about it.

I love this statement. It reminds me of the what it feels to be good at
mathematics (not my words): "Your intuitive thinking about a problem is
productive and usefully structured, wasting little time on being aimlessly
puzzled." from [http://www.quora.com/Mathematics/What-is-it-like-to-
understa...](http://www.quora.com/Mathematics/What-is-it-like-to-understand-
advanced-mathematics)

The author also says more about mathematics:

> To make an analogy with math, it's nicer to have a general formula that you
> can derive others from than having to memorize a whole bunch of formulas for
> specific problems.

> This is where Clojure comes in. With it I can always easily derive a
> solution to a particular problem from a small set of general patterns. The
> number of things I have to keep in my head is not overbearing.

Any language that lets you spend your brainpower on the essence of the problem
is a tremendous advantage and joy. This unlocks creativity and productivity.

~~~
S4M
> Any language that lets you spend your brainpower on the essence of the
> problem is a tremendous advantage and joy. This unlocks creativity and
> productivity.

For some reason the only language that let me reach this level is Python. I
tried Clojure and Common Lisp, but for some reason I could never be as
efficient as I wanted with them, which I think is a shame because in some ways
I think the Lisps are superior to Python (due to the "code is data and data is
code" of Lisp).

~~~
jcromartie
I use Clojure a lot, and did more Python in the past. Whenever I come back to
Python, I am frustrated by being unable to remember what's a plain old
function and what's a method, and the differences defining functions vs
classes and methods etc..

In Clojure I know it's always (except for interop) just functions on values.
Some functions dispatch to an implementation based on the type of the value,
as is the case with multimethods and protocols, but it's still always just
function calls from my point of view while writing the code.

~~~
mimighost
In general, Python method is just combination of function object and pointer
to "self" namespace.

~~~
agumonkey
I'd like to know if it's done differently in other languages. In my view,
methods are curried function over self with a '.' syntactic shortcut.

~~~
kazagistar
Lua does not do the currying bit, but it does a lot less OOP and a lot more
"dictionaries with stuff that can do something like prototype OOP if you
squint hard enough". Java and whatnot just don't let you really use methods as
first class citizens, so it doesn't matter.

~~~
agumonkey
IIRC under the hood Java will 'evaluate' the methods body as a sophisticated
function with 'this' in its environment.

------
nmac
I recently migrated to clojure from the php world. I have to say that although
I am still learning the language, its actually fun compared to php, which
would sometimes feel like pulling teeth to get some basic functionality. Way
less boilerplate, and as can be said of anything good, it just works.

Also, the idea of thinking in the problem domain versus the subset of problems
that arise in languages like php is an acute difference. Just being able to
focus on the product as your programming keeps you on task and thinking about
new ways to implement features, etc. -- big difference.

~~~
deno2
I made a career move from dentistry to programming. And I would say that
anything I've used pre-clojure is a good approximation of pulling teeth. But
even pulling teeth has the benefits of knowing when you're finished and the
direct customer feedback is usually good.

~~~
cheez
Why did you decide to switch from dentistry?

~~~
deno2
An intellectual, emotional disaster.

I'd been programming since a child and I think in all honesty I was pushed
into dentistry by the people that love me and wanted me to make money.

However dentistry in London is medicine in two years then three years
specialising in the head and neck. Then two years dentistry training.

I found it a LOT of learning facts. I know that knowledge-based systems are
better than humans for that application.

I had the pleasure of learning human anatomy for two years with Prof Harrold
Ellis. Which is what I really took away with me. The guy was a genius. And the
other was "If you are not certain then say I don't know, never guess, always
seek truth" not that many people appreciate that knowledge in my experience.
Robotic surgery yes, lying about the safety of amalgamate fillings no and
telling mums of the effects of sugar and carbonic acid drinks was not enough
scientific exploration for me.

I think I was too young, always the youngest in my year, to really know and
show what I wanted to do. I should have studied Physics but was told at the
time "I'd end up a Physics teacher" as if this was a bad thing...

Pre-uni I wanted to build quantum computers but my Physics teacher at St John
Ruskin College school didn't know what direction I should head in (the school
at the time was also being ripped off by the head mistress, look it up, bad).

After that I got a scholarship to a private school to do A levels which was
absolutely brilliant. Dulwich College an excellent school where I was treated
like an adult and learnt maths, physics and chemistry. Two of the best years
of my life.

Nobody noticed really that I wasn't just lazy and so it was very tempting to
my parents to be told I could go to the best medical school etc when I pissed
the exams.

So I went to the best medical school in the UK, Europe not really sure why.

After two years depression forced me to take some action and I quit and got a
job in a bank as a COBOL programmer. I learnt that COBOL doesn't cure
depression but can even make it worse. However I learnt from two old ladies
who were probably employed AS computers in their prime. And they were the
awesome COBOL dinosaurs.

From there on its always been a bit of struggle not having a degree. Although
what I've taught myself, and continue to do so, is worth several degrees at
least. Probably a PhD or two.

I now know a lot of programming languages and have lots of experience in them.
Clojure took me to the next level with regards to meta-programming and
language design. I still have hopes for genetic programming.

My interests now are really into augmented reality and basically augmentation
of human perception, memory and "brain power" both in the progression of our
species and knowledge itself.

If you really want to know where my head is at read The Beginnings of Infinity
by David Deutsch
[http://en.m.wikipedia.org/wiki/David_Deutsch](http://en.m.wikipedia.org/wiki/David_Deutsch).

He has interesting ideas on quantum computing, knowledge and reality which
align most closely with my own.

I'm now mostly a "Senior Developer". How about you?

~~~
cheez
Have you had any "portfolio" projects? That is, projects you can showcase?
This goes a long way towards the lack of degree.

My story is too long to put into text, but the short of it is that I can
relate to a lot of what you went through.

~~~
deno2
That's another issue too. If it's not a public website that you're building
it's quite hard to show off your work!

One of my favourites was a forward-chaining rules inference engine written in
T-SQL on MS SQL Server for a sixth-form college. The Management Information
System (MIS) was called unit-e built by Capita PLC and probably cost a LOT of
money.

It was quite a good system, the query builder for advanced users was excellent
(every MIS should have one), but it had a fair amount of data duplication -
names, addresses, previous address etc. And the admin staff had lots of name
changes and spelling corrections to make. Also you had the data entry dudes
who'd write a lazy name like fiesta try basharat instead of Fiesta Try
Basharat.

So I built the rules-engine as a stored procedure (SPROC) called by triggers
on tables. The rules themselves were just simple SPROCs and some not so simple
but the rule interface was simple and so the system was robust. All of a
sudden every letter sent by the school was formatted properly and went to the
correct address! The admin team even gave me and my junior a present! And the
'junior' became an expert in SQL and learnt a secret ninja weapon (rules,
inference engines and conflict resolution).

How many good things were created? How do you demo the transition of
knowledge? How do you monetize the time saved? How do you portfolio the
potential for benefit of new rules that haven't been thought of yet?

Expansion of knowledge, the beginnings of infinities, there's so much out
there I love it!

------
Touche
My biggest problem with Clojure (specifically ClojureScript) is that it's too
workflow opinionated. Nearly all Clojure devs use 1 of 2 text editors. Nearly
everyone uses Leiningen. Nearly everyone uses some sort of auto-builder.
Nearly everyone uses hot-swapping.

Clojure wasn't even optimized for this workflow, it's just the only one that
works. So as much as I love the language I keep going away from it because I
prefer the freedom of my own workflow.

~~~
andrewvc
Well, people do use these tools, but honestly, do you really want a language
with multiple build tools / package managers? The java world is a mess here.
Leiningen is pretty great, no need to fragment the community.

As far as editors go, I'm perplexed. You can use nearly any editor, why do you
perceive the need to use one of these 2?

~~~
Touche
> Well, people do use these tools, but honestly, do you really want a language
> with multiple build tools / package managers?

I want multiple _workflows_. A single build tool can accommodate that, but
Leiningen can't/doesn't.

For example, let's say I have a compiler called mycc. I can build something
like this:

    
    
        mycc main.c -o main
    

I might then combine it with an file watcher utility like entr

    
    
        find . -name '*.c' | entr mycc main.c -o main
    

With Leiningen it has to do that all. AND you pretty much have to use the auto
rebuilder capability (which means your workflow starts with turning the auto
rebuilder on).

> As far as editors go, I'm perplexed. You can use nearly any editor, why do
> you perceive the need to use one of these 2?

Then why do nearly all (probably 95%) Clojure devs use either Emacs or
LightTable?

~~~
freshhawk
Right now I'm using a combination of leiningen, guard, livereload, compass and
a shell script to handle my specific build workflow.

I'm confused as to why you think leiningen has to do it all.

I'm also not sure what you mean by auto rebuilder (for _clojurescript_ I use
the auto feature of cljsbuild ...). My workflow starts with starting a REPL.

Also, I use vim very happily, many people use Cursive happily. But the reason
there seem to be fewer editors in use is that REPL integration is so useful
that only those editors with good REPL features end up being used. Clojure's
ecosystem isn't stopping anyone from using other editors, those editors just
haven't implemented a specific feature that is extraordinarily useful when
writing Clojure.

I may have misunderstood you but it seems like you are seeing problems that
don't exist because the solutions look different than what you expect.

~~~
Touche
I think you are misunderstanding. People have shown in this thread that they
have a slightly different workflow from each other, but my point was that
Clojure(Script) points you towards a particular type of workflow, one that I
do not like. What I essentially want is 1 of three things:

1) Fast builds so I can set up an auto-build script.

2) A Leinengen daemon so I don't have to worry about building at all.

3) ClojureScript so I can just refresh the browser.

As far as I can tell none of these are possible. If I am wrong please correct
me.

~~~
freshhawk
You can certainly get all of that stuff (except fast builds in some particular
circumstances).

My project I described before is a web app, and my workflow involves my
editor, a browser, a clojure repl, a clojurescript browser repl that runs code
in the browser and a shell script that runs the various watchers I described
before.

If I change any clojure file the browser refreshes automatically (and my tests
run automatically).

If I change any clojurescript file it gets rebuilt automatically and the js
file is reloaded in the browser (just the js, not a full page refresh)

If I change any sass file, it gets rebuild and the css in the browser
refreshes (just the css)

If I change any html template then, depending on the template, either the page
is refreshed or my clojurescript is rebuilt and the js refreshed.

So all those things are possible (I saw a cool post the other day of some ring
middleware to handle using clojurescript inside <script> tags transparently).

The non-clojure stuff is handled completely outside of the clojure ecosystem,
I was using LiveReload and Guard when doing python dev to get that partial
refresh on file save functionality and it was pretty simple to hook clojure
into that same workflow.

I will say that if you are doing a lot of compile time template processing in
your clojurescript like I am (using Kioo/Om/React.js) then the compile time
for the clojurescript can be a little long, but since I have a browser REPL I
do my experimental stuff in there instead of hitting that recompile cycle
frequently so it's only a minor imperfection in practice.

So I definitely don't worry about building at all, and I don't even have to
refresh my browser thanks to LiveReload - I just have to hit save in my
editor.

There unfortunately aren't a lot of tutorials for setting this kind of thing
up. I've got a start on writing up my setup and will put the project skeleton
on github soon-ish ... I have this damn real work that keeps getting in the
way.

------
davexunit
REPL-driven development is wonderful. I'm not a Clojure user (yet), but I
write a lot of Scheme. My programs are living creatures that adapt and evolve
as they are running. It's refreshing to see that Clojure is seeing real use in
the industry. Gives me hope that I can get paid to work with a language I
really enjoy some day.

~~~
jptman
I'm a bit curious about your comment. Do you mean during development you run
your code on a REPL and change portions of it , or do you mean you run code in
Production in a REPL and change portions of it as it's running?

I'm interested to know your setup in either of those cases. The one
inconvenience I have about REPL based development is that I need to copy over
an expression from my editor into the REPL and if I make any changes in the
REPL, like fix a typo, I need to make sure to copy it back to my editor.I
guess this may be because I don't use Emacs and have an editor and REPL in
one.

~~~
deno2
REPL Driven development as it's called is really yes having your whole system
running at your thingertips (even production for the adventurous). You can
execute arbitrary code and get results or see what state has changed. You can
also redefine anything (in Clojure at least) that is referred to, such as
functions and variables (I use these terms loosely here).

Normally you have your IDE configured so that anything executed is executed in
the context of the running REPL session. So there should be no need to
copy/paste.

When done properly with tests running on every change you really can't, as a
developer, get any quicker feedback. It's brilliant and empowering!

Your issue could be emacs but, for Clojure at least, there is the Cursive
Intellij plugin which is now definitely usable. Also there are the brand new
IDEs like LightTable.

LightTable.com started out with some very different ideas with regards to code
organisation and there is still a lot of potential work there. But lighttable
instead became open source and a core for plugins. The plugins now range from
rainbow parentheses to 'pick your language' evaluation.

If you want to discuss any of these ideas or others please do or PM me. I'm
always willing to discuss as my girlfriend is hopeless. But then for
everything not programming she keeps me sane.

------
yawn
I'm curious to see how Clojure fares against the current crop of folks
becoming intrigued by statically-typed languages like Haskell, F#, etc.

~~~
gregschlom
I'm a strong static-typing advocate, and for years this has put me off
learning Clojure. (In fact, my very first HN submission, back in 2010, was
about Clojure:
[https://news.ycombinator.com/item?id=1453259](https://news.ycombinator.com/item?id=1453259)).
I've been coding exclusively in Clojure for the last month however, and I
found it extremely enjoyable to use. Much easier to learn than Haskell, for
example, because Clojure isn't purely functional.

The key of Clojure is that it's _pragmatic_ , as opposed to dogmatic. It's a
language designed to solve real-world problems in production environments
(hence the focus on concurrency, for example).

Also, being a lisp, it's a "programmable programming language", and once you
realize the power that that gives you, it's hard not to fall in love with it.

~~~
dominotw
>'s a language designed to solve real-world problems in production
environments (hence the focus on concurrency, for example).

It would be nice to see example(s) of clojure solving real world concurrency
problems.

~~~
MichaelDickens
I learned Clojure from the book Clojure Programming
([http://smile.amazon.com/Clojure-Programming-Chas-
Emerick/dp/...](http://smile.amazon.com/Clojure-Programming-Chas-
Emerick/dp/1449394701/)). Once the book gets past the basics, it starts giving
lots of concrete examples for how to solve real problems idiomatically in
Clojure.

~~~
dominotw
Yea but I am looking for actually field reports from people solving hard
concurrency problems out in the wild with Clojure. I am yet to see one.

~~~
yogthos
Storm
([https://storm.incubator.apache.org/](https://storm.incubator.apache.org/))
is a great example of Clojure used to solve concurrency problems in the wild.

~~~
dominotw
Sorry pardon my ignorance but that seems like parallization not concurrency. I
would like examples of things like pmap being used in the wild.

~~~
yogthos
Well, p in pmap does stand for parallel. :) The two are obviously linked,
Storm does both parallel and concurrent processing on the data. Another
example is PigPen ([http://techblog.netflix.com/2014/01/introducing-pigpen-
map-r...](http://techblog.netflix.com/2014/01/introducing-pigpen-map-reduce-
for.html)) from Netflix. As far as pure concurrency goes, I'm not sure any
companies have articles discussing that.

~~~
dominotw
Ok thank you. Implementing map reduce style parallzation doesn't need any
language level support. I don't see how clojure is any better at this than say
java ( hadoop is java after all).

I am looking for 'pure concurrency' in a app like videos games exctracting
last ounce of processing power from a multicore machine. This what the
original comment stated was the core competence of Clojure.

~~~
yogthos
>I am looking for 'pure concurrency' in a app like videos games exctracting
last ounce of processing power from a multicore machine. This what the
original comment stated was the core competence of Clojure.

That's not actually what the parent comment stated though. It says that
Clojure is designed to solve real-world problems in production environments.

In many cases this doesn't mean squeezing out the last ounce of processing
power, but being able to reason about concurrent code safely. You pay an
overhead of using immutability in order to facilitate higher correctness.

When your system grows it becomes important to be able to reason about parts
of it in isolation. This is particularly important when you're running in a
multithreaded environment.

That's what people generally mean when they say that Clojure has focus on
concurrency. Since the data is immutable you can make assumptions about what
the code is doing that you wouldn't be able to make otherwise.

------
sternenseemann
Being popular on HN is not the best thing for Webservers...

~~~
yogthos
It certainly isn't, my poor server went catatonic under the relentless
onslaught. :)

