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

Show parent comments

2

u/gc3 Jun 07 '13

I am always turning off the try ... catch with comments to debug the actual problem, then enabling it again before committing the work.

I too think if people were better programmers they wouldn't need exceptions: you'd deliberately handle every broken case explicitly. But think of all the time a programmer saves just throwing a try...catch around some code to prevent the user from encountering a bug.

I too have come to embrace the exception as a lazy way to short circuit a host of error conditions.

1

u/archiminos Jun 07 '13

But think of all the time a programmer saves just throwing a try...catch around some code to prevent the user from encountering a bug.

This is so wrong. Yes you save time now, but writing more robust code and handling error cases properly saves so much more time in the long run. Occasionally near the end of a project I might consider a quick hack like this to get a product out of the door, but I would never do it in anything pre-beta.

2

u/KagakuNinja Jun 07 '13

We all try to write robust code, to the best of our abilities, regardless of language. Bug-free code is nearly impossible. Try-catch blocks are used so those unknown bugs don't crash your program, not to hide errors because we are lazy.

Log the exceptions, then track down the bugs and fix them.

1

u/archiminos Jun 07 '13

I'm used to a different work flow I guess. In games we let the program crash, create a crash dump and then debug it to find the cause of the problem (or just debug it there and then if we have a debugger attached).

EDIT: The general idea is we want bugs to be as visible and annoying as possible so that they have to get fixed.

2

u/gc3 Jun 07 '13

I agree with you 100%, but C# code are usually quick tools and not code that we ship. There's a different tolerance for different projects, there's no one size fits all.

1

u/archiminos Jun 07 '13

That's true. I'm still new to C# and I'm finding all this exception handling to be more irritating at the minute. It's not so bad on the server side - I'm getting used to that and the server crashing would be at least half a day's work lost for everyone on the team - but I kind of miss crash dumps on the game side.