Common Programming Mistakes and the Lessons They Teach
This article reviews a series of typical programming blunders—such as incorrect local file includes, misuse of obscure characters, over‑reliance on long if‑else chains, meaningless variable names, hard‑coded outputs, thread‑sleep misuse, and missing return statements—highlighting the practical lessons each mistake provides for developers.
As programmers we all start as beginners and inevitably make mistakes; reflecting on these errors helps us grow.
Local file include error: Using include "d:\xxxxxxxxxxx.h" caused runtime failures when the code was shared, illustrating the importance of portable file paths.
Obscure character usage: A rare Chinese character "丨" was used as a string separator, confusing collaborators and leading to debugging headaches.
"If‑else" explosion: Writing dozens of nested if‑else statements reduces performance and readability; the article advises switching to a table‑driven (lookup) approach.
Meaningless variable names: Declaring many variables like int x,y,z,w,v,u,l,m,n,o,p,q,r,s,a1,b1; makes the code incomprehensible even to its author after a short time.
Hard‑coded output: Instead of calculating results, some developers directly output fixed values, which can lead to security issues when used for passwords or other sensitive data.
Thread waiting misuse: Using QThread::sleep(1000) actually sleeps for 1000 seconds, demonstrating the need to understand API units (seconds vs. milliseconds).
Missing return statement: Forgetting to return a value from a function caused unexpected null results in the calling code, a reminder to always include proper returns.
The article concludes that acknowledging and learning from these “stupid” mistakes fosters humility, continuous learning, and better coding practices.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.