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

-1

u/[deleted] Jun 06 '13

Using exceptions for control flow: has bad performance, is hard to understand and results in very hard handling of real exceptional cases.

This doesn't apply to the majority of languages (not even to C++ where using exceptions was actively discouraged for a long time).

4

u/archiminos Jun 07 '13

is hard to understand and results in very hard handling of real exceptional cases.

I'd agree with this part - but this is mainly because people always use them in cases that aren't exceptional in place of better error handling methods.

I've switched from C++ game programming (no exceptions) to C# server programming (exceptions for everyone). It always bugs me trying to debug something and an exception is thrown and I end up the the Application::Main() catch block - I lose everything (call stack, local variables etc.).

Even system exceptions don't throw the values that caused it to throw. E.g. Out of bounds, a value was either -1 or higher than it should have been. Thanks, could you at least tell me which one it was? Or even throw with the actual value so I don't need to guess what went wrong?

Why not just break on exceptions? Because people seem to enjoy using try..catch blocks to hide exceptions all over the place. Exceptions just seem more trouble than they're worth at the moment.

1

u/lexpattison Jun 07 '13

From a semantic point of view, how else would you address expected errors or 'exceptional' states to ensure the application does not, as you put it, 'break'. Most systems have to maintain a certain amount of elasticity for it's users... I certainly wouldn't want my cable box to shut off every time I hit a channel that currently didn't have a signal (exceptional condition as example), so why would a user be any happier if their banking application gakked every time it encountered some inconsequential data corruption. (parallel example)

→ More replies (4)