QML style guide

Dmitry Ashkadov dmitry.ashkadov at rosalab.ru
Tue Oct 30 08:25:14 UTC 2012


Hello!

First of all, it a good idea!

1. I think you should explain why you have chosen  such style instead of 
another one. Your decision should be justified. For example: I don't 
understand why you put brace on new line in case of function. As for me 
it's terrible because I need always remember that there is one exception 
for function definition and every time check functions. It's easier 
remember that I must always put brace on the same line. At the same time 
definition of function looks awfully against definitions of other items.

2. Why you put JS into code directory? IMHO, import "../../code/.." 
looks awfully. Some JS can be an adjunct to QML file and cannot be used 
outside of this QML file. Such JS can provide stuff for only one QML. To 
simplify understanding such situation such JS and QML files may be named 
similar:  main.js & main.qml. And it may be better to put them into the 
same directory.


3. What is better:

Variant 1:

Button.qml:

Button {
anchors.fill: parent
     ...
}

main.qml:

Item {
     Button {}
}


Variant 2:

Button.qml:

Button {
     ...
}

main.qml:

Item {
     Button {
         anchors.fill: parent
}
}

Q: who is responsible to set geometry properties: parent or child ?
I think, parent. Child should use width and height only to draw itself.


4. What is about private functions? What is about private properties? 
Should they go first or last in QML files? Should they have special naming?


5. Vim:
> The {{{ and }}} are just for the sakes of vim's automatic folding.
Do we all use vim? I think no. So, we must never force developers use vim.

6.
> i'm ok either way, but declared properties before geometry properties means we
> need to alter nearly every single QML file to meet that guideline.
Let them be unchanged until somebody want to do it. Old code will always 
stop you to make new code better. Refuse new code made in old style.





More information about the Plasma-devel mailing list