Earlier quoted context omitted.
"As the author alludes to as well - in C you're made more aware of the error conditions you can handle and the ones you can't." You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? In the bigger part of most of my programs I want a big, flashy, loud, total failure by default if anything goes wrong.
You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? This is the fault of the programmer who wrote the function, not of the language.
How can C Programs be so Reliable?
11–20 of 105 posts
Re: How can C Programs be so Reliable?
#12Earlier quoted context omitted.
"As the author alludes to as well - in C you're made more aware of the error conditions you can handle and the ones you can't." You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? In the bigger part of most of my programs I want a big, flashy, loud, total failure by default if anything goes wrong.
The only time a function would "silently" return a -1 would be if you're not checking your returns for errors! Functions have return codes for a reason .
Re: How can C Programs be so Reliable?
#13Earlier quoted context omitted.
"As the author alludes to as well - in C you're made more aware of the error conditions you can handle and the ones you can't." You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? In the bigger part of most of my programs I want a big, flashy, loud, total failure by default if anything goes wrong.
if ((result = foo()) == -1) { fprintf(stderr, "!$*!$&^!$*!!!!\n"); exit(1); }
Failing loudly is the only sensible behavior when an unexpected error occurs and there's absolutely no indication of what to do in such a case.
Re: How can C Programs be so Reliable?
#14Earlier quoted context omitted.
You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? This is the fault of the programmer who wrote the function, not of the language.
What? What can a programmer do besides returning a "special" value such as -1 in a language like C with strict types and that doesn't support exceptions?
By the same token, dozens of Java libraries only throw ABCException, with no other information... Might as well be -1.
Re: How can C Programs be so Reliable?
#15Re: How can C Programs be so Reliable?
#16People often write in higher level languages because they want lots of bad code fast. Almost all business applications are CRUD apps (create/retrieve/update/destroy) with some business logic, and they're generally written in C#. The app may crash when you click the wrong button, but the app is cheap to develop and the programmers are easily replaceable. Of course I'm generalizing, and a lot of C# programmers write gr…
One instance is a colleague who needed to do data post-processing, and just did it in C because it was most familiar. A language like Perl or Python would have been a better choice, and saved him time in the long run, since string manipulation in C is tedious and error prone.
Re: How can C Programs be so Reliable?
#17The author has a unique perspective since he - somehow - skipped learning C until now. He programmed assembly before, and from his other work he clearly is familiar with dynamic and more modern languages. Consequently, his perspective on C is that of somehow who is new to the language, yet also understands both the fundamentals of what his code will compile down to, and the higher level facilities that later language…
Re: How can C Programs be so Reliable?
#18Earlier quoted context omitted.
What? What can a programmer do besides returning a "special" value such as -1 in a language like C with strict types and that doesn't support exceptions?
You don't need an exception mechanism to deal with this - good libraries will let you find out the exact condition (if you do get a -1 for example). By the same token, dozens of Java libraries only throw ABCException, with no other information... Might as well be -1.
Re: How can C Programs be so Reliable?
#19Earlier quoted context omitted.
"As the author alludes to as well - in C you're made more aware of the error conditions you can handle and the ones you can't." You mean like when a function silently returns -1 to indicate failure and then you wonder why your program returned a wrong result (if you're lucky enough to even notice)? In the bigger part of most of my programs I want a big, flashy, loud, total failure by default if anything goes wrong.
if ((result = foo()) == -1) { fprintf(stderr, "!$*!$&^!$*!!!!\n"); exit(1); }
Re: How can C Programs be so Reliable?
#20Earlier quoted context omitted.
if ((result = foo()) == -1) { fprintf(stderr, "!$*!$&^!$*!!!!\n"); exit(1); }
That won't scale. I'm sure you'll have lots of fun grepping through your source files looking for "!$ !$&^!$ !!!!" when it appears on your stderr. The point is that with an exception system you don't have to write stupid shit like that everywhere just to crash and burn correctly. Failing loudly is the only sensible behavior when an unexpected error occurs and there's absolutely no indication of what to do in such a c…
tyger(~)% cat main.c
? #include
?
? void main( void )
? {
? assert( 0 == 1 ) ;
? }
? EOF
tyger(~)% gcc main.c
main.c: In function ‘main’:
main.c:4: warning: return type of ‘main’ is not ‘int’
tyger(~)% ./a.out
Assertion failed: (0 == 1), function main, file main.c, line 5.
Abort
tyger(~)%