Software Quality path: SourceMonitor, sourcemonitor

Source: Internet
Author: User
Tags ultraedit

Software Quality path: SourceMonitor, sourcemonitor

Some things cannot be done, not for happiness, but to alleviate the pain, because if you don't do it, it is more painful-this is helpless.

Xia Zhongyi Wenxin monologue

 

1 Guide

The blog hasn't been updated for a while. Recently, I have carefully considered the success of Alibaba's listing: Selection and persistence. In fact, there is no absolute right or error in life, and there is no absolute success or failure. Just as "some people are alive and they are already dead." cloud, I always choose right and wrong, which is actually a fundamental mistake. I decided to take a path and continue. Although I don't know where I am at the end, I would like to enjoy the scenery along the way and cherish the minutes of the people around me!

It's a little far away, returning to the topic. I have discussed various aspects of the software quality road before, but it is also a bit of virtual talk that cannot achieve the real purpose. In this case, it is better to describe each part of the flowchart at the end of the previous article in detail to achieve the effect that everyone can use and carry forward.

Step by step, first let's talk about the usage and usage of each tool, then explain how to manage it with Ant, and then add it to the CruiseControl for scheduling.

 

2 SourceMonitor

SourceMonitor is a free software running on Windows. It can measure the code written in multiple languages, including C, C ++, C #, Java, VB, Delphi, and HTML, and target different languages, outputs different code metric values.

Like other code measurement tools, SourceMonitor only pays attention to the code and provides timely feedback to coding personnel. It is not a project management tool, focus on the entire process from functional analysis to design code and testing in project implementation.

SourceMonitor is only a "measurement" tool. However, with basic measurements, you can discover some fundamental and basic problems at the code surface level. Therefore, you can use SourceMonitor as the first tool to introduce it, it should also be the most basic tool to control the quality of software.

 

3 SourceMonitor metric Value

When talking about the SourceMonitor metric, we provide different measurements for different languages. Here we only introduce the measurement in C ++, which provides the following measurements. (For more information about other languages, see the chapter "Explain of Language Metrics" in the help document of SourceMonitor)

1. Total number of Lines)

The number of lines of code, including empty lines.

2. Number of Statements (Statements)

In C ++, the statement ends with a semicolon. The branch statement if, loop statement for, while, and jump statement goto are all included, and the pre-processing statement # include, # define, and # undef are also included, other pre-processing statements are not calculated. The statements between # else and # endif, # elif, and # endif are ignored.

3. Percentage of Branch Statements (Percent Branch Statements)

This value indicates the proportion of the branch statement to the number of statements. The "branch statement" here refers to the statements that make the program run in an unordered manner, including if, else, for, while, break, continue, goto, switch, case, default, and return. Note that do is not included because its corresponding while has been calculated. In addition, catch for exception handling is also calculated as a branch.

4. Percentage of Comments (Percent Lines with Comments)

This value indicates the comment line (including /*...... */And //...... The proportion of the total number of rows. Generally, the company will make a special declaration and comment on the header or footer part of each document. You can filter the header or footer part of the document by setting it in the project attribute, which is not included.

5. Number of Classes (Classes)

Number of classes, struct, and template.

6. Average number of Methods per Class (Methods per Class)

The average number of methods for each class, that is, the number of class methods, including inner and non-inline functions, divided by the number of all classes.

7. Number of Functions (Functions)

The number of all functions.

8. Average number of Statements contained in each function (Average Statements per Method)

This value is obtained by dividing the total number of function statements by the number of functions.

9. Function Complexity)

The circle complexity indicates the number of executable paths of a function. The following statement contributes 1 to the Circle complexity value: if/else/for/while statement, ternary operator statement, if/for/while in the judgment condition "&" or "|", switch statement, followed by the case statement of break/goto/return/throw/continue statement, catch/catch t statements. Max Complexity and Avg Complexity ).

10. Function Depth (Block Depth)

Function depth indicates the number of nested branches in a function. Max Depth and Avg Depth ).

 

4. Practice of SourceMonitor

The following describes how to use SourceMonitor to create a Project and establish a Checkpoint for different live projects of Solution.

1. Install SourceMonitor. This is not detailed. Download and install it.

2. Open SourceMonitor and create a project.


3. Select a language and click Next.


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


5. Select the file for measurement parsing in the current project. You can add the file by using the configuration file list (XML) or by specifying the path for automatic search.


6. Select the relevant configuration, and you can ignore it directly next. If necessary, select the settings.



7. specify the name of the current Checkpoint.


8. View and confirm the configuration items.


9. Confirm the list of files to be measured.


10. The project is created and the first measurement point is completed.


11. Double-click the checkpoint to view the measurement values of each file.


12. Double-click a file to view details.


In this way, a basic project has been created, and other functions, such as setting the default values of each indicator, can be tried by yourself.

 

5. Configure SourceMonitor to the editor.

Because SourceMonitor is the most basic module of code measurement, Every programmer may add it as a common function item for code evaluation to a familiar editor. In this way, you can check whether the current file meets the metrics every time you write a piece of code.


5.1 Visual Studio settings

1. Set external tools.


2. Add and configure options


Title: SourceMonitor

Command: directory for installing SourceMonitor

Arguments:/DC ++ $ (ItemPath)

Initial directory: $ (SolutionPath)

3. Add shortcuts


Select the number of added SourceMonitor files in ExternalTools. For example, if the position I just added is sixth, select Command6 and specify the shortcut key (I set it to Alt + 1 by default, this is based on your preferences, but try not to cause a shortcut key conflict ).


4. Open a file and press the shortcut key to execute SourceMonitor. The result is displayed.



5.2 UltraEdit settings

Many companies develop secondary languages to suit their own tools. This language may be very similar to C or some languages, but it is not very efficient to open it with a huge tool such as Visual Studio. Therefore, you may choose to use some lightweight editors, for example, if UltraEdit is used, the adding method is similar to that of Visual Studio.

1. Add a new tool in the toolbar configuration.


2. Set 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 help documentation of the tool to modify the file name parameters and working directory parameters after/DC ++.

 

6. Further consideration

Next, let's talk about some recent insights. When you do not know something, you will always consider the problem from a negative perspective.

For example, I didn't know much about multithreading in the past, so I tried my best to protect myself from the disadvantages of "multithreading", so as to judge multithreading from a negative perspective and aspect. However, when I recently processed large-scale data files (about 20 million or more), I deeply realized the advantages of multithreading in various aspects and learned more, although I have also written the "spin lock" code that makes everyone laugh at, after reading the section "Imperfect C ++" about multithreading, I immediately blushed and took advantage of the weekend, this "problem" was completely modified ".

In addition, we will understand and think about this knowledge from different perspectives and discover more and more interesting content, for example, how to use C ++ 11 Asynchronization to throw the interface and processing to different threads, and how to throw the Log to the corresponding Log printing window is really fun.

I read "star baby" Again last weekend and summarized the unsatisfactory aspects recently. I found myself too self-centered, there are many problems that I don't know why from myself, and I keep blaming others (I'm sorry to someone who has been hurt by me ). You should always be alert to yourself. If the "bad guy" is full, let go of all things for the time being. If the "bad guy" is ready, continue and do not make mistakes because of yourself!



How to Use sourceMonitor

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.