Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
willol13898yYeah, I don't understand why Python doesn't have optional static typing :/ that would make the language so much more usable for real projects
-
Doesn't an extension exist that adds this? Or something that compiles to python, which is just a thin layer of static typing. Kinda like what typescript is to JavaScript
-
eldamir12298y@kpenc @ElectricCoffee but the type annotations are nowhere near as powerful as your average statically typed language. Simply because the class definitions in Python are not rigid enough :(
I am taking my personal projects more and more away from Python to Kotlin, since kotlin has even stronger checking than Java and the much desired type inference :) -
rayanon13608yHaha. I just also ranted about the same thing!
BTW, folks @everyone check out this project called mypy[1]. It adds optional static typing in Python via function annotations in Py3 and comments in Py2. Even Guido contributes to the project!
[1] http://mypy-lang.org/ -
This is not really a problem if you do proper testing, which you should do regardless of language anyway.
You can do static analysis in python with something like PyLint, it will find many errors. -
eldamir12298y@gggggggggg i hear this argument often, but it is nut entirely true. With a language like Java, you have completely removed an entire type of errors: type errors. That is a lot of tests you don't need to write.
In other languages, the compiler protects from null errors. More tests that need not be written.
So while we must always test, there are a lot fewer types of tests that need to be written for statically types languages. That is my point. And it is something that Python does not have. Even with linters -
rayanon13608y@gggggggggg it is totally a problem. Like @eldamir said you can remove a huge class of stupid tests. You just have to use a statically typed language to see the benefit. When the compiler guarantees your types match you have a very safe program. It won't throw shit errors in production suddenly like "NoneType is not iterable"! (To the Python interpreter: We all know that you giant fact machine! But that doesn't help right? Why the fuck did you accept that type in function then if it was of NoneType?)
I've been programming 5 years in Python and few months in Haskell. So my point view is based on my experiences. And the above error is one that I faced in prod recently.
@eldamir check out this project called mypy. It offers optional static typing for Python. -
eldamir12298y@rayanon i've had a look, but it doesn't seem to take it anywhere far enough, unfortunately.
But happy to see that we share opinions in the matter of languages. What kind of apps do you code in Haskell? It is strictly functional and stateless, right? No objects? -
@rayanon I write statically typed code every day ;)
"NoneType is not iterable" is not an error that would be fixed by static typing, as that would cause e.g. a NullPointerException in Java.
You don't need special tests in dynamically typed languages.
Yes static typing prevents certain errors at compile time, but duck typing allows you to speed up your development time drastically.
As I said I use both and I don't clearly prefer either one, I'm just against the rampant fanboy/girlism on both sides.
That said, modern type systems like Rust's "trait" system aim to merge benefits of both static and dynamic typing and I'm excited to see where that will bring us. -
rayanon13608y@eldamir objects not in the OOP sense. Yes it is purely functional and stateless. It might seem awkward at first but it's fun once you get the hang of it.
Among non-trivial apps, I have coded a Sokoban game and a small web service. -
rayanon13608y@gggggggggg I would not consider Java to be an example of good typed language. Languages with powerful type systems have existed since the 70s (read ML family). They were considered highly academic and arcane until recently, and people are beginning to see the benefits of a good type system in terms of guarantees and safety it gives you. Just look at Facebook and Microsoft.
These type systems are quite different from that of Java/C#/C/C++. You should have a look.
Related Rants
Biggest annoyance of favorite language:
Python has no static type checking. I know that is not something that is intended for Python. It's just that I enjoy the syntax, but would love the type-safety of something like Kotlin/Java
undefined
wk30