Beginner Programmers’ Mistakes

Beginner Programmers' Mistakes

Beginner Programmers’ Mistakes

If you are not in programming and you will be pointing this a mistake made by a programmer then be ready to see a sarcastic angry young man look of a programmer throwing a paper or stone at yourself. Programming is one of the funniest (We have already given example), hardest (If you don’t enjoy coding) and easiest (If you love to play with code) thing to do in the world. A semicolon, a bracket, a loop and a lot of small and big things matter a lot in coding and you might have definitely experienced your silly mistakes especially in the initial phase-in programming. Here are the Beginner Programmers’ Mistakes that You Should Avoid

Mistakes are part of coding and every programmer makes tonnes of mistakes especially as a beginner but that’s how they grow and become a good developer. We are going to discuss some most common mistakes that programmers make during the initial phase of coding but these are not limited. It’s good to be aware of these mistakes and not to do the same while learning to code

1. Writing Code Without Planning

High-quality content cannot be created easily. It requires careful thinking and research. High-quality programs are no exception.

Writing quality programs is a process with a flow:
Think. Research. Plan. Write. Validate. Modify.
Unfortunately, there is no good acronym for this. You need to create a habit to always go through the right amount of these activities.

One of the biggest mistakes beginner programmers make is to start writing code right away without much thinking and researching. While this might work for a small stand-alone application, it has a big, negative effect on larger applications.

Just like you need to think before saying anything you might regret, you need to think before you code anything you might regret. Coding is also a way to communicate your thoughts.

When angry, count to 10 before you speak. If very angry, a hundred.

— Thomas Jefferson

Jefferson’s advice applies to coding as well:

When reviewing code, count to 10 before you refactor a line. If the code does not have tests, a hundred.

— Samer Buna

Programming is mostly about reading previous code, researching what is needed and how it fits with the current system, and planning the writing of features with small, testable increments. The actual writing of lines of code is probably only 10% of the whole process.

Do not think about programming as writing lines of code. Programming is a logic-based creativity that needs nurturing.

2. Planning Too Much Before Writing Code

Yes. Planning before jumping into code is a good thing, but even good things can hurt you when you do too much of them. Too much healthy water might poison you.

Do not look for a perfect plan. That does not exist in the world of programming. Look for a good-enough plan, something that you can use to get started. The truth is, your plan will change, but what it was good for is to force you into some structure that leads to more clarity in your code. Too much planning is simply a waste of your time.

I am only talking about planning small features. Planning all the features at once should simply be outlawed! It is what we call the Waterfall Approach, which is a system linear plan with distinct steps that are to be finished one by one. You can imagine how much planning that approach needs. This is not the kind of planning I am talking about here. The waterfall approach does not work. Anything complicated can only be implemented with agile adaptations to reality.

Writing programs has to be a responsive activity. You will add features you would never have thought of in a waterfall plan. You will remove features because of reasons you would never have considered in a waterfall plan. You need to fix bugs and adapt to changes. You need to be agile.

However, always plan your next few features. Do that very carefully because too little planning and too much planning can both hurt the quality of your code. The quality of your code is not something you can risk.

3. Underestimating the Importance of Code Quality

If you can only focus on one aspect of the code that you write, it should be its readability. Unclear code is trash. It is not even recyclable.

Never underestimate the importance of code quality. Look at coding as a way to communicate implementations. Your main job as a coder is to clearly communicate the implementations of any solutions that you are working on.

One of my favorite quotes about programming is:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

— John Woods

Brilliant advice, John!

Even the small things matter. For example, if you are not consistent with your indentation and capitalization, you should simply lose your license to code.

tHIS is
  WAY MORE important
            you think

Another simple thing is the use of long lines. Anything beyond 80 characters is much harder to read. You might be tempted to place some long conditions on the same line to keep an if-statement block more visible. Do not do that. Just never go beyond the 80 character limit, ever.

Many of simple problems like these can be easily fixed with linting and formatting tools. In JavaScript, we have two excellent tools that work perfectly together: ESLint and Prettier. Do yourself a favor and always use them.

