Article summary
Debugging is one of the most frustrating and painful things a developer will go through. Maybe the debugger isn’t working correctly, or the stack trace is uninformative, or maybe the code base is large and unfamiliar.
Regardless of the specific problem, the goal is always the same: figure out the source of the problem and eliminate it. So what is the magical solution to debug code? There are many hot tips out there, but I wanted to focus on one unique approach that I have learned: emoji 🤯
Why Emoji?
When logging data in your code, the text all looks the same. Using emoji will help aid in making better sense of what those print statements mean. They will also show what areas of the code are being hit in a quick and easy to read way. Emoji also have recognizable colors and symbols which stand out visibly.
How To Use Emoji for Debugging
1. Color-code your functions so you can clearly see what is being called, in what order, and where.
const function1 = () => {
console.log('💟 I am in Area 1');
}
const function2 = () => {
console.log('🅿️ I am in Area 2');
}
const function51 = () => {
console.log('☢️ I am in Area 51');
}
2. Represent variables of interest with different symbols so they can be easily followed through functions.
const someFunction = (args) => {
console.log('➡️ Here I am trying to do a thing.', args);
const newArgs = doSomething(args);
console.log('➡️ Did I do a good job?', newArgs);
}
3. For different edge cases, switch statements, and Boolean expressions, use different emoji styles to screen suspicious areas of the code for the culprit.
console.log('✅ We made it here!');
console.log('🆘 I shouldn't be reaching here');
console.log('⁉️💢 This area of the code is being hit... why????');
Conclusion
Emoji are a powerful way to make the debugging process more efficient through the use of color and symbols. If you are limited to print statements in your debugging, then use these examples to help make the process more efficient and pain-free.
I also encourage you to get creative with your print statements if you are inspired. This can help make debugging less frustrating and more efficient and fun when other resources are not available!