6 ms·
Yay for another person like me who wants to be able to sprinkle just a little static-typing goodness back into the dynamic typing orgy everyone is having these
by zmimon 17y ago
Yay for another person like me who wants to be able to sprinkle just a little static-typing goodness back into the dynamic typing orgy everyone is having these days.
I don't mean huge cumbersone Java or C++-esque typing, just the simple ability to declare to the compiler (or to humans trying to read my code) - 'object foo is a Foo, please give me a hand and tell me if you can deterministically figure out that it is not, or if it is doing something that Foos are never allowed to do'.
- silentbicycle 17y agoWhile it's not caught at compile time, why not use assert? assert(type(x == "float")) should be a very clear declaration to others reading the code, and assert is also not limited to type checking. I like static typing in some circumstances, but adding it to Python would be a major change to the language. I'd rather just use OCaml when static typing is really important, and save scripting languages for the niches in which they excel.
- jnoller 17y agoasserts are stripped out when python is run in optimized mode. Not to mention sprinkling them around your code is infuriating for people dealing with your code :) I'd also point you to the links to guido's writeup I put in the post, I agree: it changes the language too much to be a positive net gain.
- silentbicycle 17y ago> sprinkling them around your code is infuriating for people dealing with your code Would this necessarily be any less true of static type annotations, though? And as for them being stripped out, yes - it's for making debugging easier, not performance.