[Development] Using semicolons in JS (QML)

Olivier Goffart olivier at woboq.com
Sat Oct 1 08:33:36 CEST 2016


On Freitag, 30. September 2016 15:43:57 CEST Shawn Rutledge wrote:
> Back in Nokia times it was said that we shouldn't use semicolons, because it
> would speed up the parsing and reduce the size of resources slightly. [...]

Back in Nokia times, someone was reviewing a patch and made a comment that a 
binding looking like this:

  someProperty: {
      if (someOtherProperty === 42) 
         return something.foobar;
      else
         return somethingElse;
  }

Should be rewritten like this:

 someProperty: someOtherProperty === 42 ? something.foobar : somethingElse;

A week later, one of the bullet point in the log of the team was something 
like: 
 - replace all ifs with '?' syntax.

They indeed spend some time replacing every single 'if' of their JavaScript 
code (no matter how complex) in their QML application by the ternary operator. 
They tought it was more efficient because it was suggested to replace one 
occurrence in a review.

-- 
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org






More information about the Development mailing list