QML style guide

Aaron J. Seigo aseigo at kde.org
Tue Oct 30 19:47:29 UTC 2012


On Tuesday, October 30, 2012 18:16:26 Aurélien Gâteau wrote:
> In the example, "property alias bar : actual.property": there is a space
> before the colon, is it on purpose?

nope. my mistake. i've fixed it now. thanks for noticing :)

> I think it would be good to standardize the id of the top-level item. So far
> I have often seen "main" or "root" used.

agreed; though i'd like to see in the Best Practices section as there will be 
exceptions.

i like "root" as it is also used in the QML documentation in several places.
 
> JS lines should end with semi-colons. This is expected by JSLint anyway, but
> I think it is invasive enough to be mentionned explicitly.

agreed. in fact, there is already this:

      fooFunction(); // in blocks, kdelibs style, including semicolons at EOL
 
but that is evidently not noticeable enough. i've addded this to the "JS Code 
Blocks" section.

> The only part I don't really like is putting left curly brace on its own
> line for functions because:
> 
> - having different conventions for event-handlers and function code blocks
> look inconsistent

fwiw, it's not just event handlers. things like:

anchors {

}

also have on-the-same-line braces and, due to the lovely consistency that is 
QML, does not have a ':'

> - it differs from many coding styles: Qt QML JavaScript, Douglas Crockford,
> jQuery, Node... so I think it is going to look odd and unfamiliar to many
> newcomers.

every style differs from many coding styles. we also don't use Linux kernel 
style. so that is not a useful argument imho.

my main gripe is that this creates an exception relative to every other bit of 
code we write in any other language. as it is right now, some of our JS code 
is written one way, and others another. 

if we do go with "always { on the same line", several us in the core team swap 
regularly between C++ and QML/JS and this becomes an annoyance through 
inconsistency and will require additional discipline as suddenly it will 
matter what language you are using :/

what i really, really don't want is .qml files with JS in them and .js files to 
have different styles.

anyways, i don't have a hugely set opinion on which way to do this. on-new-
line means one less exception to the kdelibs style to follow; on-same-line 
means QML elements and JS functions look more similar. personally, i'm not 
100% happy with either choice :P

-- 
Aaron J. Seigo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20121030/8e66b72a/attachment-0001.sig>


More information about the Plasma-devel mailing list