Avoid using risky patterns too frequently

Software ResiliencyProgramming Best Practices

Why you should care

Some specific code syntaxes, even if they compile and don’t make a software crash directly, are not recommended mainly for two reasons:

    • They’re often obscure and/or implicit and could definitely lead to misinterpretations by junior developers, which frequently means unexpected bugs when the code is modified
    • When located around these blurry syntaxes (coding gurus will qualify them as “art”), real bugs are much harder to catch, especially because the syntax doesn’t bestially describe what it does and needs advanced interpretations

    To illustrate the confusion these risky patterns could generate, take a look at this real-life example below found on GitHub (line #421 and #424):

    left_child = new_left_child;
    left_weight = left_weight;
    right_child = new_right_child;
    right_weight = right_weight;

    And most importantly, look at the issue and doubts this variable self-assignment has raised within the development team:

    Business Impacts

    Using risky syntax can lead to increased bugs in an application, since it makes troubleshooting and expansion of existing code needlessly complicated. This, in turn, will increase the time and effort that developers have to spend maintaining and updating a given codebase.


    CAST Recommendations

    When possible, software should use the most simple and explicit code syntax to perform actions. While some development gurus say they can do more with less code, it generally means spending more time for small bugs.



    Style Guide

    How we detect

    This code insight verifies that the source code doesn’t contain technology-specific patterns that tend to generate unexpected bugs. Below are listed some examples for the technologies Highlight supports. Based on specific thresholds CAST has defined over time, Highlight counts penalty points for the scanned file.

    C/C++ and Objective-C

    a = a;
    a == b;
    * expr ; with expr containing no function call nor assignment operator.


    <end of line>
    <begin of line> :
    …….. = (no colon or coma between the peer of equals)


    a = a ;
    a == b ;

    Java and JSP

    a = a ;
    a == b ;


    About CAST and Highlight’s Code Insights

    Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

    See featuresHow it works