News for hackers. Stuff that matters.
Re:Push ifs up and fors down by PaulDavisThe1st on Wednesday November 15, 2023 @06:30PM (#38283909)
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); }
Re:Push ifs up and fors down by BenFrantzDale on Wednesday November 15, 2023 @10:55PM (#38285693)
I 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!
Re:Push ifs up and fors down by leduyquang753 on Thursday November 16, 2023 @05:02AM (#38287640)
Indeed they are working in a poor language that doesn't allow overloading. It's Rust. :-)