What are the principles of programming?
Building and developing software is a multi-step process, starting from writing code, writing tests, then fixing bugs, and then maintaining… this process is iterative. And how to make that process better, better from the beginning of coding, people start thinking about the principles of programming, and hopefully when people follow suit, things will improve. benevolent.
So after having the principles of programming, has your programming become better? This is for you to answer yourself.
How many programming principles are there in all?
When starting to learn about programming principles, a world opens up, and then it makes you want to stop learning many times. Too many reasons. Too much advice. So much pressure that we have to do this, have to do that.
There are very few people who don’t use google tools who can remember all those principles.
Why is it so difficult to follow the rules?
It is easy for us to create rules for others, but not for ourselves. And people tend to break the rules. Following the principles requires proper understanding, maintaining and establishing habits, and of course it’s hard to even think about.
Create your own rules
The principle of coding so that it is simple
When coding always think about making it as simple as possible. Simple code has the following benefits:
+ Team members can follow easily.
+ It is easy for new people to accept later on
+ We ourselves later re-read to improve, maintain is also easy.
+ Especially, when they are simple, the failure would easily fix.
It’s easy to say, but the computer program itself is a very complex thing, for us today to make coding simple and easy is a process of many years of improvement, and the advancement of methods. new law was born. Imagine, this old web code with complex Frameworks, now with Laravel, Reactjs makes coding PHP or Javascript much easier. The most complicated parts were hidden inside.
So how to make code simple, which is difficult to explain and write down in words, but what we can do is avoid the one thing that leads to complicated code like this:
+ Let’s divide the large function into many smaller functions.
+ Don’t write algorithms, something like optimize this and that, save this and that, and then make the code confusing.
Code principles to be neat and clean
No matter what situation you are in, you like neat and clean people, neat and clean places, no one likes cluttered code and headaches. So how can you code neat and clean:
+ Create yourself a set of principles
+ Let’s start by naming variables neatly, easy to understand
+ Design functions with easy-to-read, easy-to-understand names
+ Let’s make functions have clear input and output
+ Inside functions restrict if/else/for too deep
And be patient to thoroughly follow the principles you give, remember that it is not easy to make everything neat and clean, it has to go through many times of improvement, experience, review. you have just established yourself a set of skills necessary to maintain those habits..
The principle of coding so that it can be easily reused
If you don’t reuse the same code over and over again, every time you fix or change it, you easily create bugs, because forgetting here and there, and all the code reading is difficult to understand.
Reusing code is also very difficult, because at first you just try to write it to work, not write code for tomorrow, for others to use, worrying about tomorrow is a very fiction thing. Structural and fiction.
But writing code that’s reusable, gives you problem-thinking skills, is in your favor, when you think about it, you’re isolating your problems to help you see out better problems.
Principle of code separation by independent class/module/packagepackage
+ Each class should only do one thing, so separate the program into many different classes.
+ Each module/package should also only do work belonging to its domain.
+ Inside each class/module/package hide implementations that don’t need to be made public.
Also, today, the language have all the package management as Composer of PHP, npm of Nodejs, Go there Go Module etc … It helps to not only code, but also the organization for an entire large environment more, like the architecture for the company, even publicizing us into open sources to contribute to others.
Principle according to composition rather than inheritance
Inheritance leads to complexity because they depend on each other, and to avoid dependencies we have to repeatedly create overlapping inheritances. And just tracing the features from the beginning is complicated.
The computer world itself is designed from electronics, not biology, itself I believe to be a collection of independent and interconnected components. Therefore, basic programming is also independent components that are tied together through interfaces, and communicate through interfaces.
+ Please observe the recent advances such as React as components fitted together.
+ Please note that the embedded Go to the struct
+ Please note that today, PHP trait
Conclusion
So your answer, what is your principle?