While exploring Clojure I came – for the first time – in contact with a dynamically typed language. I had and still have some issues to understand how one can write robust code with a dynamically typed language. My lack of understanding most probably comes from the fact that my only real experience lies in java. It has only been 3 (extremely exciting) months that I made my first babysteps out of my comfort zone. With an ever more hunger for learning about new technologies and languages. So I tried to assemble some opinions on dynamically typed languages and put some ofmine into it as well.
1. It increases development speed
Because you don’t have to think about types every time you write a piece of code, you can focus more on solving the problem.
In Clojure, this has been true for me so far. I’m really stunned by the amount of focus you can get on solving your problem. Not having to think about variable here and there and such stuff.
Because in a business environment, most of the time during development it is unclear where exactly you are heading. Also, it occurs frequently that your customer doesn’t really know what he wants. In an agile workshop this is especially true because you want your programs to be as adaptable as possible.
I can totally live with this argument. Being a humble third grader at university, of course, I’m still in a safe and didactic environment. So you might say I can have no valid opinion on this at all. But during the holidays I try to work as much at companies that can offer me interesting programming/design student jobs. Last summer I worked at Commsquare for a month. At commsquare the idea of “agile programming and “test-driven development” are seen as being very important. I learned a lot during that one month. Interesting was that the developers liked Python a lot. Also, there I met Frederik De Bleser who was the guy that initiated my extreme interest in clojure and other languages (and who has also been some influence for this blogpost). He made me think about what I learnt about OOP at university in a way I hadn’t before. I don’t say that my coding style and other things changed instantly, but my attitude towards the different paradigms certainly has!
What was I talking about? Oh right, dynamically typed languages!
It keeps programmers free from how they want to make their code robust
This is an interesting one. In a statically typed language you generally have only one way to do this: static typing.
Surely this freedom comes at a cost. What cost? In my opinion: responsibility!
“With great great power comes great responsibility” – uncle ben
Having the freedom to check for valid input in any way, it is important you follow convents and try to be as idiomatic as possible. Now.. do we really want that much responsibility? Are we capable of making complex and large software systems with no static typing? I cannot really answer this question because of my lack of experience and credibility. I can only observe that apparently engineers at an agile workshop like commsquare manage to write large software systems. What they really find important though is TDD.
In search of how to make things in clojure more robust lead me to some very promising projects:
- Typed Clojure
It is a *library* that gives you the option to actually use type systems in clojure. The fact you have the option reflects the freedom
Another very interesting project. It gives you the ability to impose some constraints on a map! For very large projects with different and “more or less” independent teams. Teams should agree on some schema and then start working indepently. Another way to do this is by creating a protocol. Which might be useful but, you are creating a new type here. By using schemes you adapt your schemas very fast if needed and still be able to use your data type – maps! – everywhere.
I’m certainly going to look into these ones after my exams(dough!) are over . If you had any experience with these libraries tell me about it in the comments!
The next two points come from myself
3. Its not such a big issue in clojure
In java, for every new piece of data I want to represent I invent a new type. SpermWhale, Bowl, Petunia. All with there own unique methods. This argument is also valid for python. Now its getting trickier because there might be literally tons of different types out there which are incompatible with your piece of code.
In clojure it’s a different story. There are in general very few types: maps, vectors, list, sets. And you choose one of these types to represent your data. And then every function that can work with one of these types will be able to work with your data! That’s what I call reuse! (Idea for a bookname: “Clojure data: elements of reusable software” The only thing missing is a writer.)
4. Measuring the annoyance of Statically typed languages
This is probably the strangest part of my blogpost, but its something that came up in me, so I’m going to write it down anyway.
My quirk can be summarized as follows:
Annoyance of static typing is proportional to the proportion of the code that is used to declare types.
There is probably a better word to use here than annoyance, but I think it is funny enough to keep it like that for now.
What this basically means is that in relatively small projects, if your language were to be statically typed, it might become quite annoying because it is a “large” proportion of the code. And therefore may take away your focus on solving the problem.
One implication of this statement is that for writing small libraries, you might be more productive using a dynamically typed language.
I still need to think about the validity of my statement here and what implications it made. Or whether it is just plain nonsense. Nevertheless it reflects how I currently think about dynamic typing. Maybe it is some material for a new blogpost. But in the meantime please criticize it as much as you like! (really)
I’m still not 100% convinced – because of no experience or whatsoever – that you can write very large and robust software systems. But what I really do like are the things you are free to do: working with schemas, protocols, reinventing static typing. It just keeps all the possibilities open and keeps room for future new ideas of making code even more robust! I never enjoyed programming as much as doing it with clojure. I’m certainly going to continue my exploration in clojure and other languages.
So long, and thanks for all the fish!