Here are a few more mistakes related to code quality:

  • Using many lines in a function or a file. You should always break long code into smaller chunks that can be tested and managed separately.

    Any function that has more than 10 lines is just too long.

  • Using double negatives. Please do not not do that.

    Using double negatives is just very not not wrong.

  • Using short, generic, or type-based variable names. Give your variables descriptive and non-ambiguous names.

    There are only two hard things in Computer Science: cache invalidation and naming things.

    — Phil Karlton
  • Hard-coding primitive strings and numbers without descriptions. If you want to write logic that depends on a primitive string or number, put that value in a constant and give it a good name.
    const answerToLifeTheUniverseAndEverething = 42;
  • Using sloppy shortcuts and workarounds to avoid spending more time around simple problems. Do not dance around problems. Face your realities.
  • Thinking that a longer code is better. A shorter code is better in most cases. Only write longer versions if they make the code more readable. For example, do not use clever one-liners and nested ternary expressions just to keep the code shorter, but also do not intentionally make the code longer when it does not need to be. Deleting unnecessary code is the best thing you can do in any program.

    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

    — Bill Gates
  • The excessive use of conditional logic. Most of what you think needs conditional logic can be accomplished without it. Consider all the alternatives and pick exclusively based on readability. Do not optimize for performance unless you can measure. Related: avoid yoda conditions and assignments within conditionals.

4. Picking the First Solution

This is a subtle sign of a true newbie. They get presented with a problem, they find a solution, and just run with it. They rush the implementation right away before thinking about the complexities and potential failures of the identified solution.

While the first solution might be tempting, good solutions are usually discovered once you start questioning all the solutions that you find. If you cannot think of multiple solutions to a problem, that is probably a sign that you do not completely understand the problem.

Your job as a professional programmer is not to find a solution to the problem. It is to find the simplest solution to the problem. By “simple” I mean the solution has to work correctly and perform adequately but still be simple enough to read, understand, and maintain.

There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.

— C.A.R. Hoare

5. Not Quitting

Another mistake newbies make is sticking with the first solution even after they identify that it might not be the best approach. This is probably psychologically related to the “not-quitting” mentality. This is a good mentality to have in most activities, but it should not apply to programming. In fact, when it comes to writing programs, the right mentality is to fail early and fail often.

The minute you begin doubting a solution, you should consider throwing it away and re-thinking the problem. This is true no matter how much you were invested in that solution. Source control tools like GIT can help you branch off and experiment with many different solutions. Leverage that. Do not be attached to code because of how much effort you put into it. Bad code needs to be discarded.

6. Not Googling

There has been many instances where I wasted precious time trying to solve a problem when I should have just researched it.

Unless you are using a bleeding-edge technology, when you run into a problem, chances are someone else ran into the same problem and found a solution for it. Save yourself some time and Google It First.

Sometimes, Googling will reveal that what you think is a problem is really not, and what you need to do is not fix it but rather embrace it. Do not assume that you know everything needed to pick a solution to a problem. Google will surprise you.

However, another sign of a newbie is copying and using code as is without understanding it. While that code might correctly solve your problem, you should never use any line of code that you do not fully understand. If you want to be a creative coder, never think that you know what you’re doing.

The most dangerous thought that you can have as a creative person is to think that you know what you’re doing.

— Bret Victor

7. Not Using Encapsulation

This point is not about using the object-oriented paradigm. The use of the encapsulation concept is always useful. Not using encapsulation often leads to harder-to-maintain systems.

A feature should have only one place in the code that handles it. That is usually the responsibility of a single object. That object should only reveal what is absolutely necessary for other objects of the application to use it. This is not about secrecy but rather about the concept of reducing dependencies between different parts of an application. Sticking with these rules allows you to safely make changes in the internals of your classes, objects, and functions without worrying about breaking things in a bigger scale.

