News for hackers. Stuff that matters.
Re:Const all the things? by brandmeyer on Monday January 24, 2022 @11:35AM (#30059957)
In the presence of types which are truthy (ie, contextually convertible to bool), its too easy to accidentally swap the unpacking:

    // Oops, backwards!
    auto [result, error_code] = do_something();
    if(error_code) {
      process(result);
    }
Re:Const all the things? by BoorishBears on Monday January 24, 2022 @01:00PM (#30061317)
To me that's not easy...

It's a very well established pattern to have (error, result) I'd immediately see something off with (result, error)

And clang-tidy can catch this: https://clang.llvm.org/extra/clang-tidy/checks/readability-i...

Re:Const all the things? by Kranar on Monday January 24, 2022 @01:24PM (#30061683)
Fair enough, in my codebase we always order data in terms of dependencies so that independent data comes before dependent data. In this case the result depends on the error_code, and the error_code is independent, so the error_code must be listed first.