this post was submitted on 07 Sep 2023
1023 points (98.9% liked)
Programmer Humor
19589 readers
760 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
What kind of runtime tag corresponds to generics, exactly?
Python handles generics essentially the same way that Java 1.0 handles generics: it just kinda punts on it. In Java 1.0, list is a heterogenous collection of Objects. Object, in Java 1.0, allows you to write polymorphic code. But it's not really the same sort of thing; that's why they added generics.
Ish.
There's typing a la Curry, where semantics don't depend on static types and typing a la Church, where semantics can depend on static types.
Haskell's typeclasses, Scala's implicits and Rust's traits are a great example of something that inherently requires Church style typing.
One of the nice things typeclasses let you do is to write functions that are polymorphic on the return type, and the language will automagically pick the right one based on type inference. For example, in Haskell, the result of the expression
fromInteger 1
depends on type ascribed to it. Use it somewhere that expects a double? It'll generate a double. Use it somewhere you expect a complex number? You'll get a complex number. Use it somewhere you're using an automatic differentiation library? You'll get whatever type that AD library defined.That's fundamentally not something you can do in python. You have to go with the manual implementation passing approach, which is incredibly painful so people do it very sparingly.
More to the point, though, limitations have both costs and befits. There's a reason python doesn't have goto and that strings are immutable, even though those are limitations. The question is always if the costs outweigh the benefits or not.