In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to make good use of SourceMonitor+Astyle to make code maintainers stop scolding? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
1. What kind of code makes you want to scold your mother?
What kind of code wants you to curse most? it's like this, the code is nested layer by layer.
Or it is so dense that it is reluctant to give up an extra line of free spaces.
Or is it that kind of code that is smelly and long?
In addition to being used to run the code, it is also very important to read, read to yourself, or read to others, if you can't read the code you wrote before after a few months, hehe.
two。 We need beautiful code.
Everyone has a love of beauty. Beautiful code, is also the pursuit of our programmers, it can not only complete the required functions, but also neat, organized, easy to understand.
Beautiful code increases readability and reduces the probability of errors. Most importantly, beautiful code will not be scolded.
Specifically, beautiful code usually:
1. Code indentation
two。 There are fewer layers of branch statement nesting.
3. There will not be too many lines of code for each function.
4. The naming of variables has a unified style
5. There is a unified style of file naming.
6. Notes have a unified style
And so on, these are all the crystallization summed up in practice. As you may have noticed, aren't these things programming specifications? That's true. In order to write beautiful code, many companies have their own programming specifications.
Some companies also take tests on programming specifications, which shows how much they attach importance to them.
3. Make good use of Jiahuo to help the code change into 3. 1 AStyle: one-click code formatting
As a wild and unruly man, I never look back when I write code. It doesn't matter what your code style is. In particular, I prefer Linux, and the code style is also Linux. For some non-Linux code-style projects, after writing the code, do you want me to put the curly braces in the function on a separate line according to the programming specification?
I need one-click formatting to change my code style from Linux to GNU to JAVA. When I am unhappy, I can change back instantly.
What I need is AStyle-support "magic skin change", one button to change the code style, can be called the coding world of Meitu.
AStyle (Artistic style) can be integrated into tools such as Eclipse,VS,SourceInsight to format and standardize the code. AStyle supports styles such as Linux,ANSI,GNU,JAVA by default, as well as custom styles.
When programmers of different coding styles jointly contribute code to a project, especially during periods of tight project cycle, there are often a variety of codes resulting in very low readability and maintainability. At this time, AStyle can solve this problem very well.
For lazy people like me, don't worry about code indentation and spend your energy on more important things, it's a burden reduction.
3.2 SourceMonitor: identify bad smells
After solving the code style, can it be regarded as beautiful code?
You know, no matter how beautiful clothes are worn on fat people, they are not as beautiful as they are (Amen, forgive me). For code, keeping with the code style is only the first step, and beautiful code is easy to understand. If it is easy to understand, the lines of code of a single function should not be too long, the number of nesting layers should not be too many, and the branching condition should not be too many. These tasks cannot be solved by code style. We need a tool that can automatically check the quality of the code-SourceMonitor.
SourceMonitor is a code quality check software. Can check the number of functions in the file, the number of lines of code for each function, comment ratio, function call depth, cyclomatic complexity and so on.
The most important thing to need is the cyclomatic complexity of each function and the number of lines of code for each function. Cyclomatic complexity refers to the path that can be executed independently in a function, so every time if/else/while,switch/case/break and so on appear in the function, the cyclomatic complexity increases by 1. 5%. The higher the cyclomatic complexity, the more executable paths in the function, the more complex it is. Consider whether the function can be reconstructed after exceeding a certain value such as (15 or 10). In addition, if the number of lines of code of a function is too long to be displayed on a screen, it is not easy for people to remember and understand, and the function needs to be refined.
3. 3 semi-automatic reconfiguration of Eclipse
After using SourceMonitor to find out the functions that need to be refactored or refined, do I have to reconstruct them manually? are there any refactoring tools? The fully automatic one has not been seen yet. If any students see it, please leave a message. In comparison, there are many semi-automatic refactoring tools. There is a refactoring menu in Eclipse, which provides many basic refactoring functions, such as function refinement, variable or method renaming, and so on.
Eclipse's semi-automatic refactoring can reduce manual refactoring errors and reduce the effort of developers, which is why I like Eclipse more and more as a CAccord Clearing + programmer.
Back to the beginning of the topic, I think there are only two kinds of code that want to scold the mother, one is difficult to use, the other is ugly.
The code is difficult to use, which is rather esoteric and is not discussed in this article.
The code is ugly, you can make the program beautiful by formatting, identify the bad smell in the code by SourceMonitor, and make the program read by means of Eclipse semi-automatic refactoring.
I believe that the code handled in this way will at least look like it will not be scolded again.
This is the answer to the question about how to make good use of SourceMonitor+Astyle to make code maintainers stop swearing. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.