No matter how skilled a software engineer you are, you will encounter sticky problems that you just can’t seem to fix. Don’t be disheartened — it’s completely normal, especially when you’re starting out. So, take a deep breath, and read through these top tips to get you out of your coding rut.
Make the problem tangible
Ever get that feeling that you just can’t ‘see’ the problem? Your scripts are probably long and complex — so it’s impossible to see them as a whole. A good tip is to make the problem tangible. Create diagrams, mind maps or sketches to help you see the problem differently. Or even jot down some notes about what you are struggling with. Anything that gets the problem out of your head can help.
Get a rubber duck
A tried and tested technique is self-explanation or ‘rubber duck debugging’. The idea is that you explain your code, line by line, to a rubber duck. Forcing yourself to explain the problem to a third party can help to isolate the problem because you will notice any mismatch between your explanation and the code in front of you. And it’s actually better to explain the problem to someone without programming skills – because you will go into detail you otherwise wouldn’t. In lieu of a rubber duck, many have turned to a friendly pet or even a potato.
Take an experimental approach
An experiment will keep as many factors as possible constant while manipulating only the variable of interest. You can easily apply this approach to your programming by making a prediction (or hypothesis, in scientific terms) about what a section of code should do, then run the code to test your prediction. Gradually change one element at a time until you identify a discrepancy between your prediction and the outcome. Eureka — you’ve found your bug.
If you are unsure which elements to change, it can help to build a library of common programming issues. Making a list of these will help to inform your hypotheses (i.e., if I change x variable, then it’s likely I have a logic error).
Invest in version control
Prevention is better than cure. A very common reason for software bugs is when someone else makes changes to a program and unwittingly breaks the code elsewhere. Investing your time in learning and creating a version control system (e.g. Git, HelixCore, Subversion) will save you countless headaches later down the line. Version control systems keep track of and manage changes to software, so that when (not if!) a problem occurs, you can look back at earlier versions of the source code and find out where the problem occurred.
Counterintuitively, the best way to solve a difficult issue might be to simply… stop. Think about your brain like a computer running a piece of code. Sometimes there’s nothing you can do except let the code run — allowing your subconscious to continue working on the problem in your absence. However, you need to give the computer enough data to begin with, and then not overload it once it’s trying to work — so work the problem until you’ve truly hit a wall, then take a break that gives you space to think. For example, taking a walk is an evidence-backed method for boosting creativity and problem-solving abilities.
Finally, don’t be afraid to seek help. It’s highly likely someone has encountered a similar problem before, so identifying keywords and searching through forums is a great starting point. Stack Overflow is a huge online platform where you can post your problem — the active community is always happy to help. And finally, approach your senior colleagues for advice. It’s important to get as far as possible before doing this (as this will help you develop your programming skills and present the problem as clearly as possible), but these people have been in your position before, and most will be happy to help.
Hopefully, these tips have armed you with a number of new techniques to try. Remember, there’s no one-size-fits-all strategy — finding what works best for you takes time and patience — but once you have identified it, you will be able to tackle all manner of coding problems that come your way.