There are many mistakes a new programmer can make. Today, you
will learn the most common mistakes that beginners make, and how you can avoid them.
This is by far the most common mistake beginner programmers make. Name your variables and functions as if your mom was going to have to read and understand what each one means (assuming your mom isn’t a
programmer, of course).
In three months, are you going to remember what the variable you named “
” means, or what that function you creatively named “
Example of poor variable naming:
Example of consistent variable naming:
Comments are an amazing way to remind you what a piece of code does. Too many beginners don’t utilize comments at all, which makes code messy and hard to read. However, there is a fine balance between how many comments you should use in your code.
If you add too many comments, you’ll have to change the comments every time you change the code that it’s describing. It is best to use comments only when a piece of code is not completely self-explanatory.
It doesn’t matter if you put the brackets on the same line as the “
Example of more consistent code formatting:
This is a mistake that could lose you years of your life. Backing up your code is extremely important, even if you are not working on a team. Do not be intimidated by GitHub! They created a great application called GitHub Desktop. GitHub Desktop makes it extremely easy to sync & save your work without even touching the command line. Best of all, it’s free!
Don’t feel pressured to code in a language that you’re intimidated by just because that’s what many others do, and especially don’t code a custom engine. There are multitudes of easy-to-understand languages that are very beginner-friendly. And, once you know one language, it’s very easy to learn any other language.
When you run into a code error that you do not know how to solve, don’t
make the mistake of just diving into the code and reading. Use the debugger. Most IDEs have them. With the debugger, it makes solving
issues a breeze; you can watch your code run line-by-line, so you can see exactly what’s going wrong.
Don’t make functions that take in many inputs, or functions that only accomplish one very specific task. Break up your function into multiple other functions, which are easier to read and maintain.
Example of a function which takes in too many inputs:
Example of a function which takes in an appropriate amount of inputs
Hopefully, these tips have helped you out. Have some tips of your own? Let us know in the comments below!
Happy coding! 🙂
Previously published at https://codeaco.com/2020/June/most-common-coding-mistakes