[PATCH] D54877: Update coding guidelines regarding use of `auto`

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 27 02:27:57 PST 2018


jhenderson added inline comments.


================
Comment at: docs/CodingStandards.rst:786-791
 Use ``auto`` Type Deduction to Make Code More Readable
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Some are advocating a policy of "almost always ``auto``" in C++11, however LLVM
-uses a more moderate stance. Use ``auto`` if and only if it makes the code more
-readable or easier to maintain. Don't "almost always" use ``auto``, but do use
-``auto`` with initializers like ``cast<Foo>(...)`` or other places where the
-type is already obvious from the context. Another time when ``auto`` works well
-for these purposes is when the type would have been abstracted away anyways,
-often behind a container's typedef such as ``std::vector<T>::iterator``.
+uses a more moderate stance. Don't "almost always" use ``auto``, but here are
+some cases where use of ``auto`` would make sense:
----------------
lebedev.ri wrote:
> Note the subject of the paragraph.
> It's not about the code being readable to the author.
> It's about code readability for the review/reviewers.
> 
> Unbanning more use-cases will not make `auto` in those cases less opaque.
Surely it's about making things more readable for both parties (not specifically the author or the reviewer)? Since developers when maintaining the code have to be able to easily read the code they are about to write/edit, it needs to be readable for them too.


================
Comment at: docs/CodingStandards.rst:797
+  such as ``auto it`` instead of  ``std::vector<T>::iterator it``.
+* Range-based for loops.
+* Where the instance is only needed to perform a validity check,
----------------
As others have said, I agree that Range-based for loops are not a good example in many situations. It may be appropriate in some, but not others.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54877/new/

https://reviews.llvm.org/D54877





More information about the llvm-commits mailing list