Context
Being a full stack developer, I have decent experience with both python and Typescript. I often use python for API development and I have been trying to write code that is pep-484 compliant (aka fully typed). However, often I get the feeling that if I was using TypeScript it would be much easier.
That got me wondering why there isn't a fully typed language that compiles to python.
I am aware of some arguments, so I am going to get the conversation started by providing my thoughts on them.
ts2python
ts2python is a TypeScript to python compiler.
Unfortunately, it covers only a small subset of python's capabilities. I am not sure why this hasn't been adopted and/or expanded to cover more of python's capabilities, but I can see possible issues with some python features that are not supported by TypeScript like context managers or operator overloading.
Still wondering if it would be possible to extend the TypeScript compiles so it would support such features?
pep-484
pep-484 describes how to provide type hints for python, it's not ideal but good enough that don't have to invent a new language.
IMO that's a trap, pep-484 (and other typing related peps) are not a good enough solution, on the contrary sometimes they are straight up misleading.
For example, consider the stubs for comparisons with built-in types, you would notice that they are defined as __op__(self, other: Any) -> bool: ...
which is not correct as when other
implements __opposite_op__
that is called instead of builtin.__op__
, and it's return value may be of a different type.
Typing tools have not caught up with it, right now only pyright has full compliance with pep-484 (and other typing related peps). For that reason, SQLAlchemy had to introduce more than a couple of workarounds so MyPy can understand what's is happening behind the scenes, even for features that are pep-484 compliant.
Use Another Language
Python was never meant to be fully typed, and they make it clear.
True, but there are a bunch of libraries unique to python that make it a mandatory choice for many tasks. Things are changing and other options become available, but it's going to take time until there is another viable alternative.
Conclusion
Interested to read your thoughts.
- Is there another reason typing support hasn't advanced?
- Are you satisfied with typing support for python?
- Are you transitioning to another language?
- Are you aware of any new and exciting typing tools?
Of course, if typing is not an issue for you, that's okay, every software has different constraints.
I can provide some context from Greece.
First of all, the unemployment rate is high. The official figure is currently at 12.5% but has been steadily decreasing from its peak of 27.7% in 2013. The real numbers are probably higher since people that haven't been employed within the last few years are not accounted.
As a result, labour rights are non-existent, overtime is rarely paid, wages have been stagnant since 2008, it is really common to work in unsafe conditions, and worker abuse occurs so often noone bats an eye.
While we do have unions more often than not they are powerless. For example, last year we had a major train accident (57 people died), the goverment blamed the train workers, their response was pretty much "our strikes for the safety issues that lead to the accident were deemed illegal, while our attempts to raise the issues were dismissed by the ministry of transportation".
We have had major nationwide protests with more than a million of people taking to the streets, but noone feels like that ever lead to anywhere.
IMO one of the greatest problems is the lack of information. Mainstream media are corrupt, and independent media are sabotaged or persecuted by the government. People do not know their rights, we have been trying to survive for so long that we cannot imagine a better future, and that allows employers to freely profit from laborers.
One interesting development is that lately more collectives are popping here and there, from coffee shops to softwafe development houses, more and more people are fed up and try to take matters on their own hands (even if in absolute numbers they are still very few).