The way of software quality: Sourcemonitor

Source: Internet
Author: User
Tags case statement goto ultraedit

Some things must be done, not for happiness, but to ease the pain, because not to do, it is more painful-this is helpless.

Xianzhongyi "Wen Xin Monologue"

1 Primer

Blog has not updated for a while, the recent serious thinking about the success of Ali listed: Choice and perseverance. In fact, there is no absolute right and wrong in life, there is no absolute success and failure. Just as "Some people live, he is dead" and so on, I always take the right and wrong to make their choice, in fact, is the fundamental error. Decided to go a road, and continue to go on, although not know where the end, then enjoy the scenery along the way, and cherish with the side of the people with the minute minutes.

It's a little far, back to the subject. Previously discussed the software quality of all aspects of the road, but also are some empty words, can not achieve the real purpose. In this case, as for the last part of the end of the flow of the flowchart of each part of the detailed description, to achieve the effect of everyone available, so that it flourish.

Step-by-Step, first of all the use of the tools and the use of methods, and then explain how to use ant management, and finally unified into the CruiseControl for scheduling.

2 Sourcemonitor Profile

Sourcemonitor is a free software that runs under the Windows platform. It can measure code written in multiple languages, including C, C + +, C #, Java, VB, Delphi, and HTML, and output different code metrics for different languages.

Like other code metrics tools, Sourcemonitor focuses on the code and provides timely feedback to the coder, not a project management tool, not focusing on the implementation of the project from functional analysis to design coding, to testing the entire process.

Sourcemonitor is just a "metric" tool, but through the basic metrics, you can find some fundamental, basic problems from the surface layer of the code, so as the first tool to introduce, it should be the most basic tool for software quality control.

3 sourcemonitor Measure

When it comes to sourcemonitor metrics, which provide different metrics for different languages, this is only introduced for C + +, which provides the following metrics. (For other languages, refer to Sourcemonitor's help document explanation of Language Metrics section)

1. Total number of rows (Lines)

Number of lines of code, including blank lines.

2. Number of statements (statements)

In C + +, the statement ends with a semicolon. Branch statements If, loop statements for, while, jump statement Goto are counted, preprocessing statements #include, #define和 #undef are also counted, the other preprocessing statements are not calculated, in #else and #endif, #elif和 # Statements between endif will be ignored.

3. Branch statement Proportions (Percent Branch statements)

The value represents the proportion of the number of statements that a spoke statement occupies, where a "branch statement" refers to statements that cause the program to execute sequentially, including if, else, for, while, break, continue, goto, switch, case, default, and return. It should be noted that do is not counted, because its corresponding while has been computed. In addition, the catch of exception handling is also computed as a branch.

4. Annotation ratio (Percent Lines with Comments)

This value indicates that the comment line, including/*......*/and//... In the form of a note) as a proportion of the total number of rows. The general company will make a special statement of the header or footer section of each document, which can be filtered in the engineering properties, not counted.

5. Number of classes (Classes)

Includes the number of class,struct and template.

6. Average number of each class method (Methods per Class)

The average number of methods per class, that is, the number of class methods, including inline and template, is divided by the number of all classes.

7. Number of functions (functions)

The number of all functions.

8. Average number of statements included in each function (Average statements per method)

The total number of function statements divided by the number of functions gets the value.

9. function loop complexity (functions complexity)

Cyclomatic complexity indicates the number of executable paths for a function, and the following statements contribute to the value of cyclomatic complexity 1:if/else/for/while statements, ternary operator statements, if/for/while "&&" or "| |", and switch statements in judgment conditions, The case statement of the Break/goto/return/throw/continue statement, the catch/except statement and so on are followed. For maximum cyclomatic complexity (max complexity) and average cyclomatic complexity (avg complexity).

10. Function depth (block Depth)

The function depth indicates the number of layers in the function that are nested in the branch. For maximum depth (max Depth) and average depth (avg Depth).

4 Sourcemonitor Combat

Here's how to use Sourcemonitor to build a project to build checkpoint for different solution to live with.

1. Installation Sourcemonitor, this is not detailed, download installation can be.

2. Open the Sourcemonitor and build the project.


3. Select the language and click Next.


4. Name the current project and select the project file save path.

5. Select the current project to measure the resolution of the file, you can through the profile list (XML) or specify the path of automatic search method to add.

6. Select the relevant configuration, you can directly next ignore, if there are related needs to choose settings.



7. Specifies the name of the current checkpoint.

8. View the configuration items and determine.

9. Confirm the list of files to be measured.

10. The project has been established and the first measurement point is completed.

11. Double-click the checkpoint to see the measurements for each file.

12. Double-click a file to view detailed information.

In this way, a basic project is completed, and other functions, such as setting the default values for each indicator, you can try it yourself.

5 configuration Sourcemonitor into the editor

Since Sourcemonitor is the most basic module of code metrics, each programmer might add it to a familiar editor as a common feature item for code evaluation. So every time you write a piece of code, you can perform a test to see if the current file meets the metrics.


5.1 Visual Studio Settings

1. Set up external tools.

2. Add and configure options

Title:sourcemonitor

Command: Install the Sourcemonitor directory

Arguments:/dc++ $ (Itempath)

Initial Directory: $ (Solutionpath)

3. Add shortcut keys

Select just add Sourcemonitor is externaltools inside the first few, for example, I just added the location of the sixth, then select Command6, and specify shortcut keys (i default to specify ALT + 1, this according to personal preferences, but try not to create shortcut key conflicts).

4. Open a file, press the shortcut key to perform sourcemonitor, the results are displayed.


5.2 UltraEdit Settings

As many companies develop two of languages to suit their own tools. This language may be similar to C or some languages, but it is not efficient to open with a large tool such as Visual Studio, so it is possible to choose a lightweight editor, such as UltraEdit, to add a method similar to Visual Studio, as follows.

1. Toolbar configuration Add new tool.

2. To set the parameters

Name: Sourcemonitor

Command line: "D:\SourceMonitor\SourceMonitor.exe"/dc++ "%f"

Working directory:%p

3. Click Execute, or use the shortcut key to execute.

5.3 Other tool settings

If you use other tools, you can refer to the tool's help documentation, modify the/dc++ file name parameters, and the working directory parameters.

6 further thinking

Again to the final key step, talk about some of the recent sentiment bar. Some things do not understand the time, always from a negative perspective to consider the problem.

For example, I was not very understanding of multithreading before, I will vigorously protect themselves "do not understand multithreading" this shortcoming, so as to from the negative angle and aspects of the evaluation of multithreading. But when dealing with a large data file recently (about 20 million or more), I have deeply realized the advantages of various aspects of multithreading, but also learned more knowledge, although also written to let Daniel ridicule "spin lock" code, read the "Imperfect C + +" on the multithreading of that section, Immediately blushed, using the weekend time, thoroughly revised the "problem".

In addition, when you come into contact with this knowledge, it's a lot of fun to understand and think from different angles and find more interesting things, such as how to use c++11 asynchrony, how to throw the interface and processing into different threads, and how to throw the log into the corresponding log Print window.

Last weekend, I watched "Star treasure" again, also summed up the recent unsatisfactory aspects, found himself before is too self-centered, there are many problems do not know from their own reasons, and constantly blame others (sincerely to be hurt by my people say sorry). Or should be vigilant at all times, if the "bad" ingredients to be full, then put aside all the things, "treatment" Good to continue, do not because of their own mistakes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.