News for hackers. Stuff that matters.
Re:Voyager 1 starts making sense again after months of babble by williamcotton on Thursday March 14, 2024 @03:01PM (#39707695)
It is known as error handling. Some languages renamed the practice to try/catch. Others added a Result type.
Re:Voyager 1 starts making sense again after months of babble by trealira on Thursday March 14, 2024 @03:46PM (#39708198)
Likely you know this, and you're just being funny, but the try/catch statement is more like setjmp/longjmp in C. The Result type in Rust is syntactic sugar for integer return codes, returning early on errors, and tagged union structures. And where C programmers use goto statements, C++ programmers use destructors, and Rust programmers use the Drop trait. Walter Bright also says that nested procedures in D eliminate most use cases of goto for him.

You can also always avoid goto, in C, but usually, either it has excessive if-statement nesting, it uses boolean flag variables in loop conditions, or it uses structures to create state machines, but these are usually just uglier and more error-prone than the equivalent version using goto. The same applies to avoiding break, continue, and early returns.