QML code style
Artur de Souza
asouza at kde.org
Thu Jan 20 21:57:10 CET 2011
Quoting Marco Martin <notmart at gmail.com>:
> Artur, do you know something more about coding conventions used
> internally for
> QML/QtComponents? if sensible we could just steal, ehm, i mean adopt them ;)
In QtComponents we use the links below as a reference:
http://doc.qt.nokia.com/4.7-snapshot/codingconventions.html
https://developer.mozilla.org/En/Developer_Guide/Coding_Style
and I could also find the guidelines below one e-mail:
1. avoid using ';', unless strictly needed (just use it if you are writing
multiple commands on the same line and even in this case avoid the last
semicolon).
target: statusbar; property: "y"
2. avoid writing more than one command on the same line :-), but this is not
strict.
The example below is good, IMO these cases, PropertyChanges and Animation,
can have their properties on one line.
states: State {
name: 'hidden'
when: window.statusbarVisible == false
PropertyChanges { target: statusbar; y: -statusbar.height }
}
transitions: Transition {
NumberAnimation { target: statusbar; property: "y"; duration: 300;
easing.type: Easing.InOutQuad }
}
3. use a blank space after and before curly braces (when in the same line)
'{', '}'
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: { button.clicked() }
}
4. use 4 spaces for indentation (no tabs)
5. use double quotes for strings: "string" instead of 'string'
I kind of dislike more than one command in the same line and for JS
stuff I put ";" in every end of line/command (while in QML code we
avoid them). I can find a link explaining the reason behind ending
with ";" every JS line if you want.
You are also right that it's going to be very good to setup some
"naming" guidelines for id's. It can be really a mess if we don't
follow some guideline.
Ah, something I almost forgot: following some scripting languages,
properties that we would like to make "private/protected" are declared
with "__" preprending their names, for example:
property int __protected: 0
Cheers,
Artur
-------------------------------------------
More information about the Plasma-devel
mailing list