Hi,

When QML used V8 as JavaScript engine and its own expression interpreter called 
V4 for "simple" expressions, some of these

"simplifications" were needed to ensure the bindings could be understood by the 
simpler evaluator instead of going for a full

fledged V8 binding.


These assumptions are not correct anymore. An if statement generates the same 
intermediate representation in the code generator

as a conditional expression, and there is only one code generator.


Simon

________________________________
From: Development <[email protected]> on 
behalf of Eike Ziller <[email protected]>
Sent: Tuesday, October 4, 2016 10:13:21 AM
To: Olivier Goffart
Cc: [email protected]
Subject: Re: [Development] Using semicolons in JS (QML)


> On Oct 1, 2016, at 8:33 AM, Olivier Goffart <[email protected]> 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
> [email protected]
> http://lists.qt-project.org/mailman/listinfo/development

--
Eike Ziller
Principal Software Engineer

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




_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to