your code should be clear and easy to maintain. Right here are several other programming principles to help you clean up your act.




You are watching: Which of the following is not a principle of good programming style?

good-programmer
It"s basic to create code. It"s daunting to write good code.

negative code come in numerous forms. Confusing code, enormous if-else chains, programs that break with one adjustment, variables that don"t do sense. The program could work once however will never organize up to any kind of scrutiny.

If you desire to it is in a programmer, don"t resolve for shortcuts. Aim to create code the is simple to maintain. Straightforward for you come maintain, and easy for any other developer on her team to maintain. How do friend write reliable code? you write great code by being disciplined with programming principles.

below are 10 programming ethics that will certainly make friend a much better coder.


1. Store It Simple, Stupid (KISS)

It sounds a small harsh, but it"s a coding principle to live by. What walk this mean?

It way you must be writing code as simple as possible. Don"t get recorded up in trying come be too many clever or reflecting off v a paragraph of progressed code. If you deserve to write a script in one line, create it in one line.


Here"s a simple function:

function addNumbers(num1,num2) return num1 + num2; pretty simple. It"s simple to read and you know precisely what is going on.

use clear change names. Take advantage of coding libraries to use existing tools. Make it straightforward to come ago after six months and also get right ago to work. Keeping it simple will conserve you the headache.


2. Create DRY Code

The Don"t Repeat you yourself (DRY) rule means, plainly, not repeating code. It"s a typical coding mistake. When writing code, avoid duplication that data or logic. If you"ve ever before copied and also pasted password within your program, it"s not DRY code.

take it a look in ~ 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, shot to uncover an algorithm that offers iteration. For loops, and while loops are means to manage code that requirements to operation multiple times.


DRY password is basic to maintain. It"s much easier to debug one loop the handles 50 repetitions 보다 50 blocks of code that manage one repetition.


3. Open/Closed

This principle method you must aim come make her code open up to extension but closed come modification. This is an important principle once releasing a library or framework that others will use.

because that example, expect you"re maintaining a GUI framework. You can release because that coders to directly modify and integrate her released code. However what happens once you relax a significant update 4 months later?

your code will certainly break. This will make designers unhappy. They won"t desire to use your library for lot longer, no issue how advantageous it might be.

Instead, release code that stays clear of direct change and encourages extension. This the end core behavior from modified behavior. The code is more stable and also easier come maintain.


4. Composition end Inheritance

If you create code using object-oriented programming you"re going to find this useful. The composition end inheritance principle states: objects with complex behaviors must contain instances of objects v individual behaviors. They should not inherit a class and add new behaviors.

Relying on inheritance causes two significant issues. First, the inheritance hierarchy can gain messy in a hurry. You also have less flexibility for defining special-case behaviors. Let"s speak you want to implement behaviors to share:


Object oriented programming principles
ingredient programming is a many cleaner come write, much easier to maintain and enables flexibility defining behaviors. Each individual behavior is its own class. You have the right to create complex behaviors by combining individual behaviors.


5. Single Responsibility

The single responsibility principle claims that every class or module in a program need to only administer one certain functionality. Together Robert C. Martin put it, "A class should have only one reason to change."

Classes and modules often start turn off this way. Be careful not to include too countless responsibilities together classes get more complicated. Refactor and also break castle up right into smaller classes and also modules.

The consequence of overloading great is twofold. First, that complicates debugging as soon as you"re make the efforts to isolate a particular module for troubleshooting. Second, it i do not care more challenging to create additional functionality for a details module.


6. Separation of Concerns

The separation of involves principle is one abstract variation of the solitary responsibility principle. This idea states that a program should be designed with various containers, and also these containers should not have access to each other.


A well-known instance of this is the model-view-controller (MVC) design. MVC off a program right into three unique areas: the data (model), the reasonable (controller), and also what the page displays (view). Variations of MVC are usual in today"s most well-known web frameworks.

because that example, the code that handle the database doesn"t need to know just how to render the data in the browser. The rendering password takes input indigenous the user, yet the logic code handles the processing. Each piece of password is fully independent.

The result is password that is straightforward to debug. If you ever need come rewrite the calculation code, you deserve to do so there is no worrying around how the data gets conserved or the logic gets processed.


7. You Aren"t walking to need It (YAGNI)

This principle means you must never code for use on the chance that you may need in the future. Don"t shot and deal with a difficulty that doesn"t exist.


In an initiative to write DRY code, programmers have the right to violate this principle. Regularly inexperienced programmers try to write the many abstract and generic code they can. Too lot abstraction reasons bloated code that is impossible to maintain.

Only apply the dried principle only when you require to. If you an alert chunks of code created over and also over, then summary them. Don"t think too far out at the price of your current code batch.


8. Document Your Code

Any senior developer will stress and anxiety the prominence of documenting your password with suitable comments. All languages market them and you need to make it a habit to write them. Leaving comments to explain objects, enhance variable definitions, and also make functions less complicated to understand.

Here"s a JavaScript role with comment guiding you with the code:


//This function will include 5 to the entry if odd, or return the number if evenfunction evenOrOdd(number) //Determine if the number is also if(number % 2 == 0) return number; //If the number is odd, this will include 5 and also return else return number + 5; Leaving comment is a little much more work while you"re coding, and you understand your password pretty fine right?

leaving comments anyway!

shot writing a program, leaving the alone for 6 months, and also come earlier to change it. You"ll it is in glad you documented your program instead of having to pour over every role to remember just how it works. Work on a coding team? Don"t frustrate your other developers through forcing them to decipher your syntax.


Code for coding principles
It"s difficult to accept, but your code isn"t walk to be perfect the an initial time. Refactoring code way reviewing her code and looking for ways to optimize it. Make it more efficient while maintaining the results specifically the same.


Codebases room constantly evolving. It"s fully normal come revisit, rewrite, or also redesign entire chunks the code. The doesn"t typical you didn"t success the first time you composed your program. You"re going come get an ext familiar through a task over time. Usage that understanding to change your existing password to be DRY, or complying with the KISS principle.


10. Clean code At all Costs

Leave her ego at the door and also forget around writing clever code. The sort of password that looks more like a riddle 보다 a solution. You"re no coding to impress strangers.

Don"t try to load a ton that logic right into one line. Leaving clear instructions in comments and also documentation. If your password is basic to read it will be simple to maintain.

an excellent programmers and also readable code go hand-in-hand. Leave comments as soon as necessary. Adhere to format guides, even if it is dictated by a language or your company.


What provides a good Programmer?

Learning just how to it is in a an excellent programmer takes rather a bit of work! these 10 coding values are a roadmap to ending up being a professional programmer. You should additionally learn about why polymorphism is precious learning.

A an excellent programmer understands exactly how to make their apps basic to use, works well in ~ a team, and finishes jobs to specification and also on time. By complying with these values you will set yourself up because that success in your programming career. Try out this 10 beginner programming projects and review her code. Check out if you"re sticking to this principles. If not, challenge yourself to boost your code.


network hacker
What Is huge Data Analytics and How walk It assist Prevent Cybersecurity Threats? large data analytics bring you the info that you have to keep your devices safe and also secure.




See more: Billy Bob Varsity Blues Truck, How Much Did Billy Bob Weigh In Varsity Blues

Anthony give is a freelance writer extending Programming and Software. He"s a computer Science significant dabbling in programming, Excel, software, and also technology.


subscribe to our newsletter

Join our news for tech tips, reviews, complimentary ebooks, and exclusive deals!