My days with “dumb code”

Variable Naming Contest

I remember when I first started learning programming, I used all kinds of fancy variable names in order to show my creativity. I used "Xiaohong" and "Xiaoming" to represent the subscripts of the array, and then used "elephant" and "giraffe" to store data. The results of it? Within two days, I couldn't understand what the code was doing. The zoo in code is more complicated than in reality.

Annotation controversy

Okay, I know comments are a good thing, but my "good intentions" once made me write in the comments: "This line of code is very important, please do not delete it." Later I discovered that that line of code was actually not important at all. On the contrary, it is a performance killer. Ever since, the note "Never delete it" has become synonymous with irony.

copy paste war

When I first started learning programming, copying and pasting was like magic to me, and I could get the code running in no time. However, this is also when I write the most bugs. The reason is simple, the copied and pasted code often needs to be adjusted for new scenarios, but I always forget. The result is that when I'm fixing a bug, similar code elsewhere becomes a potential minefield.

The lure of the “magic number”

Oh, this is my old friend. Use some "magic numbers" everywhere in the code, such as "3.14159" to represent pi, or "18" to limit the user's minimum age. Later I discovered that these “magic numbers” were not magical at all, but rather like puzzles that made people confused.

Summary: Silly but valuable

After reading the above story, you may think that I was really "stupid" at the time. But in fact, every failure brings me closer to success. I learned how to write cleaner, more efficient code.

So, if you are also fighting "stupid code" now, don't worry, these are the only way to grow. The most important thing is, keep learning, keep practicing, and one day, you will find that the once "stupid code" has become a valuable experience.

Conclusion: There are no shortcuts on the road of programmers, only a steady stream of Ctrl+C and Ctrl+V. Of course, don’t forget Ctrl+Z, it will be your most loyal friend!

Guess you like

Origin blog.csdn.net/weixin_64123373/article/details/133176675