[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: QML code style
From:       Artur de Souza <asouza () kde ! org>
Date:       2011-01-20 20:57:10
Message-ID: 20110120175710.871854685lmv9w2u () morpheuz ! cc
[Download RAW message or body]


Quoting Marco Martin <notmart@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

-------------------------------------------

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic