Let's talk dynamic languages

Dynamic languages blow

After trying to develop a few applications in JavaScript I was not impressed. The dynamic nature of the language thoroughly confused me and I felt like I had taken a step backward. I didn't have a compiler that would catch my errors, I didn't know what types my variables were most of the time, and I didn't even know what properties my objects had because there was no intellisense.

In C# I could simply type a variable, hit dot and blammo I'd have a comprehensive list of all properties on my variable. The Visual Studio parser never had to guess at what properties I had access to. Everything in C# was explicitly architected and I was able to catch tons of silly mistakes just by compiling my code. C# is the best programming language out there with Java coming in at a close second. Weakly typed languages are nothing more than toys. You could use them to write a small application for fun but for any serious enterprise application you need to use a real language.


I used to think exactly what I wrote above, but not anymore! Two years ago I would have told you that using a dynamic language makes you a worse programmer because you don't get compile-time checking. The exact opposite has been true since I began writing extensive JavaScript. It is precisely because I am responsible for catching my errors that I am now a better programmer than I was before.

In my C# zealot days I always championed testing and documentation. I couldn't have been a bigger hypocrite because I rarely wrote tests or documentation. I would either find ways to automate those tasks as much as I could or I would skip them entirely. The result was really bad or non-existent documentation and tests that didn't mean anything.

Since I started programming in Node.js I've been forced to become a better developer and adhere to best practices as much as possible. The flexibility of a dynamic language like JavaScript has allowed me to craft APIs that make complete sense to the user. I can't count the number of times I would curse at C# for making me perform the most mundane tasks to accomplish something simple. The APIs I was forced to expose through my class libraries were okay but they never just made sense. The user would always have to jump through some hoops to use my library.

Node.js makes it so easy to create libraries, or modules as Node prefers to call them. I've always felt that modules should operate as a sort of black box that accepts an input and returns a result. If your module exposes a hundred different functions then you're probably doing it wrong. Modules should be small and agile so the user doesn't have to read a book every time they consume someone else's module. In Node that is exactly how things are done.

A lack of compile-time checking has been the fire under my ass to write behavior-driven tests and the black box nature of modules has actually made writing tests somewhat enjoyable. Tests in a Node module actually mean something; when you have a well-defined scope for your module writing tests to ensure your module behaves as expected is extremely rewarding. Node makes it so easy for others to pull my module down from the package registry, run my tests, and consume my module. For once I feel like writing tests is not a waste of time.

A lack of intellisense has forced me to keep good documentation. In a dynamic language like JavaScript it's not easy to understand how to use the API that another programmer has exposed within their code. In C# I could explore the library's namespace and see all the available methods. That actually hurt libraries in C# because many authors would just leave it up to the user to figure out their API. In Node your module cannot gain a following if you have bad documentation. It's as simple as that. Sure you could open up the module and browse the source but for some modules that is such a slow and tedious task. If the author provides a solid README file in their package then users feel far more confident consuming the module's API.

Despite all the little things I lost when moving to a dynamic language, I don't miss it. The power of a dynamic language has been revealed to me and overcoming the few things I lost has only caused me to become a more responsible developer. Writing in the Node environment has reminded me what it was like to have fun programming. For a while there it was starting to feel like my job.