3 ms·
Contrarily: Push ifs down: BAD: if (ptr) delete ptr; GOOD: delete ptr; Polymorphize your fors: frobnicate (walrus); frobnicate (walruses) {
by PaulDavisThe1st 3y ago
Contrarily:
Push ifs down:
BAD:
if (ptr) delete ptr;
GOOD:
delete ptr;
Polymorphize your fors:
frobnicate (walrus);
frobnicate (walruses) { for walrus in walruses frobnicate (walrus); }
- BenFrantzDale 3y agoI agrée with them and with you. It looks like they work in some poor language that doesn’t allow overloading. Their example of `frobnicate`ing an optional being bad made me think: why not both? `void frobnicate(Foo&); void frobnicate(std::optional<Foo>& foo) { if (foo.has_value()) { frobnicate(foo); } }`. Now you can frobnicate `Foo`s and optional ones!
- leduyquang753 3y agoIndeed they are working in a poor language that doesn't allow overloading. It's Rust. :-)