Skip to content

Piero Bosio Social Web Site Personale Logo Fediverso

Social Forum federato con il resto del mondo. Non contano le istanze, contano le persone

The unwrap thing is the equivalent of ignoring the return value of C functions that can fail.

Uncategorized
2 2 4
  • The unwrap thing is the equivalent of ignoring the return value of C functions that can fail.
    I still prefer the Rust syntax for this, at least ignoring the error is explicit text in code.
    In C ignoring a possible error is silent. To spot the error one would need to know the function signature and documentation in advance.

    Side note: exceptions are even worse in my humble opinion. They have the advantage of giving more information about an error than just a null or a negative number. But it's even less obvious which function might return an exception and what's the best place to handle them.
    Functions with multiple return values are the way to go, even better if the return value is a tagged enum with information on both the correct operation or the error.

  • The unwrap thing is the equivalent of ignoring the return value of C functions that can fail.
    I still prefer the Rust syntax for this, at least ignoring the error is explicit text in code.
    In C ignoring a possible error is silent. To spot the error one would need to know the function signature and documentation in advance.

    Side note: exceptions are even worse in my humble opinion. They have the advantage of giving more information about an error than just a null or a negative number. But it's even less obvious which function might return an exception and what's the best place to handle them.
    Functions with multiple return values are the way to go, even better if the return value is a tagged enum with information on both the correct operation or the error.

    @portaloffreedom "The unwrap thing is the equivalent of ignoring the return value of C functions that can fail."

    No, it's not. Unwrap is an active check on whether the result of a function call is an error and then aborting program execution via some way, usually unwinding the stack and exiting with error code and "panic information".

  • oblomov@sociale.networkundefined oblomov@sociale.network shared this topic on

Gli ultimi otto messaggi ricevuti dalla Federazione
Post suggeriti