News for hackers. Stuff that matters.
Re:Ask HN: What habits make a programmer great? by ryandrake on Thursday July 06, 2017 @12:33PM (#14711630)
Think about your error handling best practices. Mine are:

1. Re-structure your logic so the error cannot happen

2. If you can't do 1, recover from the error silently and continue on with the program

3. If you can't do 2, handle the error gracefully and notify the user of what state is changed, letting them choose whether or not to continue

4. If you can't do 3, inform the user of what happened and ideally provide the user corrective action they can take, then exit cleanly with an error code

5. If you can't do 4, exit cleanly with as descriptive of an error code as you can

6. If you can't do 5, you're probably faced with crashing or exiting with some unhandled exception. This is a bug that should never go into production.

Always be looking for opportunities to move your code up that hierarchy. Moving every 6 to 5 is my personal bar for barely acceptable quality. 4->3 is usually a big win (basically anything that prevents the program from exiting).

Re:Ask HN: What habits make a programmer great? by ahoka on Friday July 07, 2017 @10:05AM (#14718381)
"2. If you can't do 1, recover from the error silently and continue on with the program"

I think that defensive programming is the worst way of dealing with errors. You are now silently diverging from your business requirements by making up data.

Re:Ask HN: What habits make a programmer great? by ryandrake on Friday July 07, 2017 @11:15AM (#14718961)
Thanks for the reply. Yep, this is a topic that reasonable people can disagree about. I suppose I could add "if there's no loss of user data, recover from the error silently and continue on with the program". An example of #2 would be a network connection failure that can be retried without consequence to business logic.