When it doesn't work on your machine or your brain or anywhere...

Last updated on August 06, 2024
When it doesn't work on your machine or your brain or anywhere...

Developers spend 75% of their time debugging and this is a major reason why.

Avoiding this mistake will massively cut down the bug occurrence rate in your code.

Never take new code for granted.

A simple but powerful principle with several implications.

Never assume your code works just because it looks alright

Always test your code in the real world.

And not just your machine.

You cannot trust your mind on this -- That's why bugs exist in the first place.

Bugs are always something you never expect.

It's a big reason why debugging takes much time, especially for complex algorithms.

Your mental model of the code's logic is hopelessly divorced from reality.

It's often only when you carefully step through the code line-by-line & var-by-var before you finally realize the disconnect.

It's the same reason why it can be so hard to proofread your own writing.

Your brain already knows what you meant to write. It has already created a mental model of the meaning you're trying to convey that's different from what's actually there.

So what happens when you try re-reading your work for errors?

You're far more focused on the overall intended meaning than the low-level grammatical and spelling errors.

That's why code reviews are important -- get your work scrutinized by multiple eyes that are new to the code.

That's why testing regularly is important.

Test regularly and incrementally and you'll catch bugs much faster and quicker.

As soon as you make a meaningful change, test it.

And this is where techniques of automated testing and continuous integration shine.

With manual testing you'll be far more likely to procrastinate on testing until you've made huge changes -- that are probably overflowing with bugs.

With continuous integration there's no room for procrastination whatsoever.

As long as you commit regularly, you'll drastically cut down on the bug turnaround time and the chances of something going horribly, mind-bogglingly wrong.

Coding Beauty Assistant logo

Try Coding Beauty AI Assistant for VS Code

Meet the new intelligent assistant: tailored to optimize your work efficiency with lightning-fast code completions, intuitive AI chat + web search, reliable human expert help, and more.

See also