4 ms·
On the other hand, any attempt at writing something like this in production code warrants the firing squad.
by mercurial 13y ago
On the other hand, any attempt at writing something like this in production code warrants the firing squad.
- eru 13y agoWhy? It seems unnecessary, but not overly hard to read. Some re-education should be enough.
- gleenn 13y agoIt's bad because it beckons bad behavior. Instead of doing the simple thing and changing your if-statement which puts the idiosyncrasy in the relevant piece of code, you are tucking away the behavior out of sight when something like this almost definitely belongs directly in front of your eye-balls. This is a bit of a strawman, but being able to do class Foo(object): def __bool__(self): return random.random() > 0.5 shows how crazy you could be. If you really want something weird, put it in the if-statement
- eru 13y agoI do agree with you. That particular bit of craziness wouldn't be possible in Haskell. (Since that would require declared side-effects, and my interface above didn't have any declared.)
- mercurial 13y agoNorth Korea-style? It's unidiomatic. Usually, when you find yourself writing unidiomatic style, it's a symptom of one of two issues, or both: - you are doing something you shouldn't - you are doing it in the wrong language
- mercurial 13y ago(replying to myself) It's particularly bad because it is the kind of "clever" unnecessary code which is unlikely to see widespread adoption, clashes with existing conventions, and will eventually be disposed of after the author has left the company to pursue other opportunities. Don't write clever code!