71
Ideas / Re: Error handling [proposal]
« Last post by bas on December 07, 2018, 10:40:23 AM »The main issue I have with this approach is:
- what is the actual problem it's trying to solve?
- it makes the syntax a Lot more complex (and unreadable).
- it only helps if the error system is used universally used (like in Go). In C that will never be the case
I think the power of C(2) is it's simplicity. Code can be very readable, because once you understand
a few simple patterns, it's all the same. Like:
So in C the pattern is to (for example) use signed values to be able to use special values (eg -1) to indicate
an error.
A more extended pattern is to always return a Result Enum, where Result_Ok is the happy flow. Other output
variables then need to be passed back via out params.
Just sticking to these patterns is so very powerfull, since all C programmers understand them from day 1.
- what is the actual problem it's trying to solve?
- it makes the syntax a Lot more complex (and unreadable).
- it only helps if the error system is used universally used (like in Go). In C that will never be the case
I think the power of C(2) is it's simplicity. Code can be very readable, because once you understand
a few simple patterns, it's all the same. Like:
Code: [Select]
int fd = open(..);
if (fd == -1) {
// error
}
So in C the pattern is to (for example) use signed values to be able to use special values (eg -1) to indicate
an error.
A more extended pattern is to always return a Result Enum, where Result_Ok is the happy flow. Other output
variables then need to be passed back via out params.
Just sticking to these patterns is so very powerfull, since all C programmers understand them from day 1.