[Development] Using semicolons in JS (QML)

Eike Ziller Eike.Ziller at qt.io
Tue Oct 4 10:13:21 CEST 2016


> On Oct 1, 2016, at 8:33 AM, Olivier Goffart <olivier at woboq.com> wrote:
> 
> 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.

There was this call for using “simple” expressions, since these were handled by V4 instead of the full-blown JS engine, and not originating just from some review comment.
https://blog.qt.io/blog/2013/04/15/evolution-of-the-qml-engine-part-1/

Were they right?

(Aside from that I’d say that ?: fits the declarative style much better, so there would also be other reasons to prefer that over an if-expression.)

> -- 
> Olivier
> 
> Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
> 
> 
> 
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

-- 
Eike Ziller
Principal Software Engineer

The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
eike.ziller at qt.io
http://qt.io
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B






More information about the Development mailing list