0

So JSLint is a nifty tool which promotes semantics and syntax. Most JS that I get from client's sites into JS Lint usually fails though they squeak by and most of the sites functionality still works. I try to sell them on fixing their Javascript but they see it as if it ain't broke ( meaning it is doing what they want it to do ) why fix it? Semantics and syntax is too abstract for them.

In your opinion, how important do sites with JS have to adhere to JS Lint code standards? What is a good argument for conforming to JS Lint semantics and syntax?

ectype
  • 14,865
  • 5
  • 21
  • 28
  • This is a subjective question. –  Jan 06 '11 at 18:02
  • True but I'm simply trying to build consensus. – ectype Jan 06 '11 at 18:05
  • I Googled for "semantic linters" to see if there is any - and got here. Linters are more picky on syntax. What is a tool called when it look for semantics? For example that a variable is not declared twice or that there is no unexecuted code. Or giving hints on next refactoring steps. Clean code give insights and possibilities of code to be developed. But just say "it works anyway" is to say "we are not interested to go further with this shit code". –  Jun 28 '19 at 12:03

1 Answers1

3

I would give some examples of common javascript pitfalls. Ones that could lead to more time debugging during maintenance. Global variables:

function doStuff(param1, param2) {
    foo = var1 + var2;
    return foo;
}

Brackets and indentation:

// our friend 'foo' from above. this might pass because it was global.
// what if the original writer expected foo to be undefined?
if (foo)
    foo += "some string"; // this is inside the condition
    foo += "some other string"; // this is outside. but it's not immediately obvious!

There are much worse examples out there. Go find some really nasty and confusing code, then fix it according to jslint, and compare the two snippets. Your sell will be that maintenance cost of clean code is much less than the cost of maintaining dirty code.

  • Very good! I didn't think to compare and contrast their version and the JS Lint one. Thanks. – ectype Jan 06 '11 at 18:39
  • I don't understand how the `doStuff` is needed, but it seems as the programmer was used with Python intendations that encapsulate. It is more likely the last row got intended by mistake. A linter could complain on the intendation to make programmer aware. –  Jun 28 '19 at 11:56