[Development] Using semicolons in JS (QML)
Simon Hausmann
Simon.Hausmann at qt.io
Tue Oct 4 10:33:50 CEST 2016
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 <development-bounces+simon.hausmann=qt.io at qt-project.org> on behalf of Eike Ziller <Eike.Ziller at qt.io>
Sent: Tuesday, October 4, 2016 10:13:21 AM
To: Olivier Goffart
Cc: development at qt-project.org
Subject: Re: [Development] Using semicolons in JS (QML)
> 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
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20161004/dba499d0/attachment.html>
More information about the Development
mailing list