Skip to content

Commit fdce69a

Browse files
[llvm] Improve grammar and punctuation of LLVM Coding Standards (llvm#149463)
1 parent fd12e9a commit fdce69a

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

llvm/docs/CodingStandards.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ because the naming and other conventions are dictated by the C++ standard.
3030

3131
There are some conventions that are not uniformly followed in the code base
3232
(e.g. the naming convention). This is because they are relatively new, and a
33-
lot of code was written before they were put in place. Our long term goal is
33+
lot of code was written before they were put in place. Our long-term goal is
3434
for the entire codebase to follow the convention, but we explicitly *do not*
3535
want patches that do large-scale reformatting of existing code. On the other
3636
hand, it is reasonable to rename the methods of a class if you're about to
@@ -50,7 +50,7 @@ code imported into the tree. Generally, our preference is for standards
5050
conforming, modern, and portable C++ code as the implementation language of
5151
choice.
5252

53-
For automation, build-systems and utility scripts Python is preferred and
53+
For automation, build-systems, and utility scripts, Python is preferred and
5454
is widely used in the LLVM repository already.
5555

5656
C++ Standard Versions
@@ -92,7 +92,7 @@ LLVM support libraries (for example, `ADT
9292
<https://github.com/llvm/llvm-project/tree/main/llvm/include/llvm/ADT>`_)
9393
implement specialized data structures or functionality missing in the standard
9494
library. Such libraries are usually implemented in the ``llvm`` namespace and
95-
follow the expected standard interface, when there is one.
95+
follow the expected standard interface when there is one.
9696

9797
When both C++ and the LLVM support libraries provide similar functionality, and
9898
there isn't a specific reason to favor the C++ implementation, it is generally
@@ -325,8 +325,8 @@ implementation file. In any case, implementation files can include additional
325325
comments (not necessarily in Doxygen markup) to explain implementation details
326326
as needed.
327327

328-
Don't duplicate function or class name at the beginning of the comment.
329-
For humans it is obvious which function or class is being documented;
328+
Don't duplicate the function or class name at the beginning of the comment.
329+
For humans, it is obvious which function or class is being documented;
330330
automatic documentation processing tools are smart enough to bind the comment
331331
to the correct declaration.
332332

@@ -369,7 +369,7 @@ lower-case letter, and finish the last sentence without a period, if it would
369369
end in one otherwise. Sentences which end with different punctuation, such as
370370
"did you forget ';'?", should still do so.
371371

372-
For example this is a good error message:
372+
For example, this is a good error message:
373373

374374
.. code-block:: none
375375
@@ -443,7 +443,7 @@ Write your code to fit within 80 columns.
443443
There must be some limit to the width of the code in
444444
order to allow developers to have multiple files side-by-side in
445445
windows on a modest display. If you are going to pick a width limit, it is
446-
somewhat arbitrary but you might as well pick something standard. Going with 90
446+
somewhat arbitrary, but you might as well pick something standard. Going with 90
447447
columns (for example) instead of 80 columns wouldn't add any significant value
448448
and would be detrimental to printing out code. Also many other projects have
449449
standardized on 80 columns, so some people have already configured their editors
@@ -520,7 +520,7 @@ within each other and within function calls in order to build up aggregates
520520
The historically common formatting of braced initialization of aggregate
521521
variables does not mix cleanly with deep nesting, general expression contexts,
522522
function arguments, and lambdas. We suggest new code use a simple rule for
523-
formatting braced initialization lists: act as-if the braces were parentheses
523+
formatting braced initialization lists: act as if the braces were parentheses
524524
in a function call. The formatting rules exactly match those already well
525525
understood for formatting nested function calls. Examples:
526526

@@ -607,11 +607,11 @@ Static constructors and destructors (e.g., global variables whose types have a
607607
constructor or destructor) should not be added to the code base, and should be
608608
removed wherever possible.
609609

610-
Globals in different source files are initialized in `arbitrary order
610+
Globals in different source files are initialized in an `arbitrary order
611611
<https://yosefk.com/c++fqa/ctors.html#fqa-10.12>`_, making the code more
612612
difficult to reason about.
613613

614-
Static constructors have negative impact on launch time of programs that use
614+
Static constructors have a negative impact on the launch time of programs that use
615615
LLVM as a library. We would really like for there to be zero cost for linking
616616
in an additional LLVM target or other library into an application, but static
617617
constructors undermine this goal.
@@ -698,7 +698,7 @@ If you use a braced initializer list when initializing a variable, use an equals
698698
Use ``auto`` Type Deduction to Make Code More Readable
699699
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
700700

701-
Some are advocating a policy of "almost always ``auto``" in C++11, however LLVM
701+
Some are advocating a policy of "almost always ``auto``" in C++11; however, LLVM
702702
uses a more moderate stance. Use ``auto`` if and only if it makes the code more
703703
readable or easier to maintain. Don't "almost always" use ``auto``, but do use
704704
``auto`` with initializers like ``cast<Foo>(...)`` or other places where the
@@ -783,14 +783,14 @@ guards, and might not include their prerequisites. Name such files with the
783783

784784
In general, a header should be implemented by one or more ``.cpp`` files. Each
785785
of these ``.cpp`` files should include the header that defines their interface
786-
first. This ensures that all of the dependences of the header have been
786+
first. This ensures that all of the dependencies of the header have been
787787
properly added to the header itself, and are not implicit. System headers
788788
should be included after user headers for a translation unit.
789789

790790
Library Layering
791791
^^^^^^^^^^^^^^^^
792792

793-
A directory of header files (for example ``include/llvm/Foo``) defines a
793+
A directory of header files (for example, ``include/llvm/Foo``) defines a
794794
library (``Foo``). One library (both
795795
its headers and implementation) should only use things from the libraries
796796
listed in its dependencies.
@@ -822,7 +822,7 @@ especially in header files.
822822

823823
But wait! Sometimes you need to have the definition of a class to use it, or to
824824
inherit from it. In these cases go ahead and ``#include`` that header file. Be
825-
aware however that there are many cases where you don't need to have the full
825+
aware, however, that there are many cases where you don't need to have the full
826826
definition of a class. If you are using a pointer or reference to a class, you
827827
don't need the header file. If you are simply returning a class instance from a
828828
prototyped function or method, you don't need it. In fact, for most cases, you
@@ -970,7 +970,7 @@ loops. A silly example is something like this:
970970
When you have very, very small loops, this sort of structure is fine. But if it
971971
exceeds more than 10-15 lines, it becomes difficult for people to read and
972972
understand at a glance. The problem with this sort of code is that it gets very
973-
nested very quickly. Meaning that the reader of the code has to keep a lot of
973+
nested very quickly. This means that the reader of the code has to keep a lot of
974974
context in their brain to remember what is going immediately on in the loop,
975975
because they don't know if/when the ``if`` conditions will have ``else``\s etc.
976976
It is strongly preferred to structure the loop like this:
@@ -988,7 +988,7 @@ It is strongly preferred to structure the loop like this:
988988
...
989989
}
990990

