-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some issues #4
Comments
Property Ordering
I think property assignments should be as close as possible. When a file gets bigger, it gets hard to tell whose property I'm assigning to because it's hard to discern the indentation and which item that level refers to. I find that code gets harder to read when you go from assignments to functions and to assignments again.
And the way I see it it lets me know at the top that these are the properties and I can assign to them like I would with the built-in properties. And also it's part of the interface, and when I look at a QML file, I see them first and I know what properties are available. You could argue the functions are also part of the interface and they should be at the top, but I try to use as few functions as possible. And with functions, I see them as things that operate on the entirety of the component. So, when they are down below I mentally find it easy to understand the relationship to the object it's declared in. Animations
I agree with you. When I initially wrote this, I was fine with it. But as time went on, and I worked more with QML and on bigger projects, multi line is almost always better than single line. I usually find it acceptable for one line if it doesn't exceed 80 characters. Giving Components IDs
You are right. I no longer follow that practice. I should have updated it. I did not know better when I wrote this. Import Statements
When I wrote this, I did a profiling and initially QML imports were taking a while. I believe this was with 5.11. So I should do it again to confirm If that's the case or not. Also, knowing that some people use QML for embedded development as well, I wanted to point out some cases that might affect performance. I think it should be more clear so that people don't go the premature optimization way. Item 2: Bindings
You are absolutely right. That section needs to be removed. I can maybe change it so that it can say don't repeatedly update a property that other's are bound to. So instead of; for (let i = 0; i < 100; i++) {
root.someProperty += i
} They do: let tmp = root.someProperty
for (let i = 0; i < 100; i++) {
tmp += i
}
root.someProperty = tmp Thanks a lot, Mitch! I'm looking forward to more of your feedback. |
I understand that coding conventions can be quite subjective (and that a lot of these conventions came from Qt's official docs), but regardless, here are some observations I made while reading this, based on my experience as a developer of and with Qt who writes a lot of QML.
Most of it looks good to me, so I'm just pointing out the stuff that stuck out.
Property Ordering
https://github.com/Furkanzmc/QML-Coding-Guide#property-ordering says:
I understand that this is from https://doc.qt.io/qt-5/qml-codingconventions.html#qml-object-declarations, but I think our own conventions are wrong (or outdated) here. The order that I use is:
id
firstPersonally I find it very jarring to declare new properties before existing ones are assigned to. :D
Function Ordering
https://github.com/Furkanzmc/QML-Coding-Guide#function-ordering says:
"very bottom of the file" is perhaps a bit too far. Personally I would say after attached properties, as above.
Animations
https://github.com/Furkanzmc/QML-Coding-Guide#animations says:
This is not a good argument for bunching up code onto one line. I know there are people (Qt developers, too) who will disagree with me on this, but I think any more than 2 property bindings on one line is too much. I think it makes it less readable, actually.
A code comment says:
I wholeheartedly disagree. :D
Giving Components ids
https://github.com/Furkanzmc/QML-Coding-Guide#giving-components-ids says:
In one particular case this is very good advice: if you assign an id to a delegate in a Control (Qt Quick Controls 2), it will prevent deferred execution of that item, which is bad, for performance reasons. However, it's probably not worth mentioning here, and I plan to document it in the Qt Quick Controls 2 docs soon.
I would also add that ids can be useful for identifying what an item is/does, though I would strongly encourage setting an objectName in that case, as it's very useful for debugging and testing.
Sorry, but is not something I would consider a best practice. Names should be descriptive, and if that means making them long, so be it. This becomes so important when you have to maintain an existing codebase; if a variable is not well-named, it makes everything just that little bit harder. A good IDE solves the problem of typing with auto-completion.
This is something I can get behind though. It is one less thing that you have to think about when writing QML code, and I imagine it will become even more relevant when the QML engine devs start making scope lookup more strict:
Property Assignments
https://github.com/Furkanzmc/QML-Coding-Guide#property-assignments says:
Personally I've never bothered with this. If there's a performance reason for it, it would be worth mentioning as justification.
Import Statements
https://github.com/Furkanzmc/QML-Coding-Guide#import-statements says:
I don't like this advice, because it conflicts with the idea of keeping QML files as small and self-contained as possible. If users follow this advice, they will end up with gigantic QML files. As for the performance side of it, I have no idea if it's true or not, but that's something Qt should aim to fix if it's an issue, rather than advocate for less imports. :)
https://github.com/Furkanzmc/QML-Coding-Guide#import-order says:
Agreed! Using a similar order to C++ is what I do.
Item 2: Bindings
https://github.com/Furkanzmc/QML-Coding-Guide#item-2-bindings says:
Technically true, but a bit fear-mongerish in my opinion. :)
True, but also not a huge deal in most cases.
The premise here is wrong, I think. Trying to improve performance by replacing declarative bindings with imperative assignments is backwards, and will likely result in slower code for all but the most extreme cases (i.e. expensive bindings). We have tools like the QML profiler to address bottlenecks in applications, so we should instead recommend that that be used if the user suspects their bindings are slow. When they've confirmed the binding is getting re-evaluated too often, and they've verified that there's nothing that can be improved in any relevant C++ code, then perhaps they could use profile-guided optimisation to replace bindings with assignments.
See also: https://doc-snapshots.qt.io/qt5-5.13/qtquick-bestpractices.html#prefer-declarative-bindings-over-imperative-assignments
WIP
The text was updated successfully, but these errors were encountered: