4 ms·
I work in Python day to day and have done for several years, so I think I'm entitled to describe Python's type system as "surprising." I generally think duck t
by sevensor 8y ago
I work in Python day to day and have done for several years, so I think I'm entitled to describe Python's type system as "surprising." I generally think duck typing is great, and I always appreciate the flexibility it gives me. But the flip side of that is -- surprise! -- you can't use me as an index! -- surprise! -- I'm not hashable! -- surprise! -- you can't pickle me!.
I've been looking at how other languages handle this, and I think typeclass / trait systems seem to strike a good balance, allowing flexibility without surprises.
- bunderbunder 8y agoThe typeclass approach can be just as surprising. Possibly more so, because it means that a type's implementation of a class can come from literally anywhere. So the universe of surprises still includes "Surprise! It's not hashable!", but now also includes, "Surprise! It was hashable, but now isn't, because you stopped importing this seemingly unrelated package." If you do get surprised that X doesn't support Y, though, you have ability to provide your own implementation without resorting to monkey patching.
- sevensor 8y agoThat's a good point! I suppose the grass is always greener...