-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
QEP 314: Relax prohibition against "auto" #319
base: master
Are you sure you want to change the base?
Conversation
Allow use of "auto" for variable types when the variable type is explicitly stated during its initialization
FYI @rouault |
What is the motivation for this? |
qep-314-coding-style.md
Outdated
// allowed, as the QgsPoint type is explicit during initialization: | ||
auto pointObject = QgsPoint( 3, 4 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason we would want to write this instead of QgsPoint pointObject( 3, 4 );
? The notation with auto
is longer, and may involve extra copy of the temporary object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason we would want to write this instead of QgsPoint pointObject( 3, 4 ); ? The notation with auto is longer, and may involve extra copy of the temporary object?
That's a good point. Should we reword this change to only allow for some explicit types like std::unique_ptr / std::shared_ptr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we reword this change to only allow for some explicit types like std::unique_ptr / std::shared_ptr ?
yeah I think that would be good...
It's to make super verbose lines like these less painful to write:
in this case it's still immediately clear to reviewers/readers if it's written like:
|
Being allergic to auto, +1 to restricting this relaxation to only std::unique_ptr / std::shared_ptr as suggested above. |
Being an auto worshiper, +1 to relaxing. |
@elpaso , heh, that had my laugh out loud :) |
not a great fan of auto so +1 to restricting to only std::unique_ptr / std::shared_ptr. |
Now I feel like I have to voice my opinion too :) I like By the way, thanks @nyalldawson for these coding style QEPs. A comprehensive coding standard was something I sorely missed when starting with QGIS development. |
My issue with that is that it requires an IDE to actually determine the object type. Eg in this case "index()" could quite validly return a QgsSpatialIndex, a QgsKdBushSpatialIndex, or something else entirely (a QHash? A QMap?). In short, it makes pull request reviews orders of magnitude more difficult. |
+1 for non trivial sounds good. Are iterators listed as acceptable somewhere already? |
Small note: If |
I think this is worth discussing in a different proposal (to keep this one focussed), there are a few considerations to be made but in general it's a desirable direction IMHO. |
generally speaking, we should avoid using new as much as possible and favor smart pointers (std::make_unique, etc) where possible |
I definitely agree, but it's used in the codebase today and it's not always possible to sanely replace it with a smart pointer. In the future, I'd love to see some discussion on how we can further move away from raw pointers (the main blockers right now are Qt and SIP AFAIK), but for now I just don't want to have to keep writing |
+1. @dvdkon would you like to create that QEP? |
Ok, based on feedback this is now restricted to |
Co-authored-by: Matthias Kuhn <[email protected]>
Allow use of
auto
for variable types when the variable type is explicitly stated during its initialization.Specifically:
auto
may be used for variable types if the type is explicit during variable initialization. Eg