4 ms·
Python 3.12 Preview: Static Typing Improvements
- svilen_dobrev 3y agoback in maybe 2005 (?) i made some library for "staticaly"-typed attributes (via descriptors) , and one day announced in the python mail-list . i was torn into pieces - "if you want static types, use Java!!" . Well.. i wanted static typing only in some places, not everywhere. Fast-forward 20 years.. the pseudo-static-typing-hints are seen like panacea, and applied everywhere, without thinking how much it is useful - with pro's like "my IDE can show what the variable type is". Readability.. begone. Function signatures become horrendous lists of xxx:yyy->zzz , much resembling C++ template errors.. and you'll never notice how some default value has changed in 3rd level of passing those (2 pages of) arguments down. so yeah.. not only code becomes spagetthi after dozen years, but also languages themselves. And python too.
- nicolaslem 3y ago> Function signatures become horrendous lists of xxx:yyy->zzz I get it, I used to think this way when type hints were first introduced. I then tried them and completely embraced them. I maintain a fairly large and old code base in Python where half the code has type hints and the other half doesn't. The half without type hints may look cleaner to read but so much harder to understand when every argument has to be inferred from context.
- svilen_dobrev 3y agostill, that's all hints. What the argument/attribute gonna be at runtime, is .. a guess (maybe with 99% probability what is expected but may also be not). So one gets a hint (in syntax instead of comment saying so) plus a false feeling of assurance of something. i have no problem with the notion of variable anotations, it is wildly useful for many things.. but sparingly.. and not for "static typing" illusion. Python does have real strong types (so you cannot easily replace the type of some object with some other type without anyone noticing, ala (int)(void)(char)x stuff.. but that's nothing to do with this. >> Function signatures become horrendous lists of xxx:yyy->zzz as example that i recently stumbled upon - fastapi, and few others in its vicinity. Seems IDE-fancy-ability trumps common sense. But anyway.
- bakuninsbart 3y agoI'm not too big on the clean code ideology, but I will never understand why a python class/function averages around 37 parameters. Of course it is an incomprehensible mess, but type hints aren't the cause.
- laurent_du 3y agoBefore type hints we had doc strings. "This function takes arguments of the following type and returns a value of this other type. Trust me bro!". Type hints and the ecosystem around them are without any doubt a net progress.
- kunley 3y agoOh no, @override !