Features
Code Query Language (CQL)
VBDepend supports the Code Query Language (CQL) (specification available here) for maximum flexibility.
Basically, VBDepend considers your code as a database and you can write some CQL statements to query and check some assertions on this database.
As a consequence, CQL is similar to SQL and supports the SELECT TOP FROM WHERE ORDER BY pattern.
For example the following CQL query matches all public methods that have more than 30 lines of code:
SELECT METHODS
WHERE NbLinesOfCode >
30
AND IsPublic
CQL will help you answer in seconds your questions about your code base:
-
Is the code layered correctly?
SELECT TYPES WHERE !HasLevel
-
Which classes Derived from a particular class?
SELECT TYPES WHERE IsClass AND DeriveFrom "CBase"
-
Which methods create objects of a particular class?
SELECT METHODS WHERE CreateA "MyClass"
-
Which methods assign a particular field?
SELECT METHODS WHERE IsDirectlyWriting "MyClass.m_Field"
-
What are the 10 most complex methods?
SELECT TOP 10 METHODS ORDER BY CyclomaticComplexity
-
Which complex method is not enough commented?
SELECT METHODS WHERE
CyclomaticComplexity >
15
AND
PercentageComment <
10
You can also be warned automatically when a CQL query returns a certain result. In this way, CQL queries become custom rules such as:
-
Static fields should not be named m_XXX (Custom naming conventions):
WARN IF Count > 0 IN SELECT FIELDS WHERE NameLike "^m_" AND IsStatic
-
Methods out of MyProject and MyProject2 should not have more than 30 lines of code:
WARN IF Count > 0 IN
SELECT
METHODS
OUT OF
Projects
"MyProject1", "MyProject2"
WHERE NbLinesOfCode > 30
-
Public methods should not be removed to avoid API breaking changes:
WARN IF Count > 0 IN SELECT METHODS WHERE IsPublic AND IsInOlderBuild AND WasRemoved
Writing CQL queries and constraints is straightforward both because it is a SQL-like langage and because VisualVBDepend provides a CQL editor which supports intellisense and verbose compile error description.
Related Links::
Write Active Conventions on your Code Base with CQL
Compare Builds
In software development, products are constantly evolving. Hence, developers and architects must pay attention to modifications in code bases. Modern source code repositories handle incremental development. They can enumerate differences between 2 versions of source code files.
VBDepend can tell you what has been changed between 2 builds but it does more than simple text comparison. It can distinguish between comment change and code change, between what has been added/removed and what has just been modified. With VBDepend, you can see how code metrics are evolving and you know if coupling between components is increasing or not. VBDepend can also continuously check modifications to warn you as soon as a breaking compatibility change appears.
Related Links::
How to avoid regression bugs while adding new features
Ensure the quality of the code that will be developed this year
60 code metrics
There are many ways to measure a code base. The most common way is to count the number of lines of code. This metric gives a rough estimation of the effort that had been put in to develop the code base. It also allows you to obtain a quality level agreement by pinpointing fat methods and classes.
VBDepend counts the number of lines of code. It also comes with 60 other code metrics. Some of them are related to your code organization (the number of classes , the number of methods declared in a class...), some of them are related to code quality (complexity, percentage of comments, number of parameters, cohesion of classes, stability of Projects...), some of them are related to the structure of code (which types are the most used, depth of inheritance...).
-
8 metrics on application:
NbLinesOfCode,
NbLinesOfComment,
PercentageComment,
NbProjects,
NbTypes,
NbMethods,
NbFields
-
10 metrics on Projects:
NbLinesOfCode,
NbLinesOfComment,
PercentageComment,
NbTypes,
NbMethods,
NbFields,
Afferent coupling (Ca),
Efferent coupling (Ce),
Relational Cohesion(H),
-
15 metrics on types:
NbLinesOfCode,
NbLinesOfComment,
PercentageComment,
NbMethods,
NbFields,
Type rank,
Afferent coupling at type level (TypeCa),
Efferent coupling at type level (TypeCe),
Lack of Cohesion Of Methods (LCOM),
Lack of Cohesion Of Methods Henderson-Sellers (LCOM HS),
Code Source Cyclomatic Complexity,
Association Between Class (ABC)
Number of Children (NOC),
Depth of Inheritance Tree (DIT)
-
11 metrics on methods:
NbLinesOfCode,
NbLinesOfComment,
PercentageComment,
Method level,
Method rank,
Afferent coupling at method level (MethodCa),
Efferent coupling at method level (MethodCe),
Code Source Cyclomatic Complexity,
NbParameters,
NbVariables,
-
2 metrics on fields:
Afferent coupling at field level (FieldCa)
VBDepend also provides some facilities that will help you to detect metric anomalies and to fix your own thresholds.
The VisualVBDepend UI displays an interactive view of the architecture of your C++ applications. Such a view can be tuned according to numerous software metrics and can be saved in a PNG file in order to let you print posters.
Related Links::
How do you count your number of Lines Of Code (LOC) ?
Why is it useful to count the number of Lines Of Code (LOC) ?
Layering, the Level metric and the Discourse of Method
Code metrics on Coupling, Dead Code, Design flaws and Re-engineering
A simple trick to code better and to increase testability
Manage Complexity and Dependencies
It is vital information to know how the elements of a code base depend on each other. As a developer you spend time thinking about how your layers should interact, creating interfaces and events to avoid dependencies between concrete classes.
As the code base grows, more and more time is spent managing and analyzing dependencies. If I refactor this piece of code, what will be the global impact? Is this layer allowed to access directly DB? Will I accidentally freeze the UI thread if my code invokes this method?
VBDepend comes with several facilities that allow the efficient dependency management. In seconds you can know which part of the code will be impacted if you refactor a class, you can be advised if a layer dependency violation has been accidentally created, you can pinpoint precisely which part of the code relies on a particular tier component, you can list methods that can be reached from a given method etc…
Related Links::
Deconstructing Software
Hints on how to componentize existing code
Dependencies and Concerns
Interactive Code Dependencies Graph
All Paths from A to B
Detect Dependency Cycles
The easiest way to keep a code base clean is to avoid dependency cycles between its components. Components are useful to partition a huge amount of code into smaller and understandable pieces. If a dependency cycle involves N components, these N components represent a single super-component. Indeed, the benefits of having N smaller components are lost: any component can be potentially broken by a change in any of the others components, you cannot unit test a component in isolation from the N-1 other ones and finally, all N components must be versioned and deployed all together.
Whether you consider that your components are classes, or Projects or a mix in between, VBDepend detects dependency cycles between them. It can also help you to find the right way to get rid of a particular dependency cycle. Once dependency cycles have been removed, VBDepend can continuously check your code base to warn you as soon as a cycle is accidentally created.
White paper: Control component dependencies
Related Links::
Control component dependencies to gain clean architecture
Keep your code structure clean
Layering, the Level metric and the Discourse of Method
Enforce Immutability and Purity
At runtime, program’s states are instance and static fields’ values. Controlling how/when/why states are changing is one of the most challenging programming task. This becomes incredibly difficult in multi-threaded environment. This is because potential side-effects due to a state change get too complicated to be understood.
Object-Oriented developers get more and more inspired by the functional programming approach where most states are immutable. An object is immutable if its state doesn’t change once it has been created. A method is pure if its execution doesn’t change any field state. Immutable objects and pure methods are two efficient ways to limit unexpected side-effects.
Through some dedicated CQL conditions and rules, VBDepend lets assert immutability and purity on your classes and methods. The best place to start with this feature is to look at the list of default CQL constraint and to read the associated documentation.
Related Links::
Immutable types: understand their benefits and use them
Manage state in a multi-threaded environment
Generate custom reports from your Build Process
VBDepend can analyze source code and VB Projects through VBDepend.Console.exe. Each time it analyzes a code base, VBDepend yields a report that can inform you about the status of your development. You can customize sections shown in the report and you can even provide your own XSL sheet for full customization.
You can also build your own set of CQL constraints that will be checked at each analysis. The report will warn you each time a constraint is violated. This feature makes automatic design and quality regression test a reality.
Related Links::
VBDepend.Console.exe command line options
Diagrams
VBDepend outputs several kind of diagrams
| |
|
For VB.NET Code Base use:
Our Partners:
|
|