Saturday, November 4, 2017

Weak Minded Strong Typing

It never ceases to amaze me the prejudice that exists within the coding community against weakly typed languages. Its almost as if variables have no rights. People can change. Why can't variables?

In the Python programming language I can write …

x = 2
print type( x )
x = str( x )
print type( x )

This is a thing of beauty. Its almost as if the variable can transcend its initial limitations and rise above to a greater social status. "I was a lowly int, but now I'm a string".

Try the same in a strongly typed language like Java and see what you get. Many programmers I work with look down their nose at languages like PERL and refer to them as write-only languages, and while I agree PERL's obscure syntax and side effect constructs can make it difficult to maintain, what language is immune to poor programming practices and sloppy hacking. 

I have worked on massive PERL code bases that were easy to maintain because they were written properly, with attention paid to coding conventions and detail. In fact if I recall correctly, when I got to Amazon in 1999 a significant portion of the code base was written in PERL. 

Lately it seems there is a push in the programming community to move towards more strongly typed languages. Even Javascript is not immune, nothing is sacred anymore. Why don't we just leave the language alone. If you are an advocate of strong typing then build your code base in that manner as a convention but don't impose these limitations on others. I have seen many Python projects that were obviously the product of a displaced Java engineer, with abstract base classes, inheritance work arounds and other rigid constructs more typical of a COBOL program than a modern programming language. 

Part of the beauty of coding in a typeless language is the freedom to not have to worry about the particular constraints of the language. Instead one can focus on the design rather than the implementation. Strongly typed languages are notoriously difficult to work with when the class structures are dynamic in nature to the point that you often feel like you are fighting with the programming language to get the job done. 

I once saw a Java stack trace that was 83 levels of inheritance deep. I can't think of anything that is that abstract in real life. 

While I can appreciate the desire to produce maintainable code I can also appreciate the benefit of flexibility in a programming language. I sure hope the result of this recent strongly typed movement is nothing more than a set of recommended best practice design patterns, and not the onslaught of a bunch of strongly typed interpreters. 
  


No comments: