官术网_书友最值得收藏!

Other quality gates

Next to tests, you want other measurements of code quality. For example, code that has many nested if statements is hard to test and understand. Writing an if statement without curly braces (for single statements) will increase the chances of bugs in the future. Not closing database connections or file handles may lock up your system and cause other processes to fail. Failing to unsubscribe from (static) events may cause memory leaks. Such errors may easily pass unit tests, but will eventually fail in production. These sort of errors can be very difficult to find as well. For example, a memory leak may cause your application to run slowly or even crash after a day or two. Good luck finding bugs that only happen to some users, sometimes, because they haven't closed the application in two days. Luckily, there are tools that find exactly these kinds of issues. SonarQube is one such tool. It will show you where you can improve your code, how important it is that you fix this code, the time it will probably take to fix it, and a trending graph of your technical debt.

It is important to note here that these issues, unlike unit tests, may or may not be actual bugs. For example, the following code is completely valid, but may introduce bugs that are not easy to spot:

if (valid)
   DoSomething();

Now the specifications change and you, or a coworker, have to change this code so something else is also executed when valid. You change the code as follows:

if (valid)
   DoSomething();
   DoSomethingElseIfValid(); // This is a bug as it's always executed.

Tools such as SonarQube, will recognize this pattern and they will warn you that the code is not best practice including an explanation on what's wrong with it and how to change it. In this case, the original code should be changed, so it's clear what happens when valid:

if (valid)
{
   DoSomething();
}

We will have a look at SonarQube later in this book and see both C# and JavaScript issues that may or may not be bugs.

主站蜘蛛池模板: 林芝县| 米泉市| 东源县| 怀化市| 敦化市| 突泉县| 泽库县| 宿迁市| 尉犁县| 恩平市| 买车| 盖州市| 沙雅县| 临安市| 巴塘县| 延庆县| 陆丰市| 都匀市| 贵德县| 邯郸市| 泰州市| 禹城市| 普陀区| 监利县| 永州市| 龙山县| 泸溪县| 山东省| 大冶市| 保靖县| 宁波市| 鸡泽县| 三台县| 咸宁市| 西畴县| 府谷县| 锦屏县| 永清县| 伊吾县| 道孚县| 赣州市|