I spent more than half of my career programming in strongly typing languages such as C, Pascal and Java, where for each variable we have to implicitly associate a data type. And the rest of my career programming in weakly typed languages, also known as loosely typed, such as PHP, JavaScript and shell scripts.

I’m a firm advocate of strong typing since allows the compilers, JIT’s and interpreters to optimize data according to their data type, which allows a much faster execution and less memory footprint.

However, I see the benefits of having weakly typed languages since it’s easier for newcomers and if speed isn’t an issue especially in small scripts or programs, it’s much simpler just to type the variable name, and let the JIT or the interpreter do the data type conversion when data from different types need to be manipulated without the need of typecasting.

I’m from the time where every clock cycle counted since computers were slow for what it was demand. At that time, the web had given its first baby steps to provide dynamic content.

Small Perl, then later PHP, scripts on the server-side, and JavaScript scripts on the browser side allowed the user to interact with the web pages, but it was very limited at that time.

C/C++ and desktop applications were what the users rely to deliver complex operations.

Then, the internet boomed, and the computers got faster and faster at Moore’s Law rate. The paradigm shifted from personal computers to the web, and later to the cloud. Computers were no longer slow, and we no longer rely on personal computers; step by step, it was the web servers that executed the scripts and applications. The cloud, micro-services and other methods allowed to massive parallelization at controlled cost, and with it, large scaling become possible without the need of mainframes.

Now PHP and Javascript allow to build complex web applications, but with it, a new problem arose: these languages weren’t designed to be developed at large. The easiness of their weakly typed now become more difficult to catch bugs at an early stage, as opposed to strongly typed languages that the compiler can catch data type issues.

PHP 7.4 introduced the type declarations, and TypeScript language was created as a superset of Javascript adding static typing. Both languages, didn’t stopped being weakly typed languages, but with type hinting, it become possible to add optional type checking when calling and exiting functions or methods.

At this point, I would like to highlight that type of hinting, although it provides a checking mechanism it doesn’t optimize the code for a specific data type, and it’s still possible for a variable to change its type when its value changes.



strong vs weak_typeLanguages

Python is an interesting case study when it came to data types. Python is a dynamic typed language and it was developed much earlier than PHP or JavaScript, although it was only published in 1991, still 4 years earlier than PHP and JavaScript.

Python is known for being an easy language to use. In my perspective, its strong point is its close relationship with C. The fact that integrates so well with C, allowed for a long time to be used as an easy way to allow the users to extend C desktop applications. Almost all the 3D content creation applications allowed the user to write its own python scripts. On Linux distributions is also quite common to have GUI applications written in python.

However, it was its symmetrical relationship with C that allowed it to boom when Data Science became increasingly popular. Python is easy to use but isn’t fast, as Guido van Rossum, its creator, clearly stated, and Data Science is mainly about the very large volume of number crushing which could be agonizing slow if we were only to rely on Python, but Python is designed from the ground up to have its packages written in C, and with the essential data science packages such NumPy, Pandas, Scikit-Learn, TensorFlow, taking the advantage of the GPU and parallelization, Python has skyrocketed in the realm of the Data Science, and it’s now one of the top popular languages.

Also, Python has embraced the power of type hinting since its version 3.5, although, as its authors stated on PEP 484, “Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention”.

I have met plenty of PHP and JavaScript developers who have offered resistance to adding types to their code, in case of JavaScript, it would mean migrating to TypeScript. They think that it’s a waste of time and code space, but like any other technology or technique, it takes time from its implementation to its adoption, and some developers will always feel more comfortable with typeless coding.

In the case of Python, although, version 3.5 has been around since 2015, type hinting is still something that isn’t common in the developers debate about their programming habits.

If I could predict the future, I would see the developers do a slow shift into adhering to stricter and stricter type checking systems, and in the far future, if enough developers write code with types, I believe that the JIT’s and interpreters will be able to optimize the application based on that, almost like it does the strongly typed languages.


written by Alexandre Freire