DEV Community

Rudy Ayitinya Sulley
Rudy Ayitinya Sulley

Posted on

The Benefits of Static Typing: A Developer's Perspective

Every developer has their journey of exploration and growth. For me, that journey began with Python, a language that captivated me with its elegant syntax and code beauty. Quicky, I fell in love with the magical power of Python’s indentation-based structure and magic-methods (are they still called that?). The clean and breathable syntax was like a breath of fresh air from the public static void main string args (looking at you Java) and Cs I had initially tried.

Boredom from writing console applications set in and I was eager to find new use for my freshly acquired knack. I got my hands wet with data analysis, machine learning, game development (yeah, with python) and web development. The instant gratification seeing an h1 rendered on the page made me pursue this field. So, with Python as my weapon, I set out to conquer the web development space starting with Django.

As any web developer out there would know, meeting JavaScript is inevitable, and it is only a matter of when.

The Dance with JavaScript

Switching from Python’s embrace to JavaScript’s syntax felt like dancing to a new rhythm. Having to brace every block of code had me going nuts but eventually got used to it, and oh, I’m not a fan of semi-colons, obviously. Knowledge was carried over pretty much instantly. Occasionally found myself writing code like this as it is valid Javascript.

let age = 23
// lots of other code to change age to words
age = twenty-three
Enter fullscreen mode Exit fullscreen mode

Well, not literally like this but you get the point. Python and Javascript are dynamically typed, which means that data types of variables are determined by the value they hold at runtime and can change throughout the program as we assign different values to them. Sure, not having to worry about adding seemingly obvious String and Number types makes you go faster, but with a catch. Your code is more prone to errors and being an interpreted language didn’t help it at all as most of these errors are caught only in runtime. Trying to pass age into a function meant to handle Number types after reassigning it to a String throws no error but could go on to develop into unnoticeable bugs.

Typescript – A Gleamer of Hope

Enter Typescript, it was all the rage and I had to quickly adopt it. The transition to Typescript was like donning a suit of armor. The mere mention of “type safety” was music to my ears, promising a shield against the all-too-familiar foot-shooting incidents that Javascript was infamous for. Increased Developer Experience (DX), faster development times, type safety and boy oh boy, I was hooked. Typescript ushered in an era of heightened DX. With static typing, autocomplete became a trusted companion, guiding me through the maze of methods and properties. The compiler’s watchful eye caught mistakes before they could rear their ugly heads during runtime. This newfound confidence was nothing short of exhilarating.

In a world of dynamic languages, “undefined is not a function” became a cruel joke. But Typescript transformed these cryptic error messages into friendly reminders during development time. With a strong type system, a canvas for creativity my code transitioned into from a playground for bugs.

The Return to Python’s Embrace

Occasional reunions with Python, especially with Django projects, reminded me of the power of static typing. The seamless assurance that my functions would receive the correct types as inputs, and return the expected types as outputs was a luxury I had grown accustomed to in Typescript. This contrast highlighted the tradeoffs and advantages of different approaches.

Embracing Kotlin – Patterns and Beyond

Venturing into Kotlin opened new horizons. Its strong typing and synergy with Java, whom I had initially avoided, gave me a new lens to view code. Singletons and Factories took center stage as the Gang of Four’s timeless wisdom came alive. Buzzwords like dependency injection made more sense and I soon found a new love. So sorry Python (I still love you though).

Beyond The Safety Blanket

In Python, the lack of strict type enforcement can be both a blessing and a curse. It encourages creativity but can also obscure potential errors. Through Kotlin or TypeScript, I learned to confront these ambiguities head-on. Crafting solutions that thrived in the presence of strict typing was a skill I couldn't afford to ignore.

The Grand Merge - Python and TypeScript

Bringing the experience of TypeScript's type scrutiny into Python was like infusing magic. It wasn't about abandoning Python's charm, but about enhancing it with the structured insights I gained from TypeScript. The result? A Python codebase that not only sings but also dances to the rhythm of well-defined types. Although Python’s type hints don’t prevent you from shooting yourself in the foot, the presence of code bleed would signal to any sane programmer to sanitize their code.

Conclusion: A Harmonious Code Symphony

The journey from statically typed languages to Python isn't just about trading one paradigm for another. It's about weaving a symphony of perspectives into a coherent narrative. The discipline of Kotlin and TypeScript infused me with an acute awareness of design patterns, the importance of types, and the power of type safety.

So, as I continue to code, I carry with me the lessons learned from this unique journey. The marriage of Kotlin's patterns and TypeScript's type security with Python's creative elegance is a melody that resonates through every line of code. It is a testament to the pedagogical power of programming languages and the unending quest for mastery they inspire.

What if, instead of starting with the comforting elegance of Python, you dive headfirst into the rigor of statically typed languages like Kotlin or TypeScript? The results are profound, revealing programming's deeper intricacies and best practices.

The programming education landscape could benefit from prioritizing the exploration of statically typed languages like Kotlin and TypeScript. By emphasizing deeper understanding and best practices over quick gratification, educators can equip new programmers with a comprehensive toolkit for building robust, elegant, and reliable software. This journey isn't just about learning languages; it's about gaining insights that transcend specific tools and foster a lifelong passion for mastering the art of coding.

Top comments (0)