Spaces between function name and opening parenthesis cause bugs

Software AgilityCode Readability

Why you should care

There should be no space between the name of a function and the ( (left parenthesis) of its parameter list, unless case of an anonymous literal function.
If a function literal is anonymous, there should be one space between the word function and the ( (left parenthesis). If the space is omitted, then it can appear that the function’s name is function, which is an incorrect reading.

Business Impacts

It is recommended to allow no spaces between the name of a function and the opening parenthesis of the list because more bugs in the portfolio and it prevents the code from being cost-effective.

CostTime / Effort
5362

CAST Recommendations

CAST recommends having no space between function name and parenthesis.  The JavaScript style guidelines by Douglas Crockford establish very consistent rules that help the code work well and perform with cost efficiency.

How we detect

This code insight counts one violation each time a function declaration has no space between its name and the opening parenthesis and each time an anonymous function declaration has one or more spaces between the ‘function’ keyword and the opening parenthesis.

 

function MyFunction (param) { // bad !!!

// good (it’s a literal anonymous function:
div.onclick = function (e) {
return false;
};

that = {
// bad (it’s a literal function)
method: function literal_fct (e) {
return this.datum;
},
datum: 0
};
}

5362

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