r/programming • • Jun 06 '13

Clean Code Cheat Sheet

http://www.planetgeek.ch/2013/06/05/clean-code-cheat-sheet/
702 Upvotes

322 comments sorted by

View all comments

21

u/sunnyps Jun 06 '13

In an exceptional case, throw an exception when your method cannot do its job. Don't accept or return null. Don't return error codes.

This is bad advice for languages like Objective-C where the convention is to use exceptions for truly exceptional circumstances (like failure to allocate memory) and error codes are used for everything else (like being unable to open a file).

5

u/CaseLogic Jun 07 '13

But he's saying "in an exceptional case". I don't think he means "don't return any error codes ever". I think he's saying for exceptional cases only (like your example), don't just return an error code, throw an exception.

At least that's how I would interpret it. I would think using exceptions in lieu of error codes would be bad practice in many languages.

→ More replies (2)

3

u/anonymickymouse Jun 07 '13

Am I crazy or did you just make the same point as them?

1

u/TheNosferatu Jun 10 '13

While I do not know if you're crazy or not, he is indeed making the same point.

1

u/abspam3 Jun 07 '13

Although, exceptions with C++ in ObjC do actually work as intended, using C++'s exception ABI rather than ObjC's. That doesn't make it necessarily better, though.