Commit Graph
19 Commits
Author SHA1 Message Date
Geoff Romer bf2ed6174d Move variable naming to its own section. (#7307)
My understanding is that `auto` is encouraged even when there's no
applicable naming convention for the variable, and that suffixes like
`_id` are encouraged where applicable, even if the type is explicit, so
there's really no connection between the two policies.
2026-06-05 19:07:39 +00:00
Jon Ross-PerkinsandDana Jansens fb58a41b11 Add a note about iterative coding style (#6528)
Adding the note about recursion because it occasionally comes up, and
I'm thinking it'd be helpful to document why we prefer iterative
algorithms.

Also moves a few long style points to headers so that they're easier to
link (I wasn't sure it makes sense to do to all of "syntax and
formatting", but either way what's remaining is shorter if that _is_
linked for reference).

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-12-19 21:00:14 +00:00
Dana Jansens 4a96799e1f Document our practices around using auto and naming variable types (#5663)
We use `auto` for most local variables, and we put the type name into
the variable name in common cases, especially for our ID types.

This was discussed in `#style`:
https://discord.com/channels/655572317891461132/821113559755784242/1380091326900469801
2025-06-18 14:10:01 +00:00
Jon Ross-PerkinsandDana Jansens 467e510d40 Document abbreviation style things (#4996)
We had a long discussion of this, so trying to document what seems to be
the conclusion... and also clean up the exceptions that I could find.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-02-27 02:13:17 +00:00
Jon Ross-Perkins 2fef1cb713 Switch to trailing returns in toolchain and related code. (#4919)
Also makes the style guide explicitly comment on void, but this was the
intent IIRC because it matches Carbon's `-> ()` (and "always" versus
"except for void", which we definitely went back and forth on).

Includes adjusting function pointers, which I definitely forget this
syntax works sometimes.

Excludes utils/tree_sitter/src/scanner.c because it claims to be C, but
really we should probably fix that to be cpp.
2025-02-11 18:11:14 +00:00
Jon Ross-Perkins cb4686bf21 Enable misc-non-private-member-variables-in-classes and adjust style to match (#4702)
Pursuant to discussion regarding #4699, turn on
`misc-non-private-member-variables-in-classes` using the
`IgnoreClassesWithAllMemberVariablesBeingPublic` flag (the check treats
structs as classes, so we need this for structs with all-public
members). Updates the style guide notes to match, which should be pretty
minor due to the scoping of test fixtures.

Also fixes some underscore uses in test files on the way. Basically this
is keeping the style for [class data member
naming](https://google.github.io/styleguide/cppguide.html#Variable_Names)
even while making them public.
2024-12-19 00:31:41 +00:00
Jon Ross-PerkinsandChandler Carruth 434ee32515 Style notes on passing and storing object addresses (#4310)
[Context](https://discord.com/channels/655572317891461132/821113559755784242/1283516297686286377).
Some relevant Google C++ style is at [Inputs and
Outputs](https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs).
#4301 is an example application of the style.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-09-20 23:53:02 +00:00
Jon Ross-PerkinsandRichard Smith cdc0ca14ec Be a little more prescriptive about {} initialization in style. (#4009)
Following discussions around #3958, try to provide more specific
semantics. Note we currently don't follow this everywhere, particularly
in AddInst calls, but the intent is to shift. Per discussion, designated
initializers are preferred when possible. And the
`google-readability-casting` diagnostics are poor, but with this may
primarily flag cases which should be using a different constructor
syntax, so are just a rocky way to get there.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-05-31 16:22:25 +00:00
21fb6f5802 Update broken links (#3786)
Update broken links to aid in following links while perusing the
documentation. Closes #3778

I don't imagine I got every one of these right. Some 404s may be
reported due to permissions.

Using the lychee command in #3778, only the following link is reported
as not found, but it's just a permission issue:

```
[proposals/p1367.md]:
✗ [404] https://github.com/carbon-language/carbon-lang/settings/access | Failed: Network error: Not Found
```

I tried to get it down to as few as possible, partially so that future
link scans won't run into repeat errors.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2024-03-22 18:42:20 +00:00
Jon Ross-Perkins 4605b1d3e1 Style note for explicit constructors. (#3457)
This stems from an [old
discussion](https://discord.com/channels/655572317891461132/821113559755784242/1070759074112741447),
I think this is the resolution that never got added here.
2023-12-06 00:10:33 +00:00
Geoff Romer e3d3122f1d Move tests to the namespace of the code under test (#3244)
Rationale: this convention avoids forcing closely-related code to be far
apart in the namespace hierarchy, and vice versa. By the same token, it
makes the namespace hierarchy more consistent with the directory
hierarchy.
2023-09-18 22:05:14 +00:00
Richard Smith 90cca11ea3 Document the de facto conventions for library dependencies in explorer (#3092)
Unlike in the toolchain, we have not been preferring LLVM facilities
over standard ones. Update the documentation to describe this and
provide some rationale.
2023-08-11 19:22:58 +00:00
MarchMore a3dc3cac74 Documentation: Minor corrections of several md files (#1806) 2022-07-30 11:16:11 -07:00
Jon Meow eda43faa5a Note namespace and static recommendations in C++ style guide (#1041) 2022-01-27 11:26:47 -08:00
Geoff RomerandChandler Carruth bf49f2efed Proposal: Property naming in C++ (#720)
This proposed style change allows C++ classes in the Carbon project to provide methods that are named like variables, so long as they behave like _properties_ of the class. It also requires data member names to have a trailing `_`.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-09-28 14:36:43 -07:00
Jon MeowandChandler Carruth 50fa120c87 Add style guideline for using std::foo; (#263)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-02-22 10:38:54 -08:00
Chandler Carruth 79ad0bf228 Make the rules for braces on ifs and loops simpler and more strict. (#194)
This simply requires braces and doesn't allow single-line `if`s. There
is some minor readability loss here, but it seems minor and provides
extremely simple rules which I'd value.

I can also trivially get clang-tidy to both check for this and
automatically fix code to conform.

Just sending this as a code review as it seems fully in the direction of
the style guide approved by the core team and I've heard no real
objections. That said, if anyone is concerned, I'm happy to take it
through the proposal process.
2020-12-02 20:07:13 -08:00
Jon Meow 79a9b51d07 Update pre-commits, add and address flake8 (#195)
Adopts new copyright and markdown toc checks.

The new toc check generates the toc header, so that's why all the md files changed (this had felt better to me for the long-term, more auto-generated content)
2020-11-13 16:34:23 -08:00
f44cf22924 Add a C++ style guide for the project (#113)
When writing C++ code for Carbon, we want to keep all of our code consistent,
easy to learn, and help avoid spending undue code review time arguing about
the same core style and idiomatic issues.

This adopts the Google C++ style guide as a baseline, and then makes minimal,
focused additions and adjustments to it to suit the needs of Carbon.

Co-authored-by: Thomas Köppe <tkoeppe@google.com>
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: austern <austern@google.com>
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
2020-11-13 00:49:54 -08:00