5 Mistakes Beginner Programmers Make

Karen Shao
4 min readMay 8, 2021
Photo by bruce mars on Unsplash

Are you in the middle of trying to learn Java, C++, Python, or some other programming language, but finding yourself struggling to understand the logic behind it? Are you writing functional code that you can’t explain to anyone else? Here are 5 indicators that you may need to reevaluate your approach to programming.

1. You don’t try to visualize data structures.

In the beginning, when learning about simple variables and linear data structures, everything is pretty straightforward and there is nothing to draw out. However, when working with more complex data structures such as trees or graphs, it can be hard to know where everything is. Making a diagram of the data structure not only makes it easier to visualize, but also makes it faster to read through the existing code and determine what outputs to expect.

2. You jump right into the code without planning at all.

When writing a straightforward function, it can be easy to skip the planning process and immediately start writing out the solution. While this might work for smaller programs, it can get extremely messy with larger projects. Before writing anything at all, try to make notes of the purpose of the function, how it fits into the rest of the code, and of course make sure that the logic makes sense.

3. Too much of your code is just “hard-coding” rather than making use of more variables.

Let’s say you’re asked to write a function that renders a snowman made of 3 circles, with each circle having a radius 3/2 the size of the circle above it. You could “brute force” the code in a way where you do all the calculations yourself, and have it draw each of the circles from top down with radius 8, 12, 18. This works, but only for one snowman with very specific dimensions. It would be better to define a variable for the radius and another for the multiplier of the next snowball size. This way, the function works for a multiple different cases by operating on an initial radius and multiplier given by a user input.

4. You don’t run through your code step-by-step when debugging and checking to see if it works.

When debugging, it can be easy to just look at the types of errors and trying to fix them right away without thinking about it, but this only really works for simple syntax errors such as missing brackets or incorrect spelling. If your code isn’t returning the expected values, the best thing to do is pinpoint what function might be causing the issue, and then running through it one step at a time. For example, you’ve made a function that returns the shortest possible route from point A to B. If the output of the function is anything other than the expected answer, try manually following the code and seeing what happens (what variables change, what path it takes through if statements, etc.) at each step of the way when running it with those specific values of A and B.

5. There aren’t enough tests to check your code against.

Many beginners think that just writing a function that runs properly is the only thing they need to do, but that’s not true at all. After all, how do you know everything is working as planned without writing tests? Let’s say you want to write a function that produces the number of all positive even numbers in a list. It is important to check for different cases that could cause errors as well as making sure that valid inputs produce the expected result by writing multiple different tests. For example, you might want to write a test for what happens if the list is empty, if the input type is incorrect (what if it’s a list of strings?), if the list is a mix of positive and negative numbers, if it has only odds or negatives, and maybe a few others. This seems excessive, but with more complex functions it is important to test as many different scenarios as possible to make sure it works properly. In the case of this particular function, writing enough tests might lead you to realize, “Oh, my function counts 0 as a positive number”. This is called an edge case, and it is one of the most important things to test for as it is what often causes unexpected results in the function.

--

--

Karen Shao

Computer Science Student at the University of British Columbia (also studying music on my own)