The code is easy to write. It is a challenge to write good code.
The wrong code comes in many forms. Messy code, massive strings if not, programs that break with a fit, variables that don’t make sense. The program can run once, but will never be subject to scrutiny.
Don’t settle for shortcuts. Aim to write code that is easy to maintain. Easy to maintain and easy to maintain for any other developer on your team. How do you write an effective code? You write good code by being disciplined with programming principles.
Here are 10 programming principles that will make you a better encoder.
1. Keep it simple, stupid (KISS)
It sounds a bit harsh, but it is a coding principle for living. What does this mean?
It means you should write code as simple as possible. Don’t get caught up in trying to be too smart or showing off with an advanced code paragraph. If you can write a script on one line, write it on one line.
Here is a simple function:
function addNumbers(num1,num2){
return num1 + num2;
}
Pretty simple. It is easy to read and you know exactly what is happening.
Use clear variable names. Take advantage of coding libraries to use existing tools. Make it easy to return after six months and return to work. Keeping it simple will save you the headache.
2. Write DRY code
Don’t repeat yourself (DRY) principle clearly means not repeating code. It is a common coding error. When writing code, avoid duplication of data or logic. If you have ever copied and pasted code into your program, it is not DRY code.
Take a look at this script:
function addNumberSequence(number){
number = number + 1;
number = number + 2;
number = number + 3;
number = number + 4;
number = number + 5;
return number;
}
Instead of duplicating lines, try to find an algorithm that uses iteration. For and while loops are ways to control code that must be run multiple times.
DRY code is easy to maintain. It is easier to debug a loop that handles 50 repetitions than 50 code blocks that handle one repetition.
3. Open / Closed
This principle means that you should try to make your code open to extension but closed to modification. This is an important principle when launching a library or framework that others will use.
For example, suppose you maintain a GUI framework. You can free encoders to directly modify and integrate your published code. But what happens when you release a major update four months later?
Your code will be broken. This will make the engineers unhappy. They won’t want to use their library for much longer, no matter how useful it may be.
Instead, postcode that prevents direct modification and encourages extension. This separates core behavior from modified behavior. The code is more stable and easier to maintain.
4. Composition on inheritance
If you write code using object-oriented programming you’re going to find this useful those composition on inheritance Main principles: Objects with complex behaviors must contain instances of objects with individual behaviors. They should not inherit a class and add new behaviors.
Relying on inheritance causes two main problems. First, the inheritance hierarchy can quickly become messy. It also has less flexibility to define special case behaviors. Suppose you want to implement sharing behaviors:
Composition programming is much cleaner to write, easier to maintain, and allows flexibility in defining behaviors. Each individual behavior is its own class. You can create complex behaviors by combining individual behaviors.
5. Individual responsibility
the sole responsibility principle says that each class or module in a program should only provide specific functionality. As Robert C. Martin says, “A class should have only one reason to change.”
Classes and modules often start this way. Be careful not to add too many responsibilities as the classes get more complicated. Refactor and break them into smaller classes and modules.
The consequence of overloading the classes is twofold. First, it complicates debugging when you try to isolate a certain module for troubleshooting. Secondly, it becomes more difficult to create additional functionalities for a specific module.
6. Separation of concerns
the principle of separation of concerns is an abstract version of the principle of sole responsibility. This idea states that a program must be designed with different containers, and these containers must not have access to each other.
A well-known example of this is the model-view-controller (MVC) design. MVC separates a program into three distinct areas: the data (model), the logic (controller), and what the page displays (view). MVC variations are common in today’s most popular web frameworks.
For example, the code that handles the database does not need to know how to represent the data in the browser. The rendering code receives information from the user, but the logical code handles the processing. Each piece of code is completely independent.
The result is easy-to-debug code. If you ever need to rewrite the rendering code, you can do it without worrying about how the data is saved or the logic is processed.
7. You won’t need it (YAGNI)
Is The principle means that you should never encode the functionality in case you might need it in the future? Don’t try to solve a problem that doesn’t exist.
In an effort to write DRY code, programmers may violate this principle. Often inexperienced programmers try to write the most abstract and generic code they can. Too much abstraction causes bloated code that is impossible to maintain.
Only apply the DRY principle only when you need it. If you look at pieces of code written over and over, summarize them. Don’t think too much at the expense of your current batch of code.
8. Document your code
Any senior developer will emphasize the importance of documenting your code with appropriate comments. All languages offer them and you should get used to writing them. Leave comments to explain objects, improve variable definitions, and make functions easier to understand.
Here is a JavaScript function with comments that guide you through the code:
//This function will add 5 to the input if odd, or return the number if even
function evenOrOdd(number){
//Determine if the number is even
if(number % 2 == 0){
return number;
}
//If the number is odd, this will add 5 and return
else {
return number + 5;
}
}
Leaving comments is a little more work while you’re coding, and you understand your code pretty well, right?
Leave feedback anyway!
Try writing a program, leaving it alone for six months, and modify it again. You’ll be glad you’ve documented your program instead of having to go through all the features to remember how it works. Work on a coding team? Don’t frustrate your fellow developers by forcing them to decipher your syntax.
9. Refactor

It is difficult to accept, but your code will not be perfect the first time. Refactoring the code means reviewing your code and looking for ways to optimize it. Make it more efficient while keeping the results exactly the same.
Code bases are constantly evolving. It’s completely normal to revisit, rewrite, or even redesign entire chunks of code. It does not mean that you did not succeed the first time you wrote your program. Over time, you will become more familiar with a project. Use that knowledge to adjust your existing code to be DRY, or follow the KISS principle.
10. Clean code at all costs
Leave your ego at the door and forget about writing smart code. The type of code that looks more like a riddle than a solution. You are not coding to impress strangers.
Don’t try to package a ton of logic on a single line. Leave clear instructions in comments and documentation. If your code is easy to read, it will be easy to maintain.
Good programmers and readable code go hand in hand. Leave comments when necessary. Adhere to the style guides, whether dictated by a language or your company.
What makes a good programmer?
Learning to be a good programmer takes a lot of work! These 10 coding principles are a roadmap to becoming a professional programmer.
A good programmer understands how to make their applications easy to use, works well within a team, and completes projects to specifications and on time. By following these principles, you will prepare yourself for success in your programming career. Try these 10 programming projects for beginners.

She is a freelance blogger, writer, and speaker, and writes for various entertainment magazines.

