3 ms·
I think we've largely settled on "doing clever things is bad, actually." At least, I have. Your code should be obvious and self-documenting. Relying on languag
by coldpie 4y ago
I think we've largely settled on "doing clever things is bad, actually." At least, I have.
Your code should be obvious and self-documenting. Relying on language features to do a bunch of stuff behind the scenes more often leads to programs that are hard to debug and perform badly. How many times have you had to dig into C++ operator overloading compiler errors or someone being too clever with C macros (wait, that macro can return?!?) or someone overloading a Python built-in function in surprising ways. Coming across the short double example from the article in production code would make me groan. The "all sorts of uses for this kind of trick" the author lists sound like a nightmare for some poor employee to have to reverse-engineer five years from now.
I feel modern languages (Rust, Go, Swift) have moved away from clever, implicit behavior in favor of more considered and explicit code-efficiency mechanisms. For example making error handling (? error operator in Swift & Rust) an explicit first-class citizen, rather than some clever macro hacking; or the trend away from operator overloading and complicated class structures and towards explicitly declared interfaces; or the many restrictions on Rust macros[1] to help ensure they're maintainable.
[1] https://veykril.github.io/tlborm/decl-macros/minutiae/hygiene.html https://veykril.github.io/tlborm/decl-macros/minutiae/hygien... and related sections
- zozbot234 4y ago'?' in Rust isn't quite a first-class citizen. It would be one if Rust supported general effects.
- __jem 4y agoIn what way is '?' not first-class error handling just because it does not exist in the context of a generalized effects framework? I don't see at all why handling other effects is a requirement for error-handling to have good ergonomics in the language.
- fizx 4y agoAs a sometimes-clever programmer, I find it interesting that Github Copilot is discouraging my inherent cleverness.
- int_19h 4y agoI wouldn't conflate Rust and Go here. Rust does this right - it doesn't try to remove the "clever" features altogether but streamlines ergonomics such that they're rather painful to use in "bad" ways. On the other hand, Go is an antipattern of PL design - it avoids features to such an extent that you end up writing less readable / maintainable code because of it (just witness all the codegen before generics!).