Ask HN: How do you migrate from static to dynamic typing
With dynamics that obviously doesn't exist. I'm not complaining, just looking for coping mechanisms. Unit testing is obviously one, though I've found it's just as likely if you forget to update a function to use the new record format, you'll forget to change the test too, so lots of stuff gets through.
Do you essentially stop refactoring when doing dynamic code, or does it change what you refactor e.g. less "structural" or "naming" refactoring? Or do you find yourself using longer variable/function/class names such that a global text search will be less likely to produce collisions? Other things?
Mostly interested in opinions of people who have successfully/happily made the switch from static languages, especially if they previously liked static typing and were similarly disgruntled initially with dynamics. I'm curious how you've found your programming style has changed.
I recognize many benefits of dynamic languages; that's not what this post is about nor is it meant to start a flame war.
3 comments
[ 4.2 ms ] story [ 14.7 ms ] threadOne big detail is which particular dynamic languages you are using and why. Is it ColdFusion? PHP? Python? Do you have a choice of what language you are using.
The best case for dynamic languages is when you get a truly large improvement in concision. I think for instance of how Clara is about 1% of the line count of Drools Core for a whole bunch of reasons. My favorite environment now is Java + Clojure because I get to use Java when Java is comfortable and Clojure when Clojure is a better fit.
It is a change for sure. But how much did you really let the complier catch before? You have already discovered the "rub" in dynamic languages.
The bit your missing is tooling. You really need to have a solid debugger, one that lets you step through the code. Most of the time this is going to be attached to a solid IDE, and thats also going to be of help!
There are places where TYPE will matter and you should still learn how to cast in your dynamic language of choice. The path from a local variable to JSON in a lot of dynamic languages is a good example, the int you have been using as a string might need to be cast an int to get it to behave the way you want it to, booleans may end up in this boat as well. A static language means the delta between running and RIGHT is pretty small, dynamic may mean this is fairly large. Sometimes it doesn't really matter, and you don't have to care, potentially saving you a lot of time.
What language are you coming from, and what are you going to!