2 ms·
While 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 ass
by silentbicycle 17y ago
While 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.