DEV Community

Discussion on: When was the last time you ran your code successfully on the first try?

Collapse
 
wclayferguson profile image
Clay Ferguson

One thing you learn after about 30yrs of coding is to never write more code than you know will work on the first try. This way you genuinely end up with about 95% of your code just always working every time, on the very first try. I genuinely do that all day every day.

Sure part of this is just the skill level attained from that many decades under your belt but the thing junior developers can learn is only write a few lines at a time. Once you think "I wonder if this is going to work" you've written too much already. Comment out some (to back up) to where you fully understand it again, then test that first, before adding more.

Also when the code DOES fail you know which 5 lines of code to look at and in generally have the 'ah ha' moment the second yo do see it fail, when it does.

Collapse
 
ravgeetdhillon profile image
Ravgeet Dhillon

Great Advice.