[Development] Using semicolons in JS (QML)
Michael Zanetti
michael.zanetti at canonical.com
Fri Sep 30 15:25:34 CEST 2016
FWIW, in unity8 (reasonably big QML application) we agreed to not use
semicolons for declarative code unless you really want to write some
things into a single line and need them, but always use semicolons for
imperative code.
This has served us very well over the past years, seems consistent and
everyone in the team agrees this makes sense. Of course, your opinion
may differ but I thought I'd share nevertheless...
example:
Button {
anchors { left: parent.left; right: parent.right }
height: 100
text: "foobar"
onClicked: {
doSomething();
soSomeMoreStuff();
}
onReleased: doSomethingElse();
}
Br,
Michael
On 30.09.2016 14:19, Kai Koehne wrote:
> Hi,
>
>
>
> It’s Friday, so time for some bikeshedding ;)
>
>
>
>
>
> As you might know, the semicolon as a statement separator in JavaScript
> is optional. That is, most of the time you can just separate commands
>
> by newlines. There are a few pathological cases [1] though where a
> semicolon is needed. It seems the JavaScript world is divided on the topic
>
> whether to use semicolons by default though.
>
>
>
> Now I do not care that much about JavaScript as a language, but I do
> care about consistency in the Qt documentation and examples. Unfortunately
>
> we didn’t seem to have made a call so far what to prefer. Even our
> minimal “QML coding conventions” at
> http://doc.qt.io/qt-5/qml-codingconventions.html
>
> feature a semicolon in places, and in others no semicolon.
>
>
>
> To make a proposal: Let’s use semicolons in imperative JS parts of QML
> in our examples and documentation.
>
> Apart from being on the safe side regarding some pathological cases, it
> also makes the difference between declarative QML bindings and
>
> imperative JS code more explicit.
>
>
>
> Now I do realize that the right side of QML bindings is actually
> JavaScript. But no, I do not want to propose that now every binding ends
> with a ‘;’.
>
> A good rule of thumb might be that semicolons should be used inside
> either function X() {} or OnSignalHandler: {} blocks, or in .js files.
>
>
>
> Thoughts?
>
>
>
> Kai
>
>
>
> [1]: See e.g.
> http://benalman.com/news/2013/01/advice-javascript-semicolon-haters/
>
>
>
>
>
>
>
> --
>
>
>
> Kai Köhne, Senior Manager R&D | The Qt Company
>
>
>
> The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
>
> Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho. Sitz der
> Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB
> 144331 B
>
>
>
> Qt World Summit 2016 | Pier 27, San Francisco, CA
>
> Experience Exponential Potential on October 18-20
>
> www.qtworldsummit.com
>
>
>
>
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 246 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160930/6b7fd0d1/attachment.sig>
More information about the Development
mailing list