2 ms·
I looked at Clojure but the lack of static types and thus losing the benefit of refactoring always put me away. Out of curiosity - how do you safely refactor Cl
by lenkite 10y ago
I looked at Clojure but the lack of static types and thus losing the benefit of refactoring always put me away. Out of curiosity - how do you safely refactor Clojure code ? Safe Refactoring offered by type safe languages is such a major aid to redesigning code that it has become difficult for me to work in dynamic languages for any large code bases.
- _halgari 10y agoI've been a full-time Clojure dev for about 4-5 years now. And the number of times you have to refactor (in the traditional sense) Clojure code is pretty rare. And the reason is that Clojure leverages it's use of immutable data structures, namely hash maps. So let's say I have a function that needs :name and :addr and it adds a new field calls :name+addr. Now in most (all?) statically typed languages I would have to say that this function takes a "name and addr" and returns "name, addr, and name+addr". So I have a type conversion, right? If the time comes that I need to modify these types, I have to do some sort of refactor. In Clojure we'd just take a hash map and add a new k/v pair to the hash map we get. Any hash map will work, as long as it has the proper entries, and we'll just add a new entry to that. So if the time comes that I want to call this function with a "company" instead of a "person", it just works, as long as I have the proper keys. And to help check this sort of stuff we do have spec (https://clojure.org/about/spec https://clojure.org/about/spec). TL;DR -- my belief having programed in both static and dynamic languages is that deep refactoring is primarily driven by the inflexibility of static types.