4 ms·
Couldn't they use helper methods to convert all those types he brought up to a single common type that they annotated with? It would simplify the API a lot. I c
by seivan 11y ago
Couldn't they use helper methods to convert all those types he brought up to a single common type that they annotated with? It would simplify the API a lot. I come from a full day of working with associated types, generics, type erasures and protocol extensions, there is a darker side to it.
I wanted to have a generic protocol that could have some logic of its own without enforcing you to subclass it. I would regret the decision so much, if I wasn't busy regretting other decisions even more.
Just enforce a type that you accept that's large enough to be used by many and convertable from other common types you want to use.
I swear, soon they'll classify programmers urge to write as generic and extendable as a mental illness.
- snuxoll 11y ago> Couldn't they use helper methods to convert all those types he brought up to a single common type that they annotated with? But then it wouldn't be "pythonic". To be frank though, I think being too generous with your inputs is just asking for maintenance hell. I don't see why requests feels the need to allow data in so many different formats when one or two + conversion functions for anything else would be sufficient.
- seivan 11y agoI've come to realize it's an addiction/urge, that's the only /reasonable/ answer I can give.
- seanp2k2 11y agohttps://en.m.wikipedia.org/wiki/Robustness_principle https://en.m.wikipedia.org/wiki/Robustness_principle """ Be conservative in what you do, be liberal in what you accept from others (often reworded as "Be conservative in what you send, be liberal in what you accept"). """
- taneq 11y agoDidn't we decide later that that's a bad idea? I mean, in the early days of the web, Internet Explorer was the very embodiment of this principle and a couple of decades later the internet is still full of the resulting non-standard crud.
- lomnakkus 11y agoYes we did. It can also lead to really surprising security issues in protocol-land where such "liberalism" interacts badly with security-sensitive portions of protocols. (Security is non-trivial and mostly there are very good reasons that things are exactly as they are in such protocols.)
- taneq 11y agoIn my (limited) Python experience, this kind of amorphous-blob-of-properties interface is great fun to write but is absolute hell to decipher later, especially if you're not the person who wrote it. You end up having to read the entire function and usually recurse through most of the things it calls in order to even know how to call it. That's maybe not so much of an issue if you're just writing small self-contained scripts, but an interface to an API it's awful.