Static vs dynamic typing

Linas Naginionis
soundvibe
Published in
2 min readNov 25, 2014

Recently I’ve attended software conference called “Build Stuff”. The conference was smoothly organized, some great world-known speakers gave their talks there. I can say that functional programming topics were the most interesting to me. FP is reborn in the software development nowadays and I can’t say I don’t like it. I see that FP languages are getting more and more attention and they will definitely receive more adoption, at least in the new projects. This functional trend received some attention in OO languages also. I am very happy with the recent Java 8 language improvements, we are using lambdas and streams in our projects extensively. It’s very useful to think and solve problems using functional style.

FP languages

The most popular of all modern FP languages are probably Clojure, Scala and F#. Clojure could be called “traditional” FP language in the sense that it more or less forces you to use functional style everywhere. Scala and F# can be both object oriented and functional but still they are functional by default. All these languages are great but the biggest difference to me is typing systems in these programming languages.

Static vs dynamic

Clojure is dynamically typed, but both Scala and F# are statically typed. I like Clojure (although it’s syntax is quite confusing at first) but this is a stopper for me. I can’t understand why language, which has a compiler, cannot enforce type safety? It’s ok for Javascript to be dynamically typed because it’s a scripting language! I seriously think the designers of Clojure were too lazy to implement it.

Without type safety I don’t trust my code so much. I can introduce some awful bugs which will be caught only at runtime. Therefore, I need to write more tests.

I completely agree that declaring types everywhere isn’t a good thing. But just look how Scala, C# or F# solved this issue. They implemented type inference. So instead of forcing you to declare a type each time, compiler tries to infer it from the context. Yes, it’s much more difficult to write a compiler which is able to infer the types but all the modern programming languages should have this feature IMO. Clojure is relatively young and modern language so I don’t see why this couldn’t apply to it.

Having powerful type system in your language is a huge benefit, especially if it’s a functional language. E.g., types can help you to write better unit tests or transparently handle exceptions. Types can also act as a documentation.

I would like to hear the reasons why Clojure is dynamically typed and what are the benefits of this?

On the other hand, I feel that learning the concepts and patterns of functional programming makes me a better developer. I am not saying that object oriented languages have no future. I think they need to embrace functional programming more because some problems could be better solved using functional style.

--

--