Day 70 / 100 Days of Code: Flow Control Redux

jacobsternx

Jacob Stern

Posted on September 9, 2024

Day 70 / 100 Days of Code: Flow Control Redux

Sun, Sep 8, 2024

Have you ever faced a bug that brought your entire project to a halt? Effective troubleshooting can save not only your project, but entire teams and businesses and is the backbone of successful software development, influencing entire engineering teams and businesses.

On July 19, 2024, a software update by a Windows security vendor caused the largest IT outage in history. This catastrophic event affected over 10,000 airline flights, disrupted public transit systems, hospitals, 911 call centers, and caused global stock markets to plummet.

Layers of Flow Control Troubleshooting
While choosing an effective loop function is crucial, it’s important to consider the tradeoffs, as for or while loops offer more control but can be less readable compared to modern forEach or map methods, which are more concise but might be less flexible for advanced iteration.

Functional Programming for more predictability
Using modern JavaScript iterator methods like map, filter, and reduce can significantly reduce side effects and improve code maintainability by abstracting iteration, especially when used with arrow functions. Currying functions to take one argument at a time not only isolates issues, but also enhances reusability and error handling.

Self-Documenting Code, aka Best Practices for Readability

  • Variable Naming: Instead of naming a variable arr, use groceryList to make its purpose clear.
  • Comments: Keep comments clear and concise, explain the purpose, and detail more complex logic step-by-step
  • Indentation: Follow style guidelines--Codecademy teaches 2 spaces, which usually looks neat.

Logging Techniques
When there are no error messages but values are off, use console.log() to track changes:

console.log(`\n*firstLetter1: ${firstLetter1}, firstLetter2: ${firstLetter2}, \n*string1: ${string1}, string2: ${string2}`);
Enter fullscreen mode Exit fullscreen mode

Keep logs left-aligned to simplify scanning and remember to remove or comment out logs once debugging is complete.

When troubleshooting non-trivial code with ambiguous variable names and runaway comments, I've found the best start is to make a duplicate copy for reference, then apply best practices for readability. This also makes it easy to balance braces, brackets, parentheses, and position semicolons.

When dealing with scope issues, ensure variables are declared at the appropriate scope level, and use let and const instead of var to avoid hoisting issues.

What are your go-to troubleshooting techniques? Share your bug-hunting exploits or favorite troubleshooting habits and let’s learn together! 🚀

Cross posted: Dev https://dev.to/jacobsternx and LinkedIn https://www.linkedin.com/in/jacobsternx

💖 💪 🙅 🚩
jacobsternx
Jacob Stern

Posted on September 9, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related