991-
This has all the benefits of using early exits for functions: it reduces nesting
991+
This has all the benefits of using early exits for functions: it reduces the nesting
992992
of the loop, it makes it easier to describe why the conditions are true, and it
993993
makes it obvious to the reader that there is no ``else`` coming up that they
994994
have to push context into their brain for. If a loop is large, this can be a
@@ -1149,12 +1149,12 @@ In general, names should be in camel case (e.g. ``TextFileReader`` and
11491149
nouns and start with an upper-case letter (e.g. ``TextFileReader``).
11501150

11511151
* **Variable names** should be nouns (as they represent state). The name should
1152-
be camel case, and start with an upper case letter (e.g. ``Leader`` or
1152+
be camel case, and start with an upper-case letter (e.g. ``Leader`` or
11531153
``Boats``).
11541154

11551155
* **Function names** should be verb phrases (as they represent actions), and
11561156
command-like function should be imperative. The name should be camel case,
1157-
and start with a lower case letter (e.g. ``openFile()`` or ``isFoo()``).
1157+
and start with a lower-case letter (e.g. ``openFile()`` or ``isFoo()``).
11581158

11591159
* **Enum declarations** (e.g. ``enum Foo {...}``) are types, so they should
11601160
follow the naming conventions for types. A common use for enums is as a
@@ -1207,7 +1207,7 @@ Assert Liberally
12071207
^^^^^^^^^^^^^^^^
12081208

12091209
Use the "``assert``" macro to its fullest. Check all of your preconditions and
1210-
assumptions, you never know when a bug (not necessarily even yours) might be
1210+
assumptions. You never know when a bug (not necessarily even yours) might be
12111211
caught early by an assertion, which reduces debugging time dramatically. The
12121212
"``<cassert>``" header file is probably already included by the header files you
12131213
are using, so it doesn't cost anything to use it.
@@ -1302,7 +1302,7 @@ preferred to write the code like this:
13021302
assert(NewToSet && "The value shouldn't be in the set yet");
13031303

13041304
In C code where ``[[maybe_unused]]`` is not supported, use ``void`` cast to
1305-
suppress unused variable warning as follows:
1305+
suppress an unused variable warning as follows:
13061306

13071307
.. code-block:: c
13081308
@@ -1546,7 +1546,7 @@ whenever possible.
15461546
The semantics of postincrement include making a copy of the value being
15471547
incremented, returning it, and then preincrementing the "work value". For
15481548
primitive types, this isn't a big deal. But for iterators, it can be a huge
1549-
issue (for example, some iterators contains stack and set objects in them...
1549+
issue (for example, some iterators contain stack and set objects in them...
15501550
copying an iterator could invoke the copy ctor's of these as well). In general,
15511551
get in the habit of always using preincrement, and you won't have a problem.
15521552

@@ -1663,7 +1663,7 @@ Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
16631663

16641664
When writing the body of an ``if``, ``else``, or for/while loop statement, we
16651665
prefer to omit the braces to avoid unnecessary line noise. However, braces
1666-
should be used in cases where the omission of braces harm the readability and
1666+
should be used in cases where the omission of braces harms the readability and
16671667
maintainability of the code.
16681668

16691669
We consider that readability is harmed when omitting the brace in the presence
@@ -1763,7 +1763,7 @@ would help to avoid running into a "dangling else" situation.
17631763
handleAttrOnDecl(D, A, i);
17641764
}
17651765
1766-
// Use braces on the outer block because of a nested `if`; otherwise the
1766+
// Use braces on the outer block because of a nested `if`; otherwise, the
17671767
// compiler would warn: `add explicit braces to avoid dangling else`
17681768
if (auto *D = dyn_cast<FunctionDecl>(D)) {
17691769
if (shouldProcess(D))

0 commit comments

Comments
 (0)