DEV Community

Cover image for 6 Programming Principles You Should Know
Kelvin.eth
Kelvin.eth

Posted on

6 Programming Principles You Should Know

It's always easy for a programmer to write codes, but it becomes a difficult task to write clean, well structured and easy to read codes. Writing a clean code is a task every programmer should practice.
In this article I will give you a comprehensive overview of programming principles to make you a better programmer.

DRY (Don’t Repeat Yourself)

The DRY principle suggests that we refactor our multiple pieces of code that does the same function into a single and simple reusable function, that can be called or used throughout the project. This practice enables us to reduce the amount of code in the project and also makes it easier to read, maintain and modify in the future.

In addition to reducing code complexity, the DRY principles also encourages programmers to avoid duplication of codes and data in projects, which reduces bugs and errors in your project when followed.

In general, The DRY principles promote code efficiency, readability and maintainability.

SOC(Separation Of Concern)

The SOC principle requires you to break down your programs into sections and modules which have a clearly defined purpose or concern. It suggests that your program should be divided into smaller and manageable parts that are focused on a specific aspect of the project’s functionality.

The Separating concern allows changes made to one part of the program to have minimal impact on other parts. This makes it easier to maintain or modify each individual part of the program without affecting the entire program, thereby leading to less errors or bugs in the program.

Adhering to the SOC principles helps to improve code quality and makes code easier to maintain, modify and reduce chances of errors or bugs.

YAGNI (You Are Not Going to Need It)

This principle emphasizes on keeping your programs simple and avoiding complex features in software development.

This is to ensure time management and efforts on features of a program that are unlikely to be used, and to focus on features that meet the immediate requirement of your project.

By following this principle, you can keep your codebase simple and maintainable and also help reduce the risk of bugs and errors.

DYC (Document Your Code)

DYC emphasizes the importance of documenting your codes. This principle makes your code more readable, understandable and maintainable, for you and any other programmer who may need to use your code in the future.

Documenting your code as a programmer is a good practice but writing good documentation is a more concise and advisable practice as a programmer.

Good documentation can help other programmers understand the purpose, structure and other relevant dependencies in your code, which is essential for debugging and modifying or updating the code.

Documentation Can be written in different form;

  • Comments with codes
  • README files
  • User guides

Adhering to the DYC principles, can help to improve the quality and maintainability of your code and also makes it easier for other programmers to work with your codes.

SLAP (Single Level Of Abstraction)

The slap principle proposes that code should have a single level of abstraction. That is, a block of code should not mix what the code does and how it works. As SLAP promotes code clarity, maintainability, and reusability, functions and modules are focused on completing one task at a time.

The code is easier to read, understand, and modify when it is at the same level of abstraction, since it is modular, and each piece can be understood independently.

Thus, code in a function or module should be at the same abstraction level and should not mix lower-level implementation details with higher-level business logic.

KISS ( Keep It Simple Stupid)

KISS (Keep It Simple, Stupid) is a principle which advocates keeping systems, software, or any solution as simple as possible.

The purpose of this principle is to avoid unnecessary complexity and to focus on the most essential features or components of a project.

In General, KISS provides developers with a useful guideline for creating software that is easy to understand, maintain, and use, as well as that delivers a good user experience.

Conclusion

In this article you have learnt about the 6 programming principles you should know and apply to become a better programmer and also to practice well, structured and easy to read codes.
Thanks for reading.

Top comments (1)

Collapse
 
codecat1024 profile image
CodeCat1024

Great article!