Introduced five simple overall concepts that can be easily written to write good code

Bug is low, performance is good, and easy to modify. Good code has far-reaching implications, and it can be the main reason for developers who are 10 times more productive. Although good code is very important, there is no way to develop a newbie. The skills on this topic are many and cumbersome, so how do the novices remember? “Code Complete” is a classic of this theme, but the content is up to 960 pages!

I think we should build a good attitude so that no matter what language or library you use, you will naturally write high quality code. Here I mainly talk about five related concepts. Remember them and easily write good code.

Please avoid maverick

When you read some of the new techniques in the article, such as 醍醐 醍醐, you will want to write some clever code to make your peers shine.

The problem is that people just want to fix the bug and then continue to deal with other things. Those clever skills often only become a pastime. I once said in "Applying neuroscience to software development" that when people are forced to understand your code, their "spirit stack" will fill up quickly, making it difficult to understand the meaning.

Introduced five simple overall concepts that can be easily written to write good code

[Translator's Note: The comment in the picture: This is used in the C language to avoid miswriting as variable = null. It has caused a lot of confusion recently, but it does not seem to bring much benefit]

Don't use too much personalization at work that may require additional explanation.

Don't write your code in "your way", just write it in accordance with the standard (code specification). Once again, it is necessary to write a code that people can read and understand, and let people understand it.

Divide and conquer

Modularity can make complex code structures clear, and there are many ways to achieve the same goal without having to create more functions. Saving a long conditional expression as one or two variables is a good way to avoid the overhead of calling a function. These variables can be used elsewhere and can even be used to combine more complex conditions.

The way to disassemble the problem is to keep each part as concentrated as possible, only affecting the local state, not mixing irrelevant problems, and avoiding side effects. Programming languages ​​and libraries often bring their own problems, and avoiding them can make your code more focused on the business it expresses. The single responsibility principle is an example of good design through centralized code and localized code.

[Translator's Note: Note in the figure: This is a modular approach that does not require additional function overhead]

I like to use variables for logical division.

The successful implementation of TDD (Test Driven Development) demonstrates the benefits it brings, forcing people to apply some previously unpopular guidelines. Stateless code was once rejected and slow and unnecessary (most of the old C/C++ code can be seen), but now everyone is talking about pure functions. Even if you don't adopt TDD, you should learn the principles behind it. Working in the new mode will make you a highly adaptable developer.

Separate the code and make it separate

What are the difficulties you face when writing your code, and your computer and tools face the same difficulties. The complexity of the code is more or less related to the pre-processing that needs to be done and the sudden situation that needs to be handled.

Now let's put aside the benefits of the extra build tools. They require you to use a domain-specific language, such as a custom template, or a complex dynamic data structure, such as a hash table. The IDE is usually not good at handling these things, and it is more difficult to find the relevant code snippets.

Try to avoid using language extensions and libraries that don't support IDE well. The benefits they bring to your productivity are far greater than the ease of configuration and the convenience of saving keystrokes with a simple grammar.

[Translator's Note: Note in the figure: Using a magic font string may cause the IDE to not recognize your code correctly]

ServiceLocator is a design example of poor integration with the IDE.

Another way to keep the IDE "integration" is to avoid writing special code. Most languages ​​provide the ability to write dynamic code. If you abuse these features, such as special strings, special array indexes, and custom templating language features, it will create a code base that is difficult to connect. [Translator's Note: The connection here should refer to the relationship, the most direct connection. The effect is to automatically modify the relevant references based on the connection relationship when refactoring using tools such as IDE]. In general, features that only you can understand can make you fall, because if the IDE can't understand the code, the IDE won't be able to refactor it when you want to make structural adjustments.

Make the program readable

Committed to a predictable architecture. Under this framework, it is easy for your teammates to perform a search and save a lot of time. Once you have a holistic architecture for your project, be sure to put the main elements in a prominent position. Use MVC? Put models, views, and controllers in their own directories, don't put them in three deep directories, and don't put them in a few different places.

I talked about modularity in the previous section. There is also excessive modularity that makes it difficult to locate code. The IDE may bring some help, but usually you tend to let the IDE ignore the library directory, because there are a lot of irrelevant code, or its index needs to manually handle some problems, it will lead to a losing situation. Try to use fewer libraries and choose the ones that cover your needs as much as possible.

Libraries and tools can also be obstacles for newcomers. I recently built a project using EcmaScript 7 (babel), and then I realized that our junior developers had been stuck there because they wanted to understand it, which caused a huge loss to the team's productivity. I underestimated the pressure on a newbie. Don't use tools that are too difficult for you to master today, and wait until the time is right.

Introduced five simple overall concepts that can be easily written to write good code

This is the real code in a makefile I wrote. Novices don't need to master too many new technologies.

Make the code easy to understand

If you have already done this, then let's solve the more important problem - choose a good name, which is an important part of software development. The build tool can't help in this regard for the simple reason that the computer doesn't really know the logic behind the solution. You have to interpret the code through documentation, and it's context-sensitive and context-sensitive, and the names of variables and functions do just that. Semantic names can even reduce the need for documentation.

Using prefixes in names is helpful for understanding them. This has been a popular practice in the past, and I believe that the misuse of this practice has led to its demise. Prefix systems like the Hungarian nomenclature were originally intended to add meaning, but the context in which they were used was less and less, and finally there was only a small amount of information left.

Introduced five simple overall concepts that can be easily written to write good code

[Translator's Note: The comment content in the picture: use the name to express the intention, do not use the language to play smart]

Recently, the Fluent interface has often been abused.

Finally, I would like to talk about the retrospective complexity of the old talk. Simply put, it is necessary to reduce the number of conditional branches as much as possible. Each additional branch adds indentation while reducing readability. But more importantly, the more things you add, the more things you need to track.

in conclusion

This article introduces five simple overall concepts, and I hope that you can easily learn how to organize your code.

Practice is the best teacher, using programming to consolidate theory. If you haven't done so already, I sincerely recommend the code to you. It brings a lot of examples and almost analyzes every problem you might encounter.

DC Cross-flow Fan

Dc Cross-Flow Fan,Dc Axial Fans,Dc Cross Flow Blower,Dc Cross Flow Fan

Original Electronics Technology (Suzhou) Co., Ltd. , https://www.original-te.com