News for hackers. Stuff that matters.
Re:Robust Programming by lehmannro on Friday September 17, 2010 @03:40AM (#1700419)
Assume that the caller or user is an idiot

I think this is not helpful at all, probably harmful. There might be use cases for my code I did not even think about and third-party programmers should well be able to use it as they wish. And if they feel like modifying internal state (which the author deems fragile in his article) -- oh well! We are all adults here.

NB. I agree that the library he's examining is sub-par quality and is well worth a look.

Re:Robust Programming by andymorris on Thursday September 16, 2010 @07:31PM (#1699502)
At my last company, I had to code in this style, and it sucks. You get into ridiculous situations where you have to somehow fail gracefully with absolutely no context or information about how to do so.

Exceptions are a much better solution - I pity anyone who isn't able to use them.

-- Ayjay on Fedang #coding

Re:Robust Programming by wanderr on Thursday September 16, 2010 @07:40PM (#1699517)
Re:Robust Programming by apu on Thursday September 16, 2010 @06:17PM (#1699330)
Mostly about C programming, but many of the comments apply equally well when you're writing a library in a higher-level language or a web API.

Still, I'm glad not to have to worry about malloc fails, pointer craziness and array overflows anymore, for the most part =)

Re:Robust Programming by corysama on Thursday September 16, 2010 @11:08PM (#1699953)
I'll grant you pointer craziness and give array overflows a pass, but I ran into a MemoryError exception in Python just a few hours ago. I loves me some higher-level languages, but they still run on a machine with lower-level limitations.
Re:Robust Programming by figment on Thursday September 16, 2010 @04:17PM (#1699007)
one other useful thing to point out. It can often be harder to implement robustness at the bottom of your call chain. You may need to step up a layer.

user_method() call_to_get_info_from_remote_system()

Just because call_to_get_info_from_remote_system fails doesn't mean you have to be done.

user_method(tries) while i < tries if call_to_get_info_from_remote_system() == FAIL # log error if check_remote_system_reachable() # fatal error be done i++

granted this makes all kinds of assumptions like you can afford to retry this operation up to N times. It also may break the rule of "Stupidity"

Re:Robust Programming by JoeAltmaier on Thursday September 16, 2010 @07:00PM (#1699436)
Appropriate for exported APIs; maybe not for internal objects used once by your own code.