QML style guide
Sebastian Kügler
sebas at kde.org
Tue Oct 30 12:10:16 UTC 2012
On Tuesday, October 30, 2012 12:25:14 Dmitry Ashkadov wrote:
> 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.
This kind of stuff really falls into the category: "Is it more important to be
consistent than it is to satisfy everybody's personal preferences?". We'll
have to settle with one.
Also, this is a perfect example for bikeshedding. Sure, some discussion about
coding style is useful ("Do we want one?" for example, here the answer is
yes), but it's also prone to being discussed to death, as it's really a matter
of "common taste" (which is often confused with personal taste). We just need
to settle with one style, that weighs much higher than the "personal freedom
to write your code as you like", because the latter leads to the current
mess. If we settle with one style, code will be easier to read, easier to
understand, easier to review, easier to maintain, nicer to look at and have
perceived higher quality. It also allows us to communicate and percolate best
practises, which is quite important inside teams.
> 2. Why you put JS into code directory? IMHO, import "../../code/.."
> looks awfully.
import "plasmapackage:/code/LayoutManager.js" as LayoutManager
is how you can import something from the package. Don't use ../code-relative
paths.
> 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.
Or in the same file. If it's not shared, it can live in the same file, makes
it easier to associate js with qml code and slightly reduces startup time (one
file less to parse)
> Q: who is responsible to set geometry properties: parent or child ?
> I think, parent. Child should use width and height only to draw itself.
That depends on the code. Some will want to use parent for anchoring, some
will set their own geometry (for example through childrenRect) and have their
parents listen to that. This can't be determined in a style guide. (Other than
maybe, "Don't put anchors in top levels of reusable Components".)
Cheers,
--
sebas
http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
More information about the Plasma-devel
mailing list