Home  >  Article  >  Backend Development  >  5 Bad Habits You Must Avoid to Become a Good Programmer_PHP Tutorial

5 Bad Habits You Must Avoid to Become a Good Programmer_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:34859browse

When you start to become a programmer, it is easy to fall into some of the bad habits described below when programming.

As a programmer, you will inevitably make mistakes, it is part of your learning to program. You'll make a lot of mistakes during your career - some unique, some common - and through them you can learn how to avoid making the same mistakes in the future.

But if you are a beginner, you may make mistakes more often than others. So how can you avoid these common mistakes that most programmers make every day?

If you want to avoid mistakes, you have to understand them. That’s why I want to share with you some common mistakes that hinder our growth in our career as programmers.

Before we begin, you may be wondering why I know these are errors and not the best approach?

The simple answer is – I’ve been in all of these situations in my career. Some situations are encountered frequently, while others are encountered only a few times. Every time I make a mistake, I regret it.

The worst case scenario is that I have no idea you are doing something wrong. Once I realized I was doing something wrong, I started avoiding those missteps. At least, the code I write now is much better than what I wrote before.

Now you can avoid these mistakes too. The first thing to know is that what you are doing is wrong. I know that most programmers don't do anything wrong because they think it's right, so their actions can have a detrimental effect on the program and the programmer's career growth.

Most bad programming habits stem from ignorance and nothing else.

To become a good programmer, we must get rid of these ignorances one by one. This is what good programming books try to show us.

Part of the reason we make these mistakes is because they actually get the job done. That's not what we do - let our programs run and do our daily work.

But making something work is only part of your job. If you want your app to be useful, you will have to update it regularly to fix any new bugs, which will likely become frequent. One way to make your job easier is to follow good programming practices.

Also, even if you can get away with these errors in a small program, you may encounter them in a large program.

If you still make these mistakes, your program may still run normally and be able to complete the required tasks, but it will become bug-prone, full of inefficient code, and difficult to maintain. And, when you look at its code after a long time, you will find that the code is difficult to understand.

As programmers, our job is not just to make our programs work, but to let users deal with bugs. Our job is to ensure that users don't get unexpected results even if they make a typo.

So to create high-quality applications, make sure you don’t make these common mistakes when programming:

Copy code without understanding

You will often find that the code you need is in some other program. It's tempting to copy an entire section of code and just use it without bothering to understand every line of code.

Sometimes the code you copy may be so big that you don’t have time to fully understand it. If you copy any code like this, you run the risk of making your program brittle and prone to bugs.

This might get the job done, but what if this code produces some unexpected behavior in some situation? What would happen if it slowed down your program or acted maliciously? Therefore, you need to understand the code properly, or you need to be absolutely sure of the source of the code you copied.

If a bug occurs later, you will find it difficult to understand the code because you never wrote it. You may even find it difficult to find a bug and fix it, especially if you copy a lot of code in different places in the program.

So be careful when copying code, even small amounts of code. Make sure you understand it completely. If you have used a piece of code before and can be 100% sure that it works, then it is safe to use. But if not, beware.

Start from scratch every time

This is completely opposite to what I said before, but this is indeed another mistake that beginners often make.

Maybe you think it would be good to start from scratch every time, but in fact it wastes too many resources – time, energy and thinking, which you can better use in other ways.

If what you need already exists, then use them. Don’t repeat the basics over and over again.

You can use this time to make your app better in other ways.

If an API, framework, or game engine makes your task easier, there's no reason why you shouldn't use it. Your goal is not to show how great you are or to prove that you can complete any task on your own. Your goal is to make sure your apps work perfectly and spend as few resources as possible to create them.

If you do this, you can get the same job done in less time. Time is money, and even if you work for yourself, you should try to make more money in the same amount of time.

Start Google without trying it yourself

Many times, out of habit, every time a new problem arises, you will use Google to find the solution. This is not a good idea for a program. If you always search for answers through external methods without trying them yourself, your thinking will never be challenged.

When your mind stops being challenged, your own programming skills will stop growing. Make any skill of yours great and you'll be able to solve problems on your own, and this also applies to program development.

You are creating something that already exists, you are never original. Is this really what you want to do?

Searching for existing solutions may seem smart, but it will blind you and your laziness will prevent you from becoming a good programmer. If you really want to search for a solution, at least initially spend some time thinking about the problem.

Perhaps you can solve it yourself without much incident. Maybe you will solve it better than others. Maybe your solution is more precise than someone else's.

If you don’t try, you’ll never know.

Ignore warning

This is another mistake I made early in my program development. I can't tell you what a big difference it makes when hundreds of alerts appear in your program versus none at all - the most important thing is to ignore them and create new problems.

A warning is usually a sign that what you're making may not work properly every time. Sometimes, ignoring these warnings can cause big security problems. But the real problems usually arise when a program displays hundreds of warnings, or when the program doesn't work properly.

It is difficult to determine what caused the error, and you must spend more time analyzing each warning to find the root cause of the problem. Instead, you can handle the warning when it occurs.

Usually you just need to use the right variables or the right functions to handle these warnings. It won't take you hours, just a few minutes to deal with them when you encounter them.

Handle warnings as early as possible. Clean code looks good and works well. Remember - treat warnings the same as errors .

Quick fixes rather than permanent solutions

Yes, I feel guilty about doing this. I'm not proud of it. But usually, we just make a hasty repair and rarely solve the problem fundamentally.

It works normally and the problem is solved. But if you're not careful, the problem can resurface in a different way.

No matter how you fix a problem, make sure you don't break the entire system. Repairs should improve overall system health, not make it slower or more clunky.

In the meantime, a fix should be made to permanently resolve this issue. Be long-term, not short-term. Sometimes, due to laziness and ignorance, we usually like to solve the problem quickly without spending too much time on it. This is why the code we write works fine, but not in all situations.

If you ignore it while you are working, you will spend more time later.

Knowing the mistakes above can help you avoid them. If you know what you're doing is wrong, you generally won't do it.

In order to do a good job you should love what you do. If for some reason you don't like programming, you will rarely put in the extra effort to write good maintainable programs.

If you plan to write good programs then you should change your view on programming.

You have to view programming as an art and yourself as an artist. Then you won't make mistakes due to laziness and carelessness.

Will a writer publish an unfinished article? Do painters sell unfinished paintings? Will a singer sing useless lyrics in his songs?

Absolutely not.

The same goes for programming. Under no circumstances should you write half-assed code that hasn't been tested. Don't release your program until it's finished. Don't write useless code that you won't use.

These are some common mistakes we make because we like to spend less time at work and do other things. But that won't work. Sooner or later you'll be responsible for making sure your code doesn't break.

The earlier you practice correct programming methods, the better for your users and yourself. Sometimes being a good programmer means you don't make the same mistakes as bad programmers.

Thank you everyone for reading. If you know someone who doesn't know these programming skills, please send them this article so that they can become good programmers.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824627.htmlTechArticleWhen you start to become a programmer, it is easy to fall into some of the bad habits described below when programming. . As a programmer, it is inevitable to make mistakes. This is your lesson in programming...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn