Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 4
    What bothers me more is comparing the return value to false, in Yoda style no less. But to stay on topic: this is exactly what exceptions are for. Commented Sep 29, 2024 at 5:51
  • 3
    @Bossie: Exceptions are not intended for returning the status result of a processing operation. Commented Sep 29, 2024 at 5:54
  • 5
    “check beforehand whether its possible to read that many bytes from file or not, and make the read function so that it asserts/crashes if it can't read” is itself an anti-pattern at best, and a time-of-check-to-time-of-use (TOCTOU) bug at worst. And not even always possible to achieve: sometimes you can’t know if you can until you try. Commented Sep 29, 2024 at 11:18
  • 1
    @Newline true/false is not saying much. This is especially true for the error side. You should pass meaningful, rich errors. It helps so much. The best way would be to have a generic/template Result<TOk, TErr> class and pass around meaningful errors in the form of custom class. Commented Sep 30, 2024 at 2:14
  • 1
    ! is much more idiomatic than false == Commented Sep 30, 2024 at 6:53