Conceptual units of logic and state should get their own classes. By class, I mean a blueprint template. This can be an actual Class object or a Function object. You might also identify it as a Module or a Package.

Within a class of logic, self-contained pieces of tasks should get their own methods. Methods should do one thing and do that thing well. Similar classes should use the same method names.

Newbies usually do not have the instinct to start a new class for a conceptual unit and they cannot identify what can be self-contained. If you see a Util class that has been used as a dumping ground for many things that do not belong together, that is a sign of newbie code. If you make a simple change and then discover that the change has a cascading effect and you need to do many changes elsewhere, that is another sign of newbie code.

Before adding a method to a class or adding more responsibilities to a method, think and question your instincts. You need time here. Do not skip or think that you will refactor that later. Just do it right the first time.

The big idea here is that you want your code to have High Cohesion and Low Coupling, which is just a fancy term that means keep related code together (in a class) and reduce the dependencies between different classes.

8. Planning for the Unknown

It is often tempting to think beyond the solution that you are writing. All sorts of what-ifs will pop into your head with every line of code that you write. This is a good thing for testing edge cases, but it just wrong to use as a driver for potential needs.

You need to identify which of these two main categories your what-ifs belong to. Do not write code that you do not need today. Do not plan for the unknown future.

Writing a feature because you think that you might need it in the future is simply wrong. Do not do it.

Always write the minimum amount of code that you need today for the solution that you are implementing. Handle edge-cases, sure, but do not add edge-features.

Growth for the sake of growth is the ideology of the cancer cell.

— Edward Abbey

9. Not Using the Right Data Structures

When preparing for interviews, beginner programmers usually put too much focus on algorithms. It is good to identify good algorithms and use them when needed, but memorizing them will probably never attribute to your programming genius.

However, memorizing the strengths and weaknesses of the various data structures that you can use in your language will make you a better developer.

Using the wrong data structure is a big and strongly-lit billboard sign that screams newbie code here.

This is not a book to teach you about data structures but let me mention a couple of quick examples:

Example: Using lists (arrays) instead of maps (objects)

The most common data structure mistake is probably the use of lists instead of maps to manage a list of records. Yes, to manage a LIST of records you should use a MAP.

In JavaScript, for example, the most common list structure is an array and the most common map structure is an object (there is also a map structure in modern JavaScript).

Using lists over maps is often wrong. While this point is really only true for large collections, I would say just stick with it all the time. There are few specific cases where lists might be a better option than maps and these cases are vanishing in modern languages. Just use maps.

The main reason this is important is because accessing elements in maps is a lot faster than accessing elements in lists. Accessing elements is something that you will be doing often.

Lists used to be important because they guarantee the order of elements. However, modern map structures can do that too.

Example: Not Using Stacks

When writing any code that requires some form of recursion, it is a lot easier to just use the concept of recursion. However, it is usually hard to optimize recursive code, especially in single-threaded environments.

Optimizing recursive code also depends on what recursive functions return. For example, optimizing a recursive function that returns two or more calls to itself is a lot harder than optimizing a recursive function that simply returns a single call to itself.

What beginners often forget is that there is an alternative to recursion. You can just use a Stack structure. Push function calls to a Stack yourself and start popping them out when you are ready to traverse the calls back.

10. Learning Too Many Programming Languages, Frameworks, and Technology

This is one of the common mistakes that most the beginners make when they start learning to code. They think that it’s impressive to have Java, C++, Python and a lot of more language, frameworks or technology to showcase to someone or to mention in the resume but that’s actually foolishness not the sign of intelligence if you don’t have command or in-depth knowledge in any one of them.
Learning Java for 15 days and switching to Ruby just because java is tough or there is another reason then you will eventually end up with lots of confusion. It’s good to have knowledge of multiple languages but we highly recommend you to focus on a single language, in the beginning. Once you are experienced you won’t face difficulty in switching to another language. If you do this mistake then after a couple of years you will realize you aren’t master in any single language.

If You are interested to join our Team, you can submit your cv here

Rate this post


Chat Us