Good programming principles are closely linked to good system design principles and technical implementation principles. The following programming principles have made me a good programmer in the past years, and I believe that these principles can greatly improve the programming capabilities of any developer, allowing him to develop programs that are more maintainable and less flawed.
I don't want to repeat myself -this is probably one of the most basic tenets of programming development, which is to tell you not to repeat the code. Many of our programming constructs exist to help us eliminate duplication (for example, looping statements, functions, classes, and so on). Once a program begins to appear repetitive (such as long expressions, a whole bunch of statements, but all to express the same concept), you need to do a new refinement of the code, abstraction.
Http://en.wikipedia.org/wiki/Don%27t_repeat_yourself
Refining principle -in relation to the "do not self-repeat principle", the principle is that "any functional code in the program should be unique in the source code file." ”
Http://en.wikipedia.org/wiki/Abstraction_principle_ (programming)
Keep it simple -simplification (avoiding complexity) should always be your first priority. Simple programs make it easy to write, produce fewer bugs, and easier to maintain changes.
Http://en.wikipedia.org/wiki/KISS_principle
don't develop features you don't currently have-unless you really need it, don't add to the clutter.
Http://en.wikipedia.org/wiki/YAGNI
Use the simplest way to get the program running -there is a very good question in development and you need to ask yourself, "How do I get the simplest program to run?" "This can help us keep the program simple at design time."
Http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html
don't make me think .-This is actually the title of a book that Steve Krug about web interface operations, but it also works for programming. The main idea is that program code should allow people to read and understand with minimal effort. If a program takes too much effort for a reader to understand, it is likely that it will need to be further simplified.
Http://www.sensible.com/dmmt.html
Open/Closed principle -Entity items (classes, modules, functions, etc.) in a program should be open to extended behavior and closed for modification behavior. In other words, do not write classes that allow others to modify, and should write classes that allow people to expand.
Http://en.wikipedia.org/wiki/Open_Closed_Principle
Write programs for maintainers -any program that is worth your writing is worth maintaining in the future, perhaps by you, perhaps by others. In the future, when you have to maintain these programs, your memory of the code will be basically the same as a stranger, so you'd better be as if you have been writing programs for others. One way to help you remember this principle is to remember that the person who is going to maintain your program in the future is a psychopath who has a serious tendency to violence and knows where you live.
Http://c2.com/cgi/wiki?CodeForTheMaintainer
least surprising principle-the least accidental principle is usually used in user interface design, but the same principle applies to writing programs. The program code should be as far as possible to not surprise the reader. In other words, coding norms and common habits should be followed, organized and named in accordance with accepted customary practices, and inconsistent with routine programming actions should be avoided as much as possible.
Http://en.wikipedia.org/wiki/Principle_of_least_astonishment
Single Responsibility principle -a code component, such as a class or function, should perform only a single preset task.
Http://en.wikipedia.org/wiki/Single_responsibility_principle
Minimizing coupling relationships -a snippet (code block, function, class, etc.) should minimize its reliance on other code. This goal is achieved by using as few shared variables as possible. "Low coupling is a symbol of a computer system with reasonable structure and excellent design, and it is very important for the realization of important goals such as readability and maintainability to combine it with high aggregation characteristics." ”
Http://en.wikipedia.org/wiki/Coupling_ (computer_programming)
Maximize Cohesion-code with similar functionality should be placed in the same code component.
Http://en.wikipedia.org/wiki/Cohesion_ (computer_science)
Hide Implementation Details -The hidden implementation details minimize the effects of the other program modules that you use to modify the program components.
Http://en.wikipedia.org/wiki/Information_Hiding
The law of Demeter -The program component should only be related to its immediate family (for example, inheriting classes, objects contained within, objects passed in through the parameters portal, etc.). )
Http://en.wikipedia.org/wiki/Law_of_Demeter
Avoid premature optimization -only if your program has no other problems, just slower than you expect, you can think about optimization. Only when other work is done can you consider the optimization problem, and you should only optimize it based on empirical practices. "For small-scale performance improvements should not be considered, to optimize should be 97% performance improvement: Premature optimization is the root of all evils,"-donald Knuth.
Http://en.wikipedia.org/wiki/Program_optimization
code Reuse -This is not a very central principle, but it is as valuable as any other principle. Code reuse can improve the reliability of your program and save you development time.
Http://en.wikipedia.org/wiki/Code_reuse
segregation of duties -functions in different areas should be managed by a completely different code module, minimizing overlap between such modules. Http://en.wikipedia.org/wiki/Separation_of_concerns
Embracing Change -this is the subtitle of Kent Beck's book, which is also one of the basic tenets of extreme programming and agile development methodologies. Many of the other principles are based on the idea that change is welcome. In fact, some classic software engineering principles, such as minimizing coupling, are meant to make the program more prone to change. Whether or not you use the extreme programming approach, this principle is important for your program development. http://www.amazon.com/gp/product/0321278658
Programming principles that every programmer must follow