Skip to content

Commit 034551c

Browse files
authored
Update .gemini/styleguide.md (#972)
Changes: - Don't tell it to use full sentences in comments, or it goes overboard when critiquing people's PRs. - Add some guidance for shell scripts. - Add some more points to the overall development approach. - Minor verbiage changes here and there.
1 parent ccd7e8c commit 034551c

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

.gemini/styleguide.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# qsim style guide
22

3-
This style guide outlines the coding conventions for this project. There are
4-
separate subsections for Python, C++, and other file types below.
3+
This style guide for Gemini outlines the coding conventions for this project.
54

65
## General guidance
76

87
### Overall principles
98

10-
* _Readability_: Code should be easy to understand for all team members.
9+
* _Readability_: Code must be easy for humans to understand. Prefer clarity
10+
over cleverness. Write elegant, well-structured code.
1111

12-
* _Maintainability_: Code should be easy to modify and extend.
12+
* _Maintainability_: Code must be easy to modify and extend.
1313

14-
* _Consistency_: Adhering to a consistent style across all projects improves
15-
collaboration and reduces errors.
14+
* _Consistency_: Be consistent with naming convention, style, and other
15+
patterns in the code base.
1616

1717
* _Performance_: While readability is paramount, code should be efficient.
1818

1919
### Overall development approach
2020

21+
* Code should be modular and adhere to language idioms and best practices.
22+
23+
* Data obtained from the user or read from a file should be validated.
24+
Identify and guard against potential vulnerabilities in data handling or
25+
input validation.
26+
2127
* When new functions, classes, and files are introduced, they should also
2228
have corresponding tests. Existing tests must continue to pass (or be
2329
updated) when changes are introduced, and code should be covered by tests.
@@ -28,16 +34,16 @@ separate subsections for Python, C++, and other file types below.
2834

2935
* Tests must be independent and must not rely on the state of other tests.
3036
Setup and teardown functions should be used to create a clean environment
31-
for each test run. External dependencies (e.g., databases, network
32-
services, file system) must be mocked to ensure the test is isolated to the
33-
unit under test.
37+
for each test run. External dependencies (e.g., databases, network services,
38+
file system) must be mocked to ensure the test is isolated to the unit under
39+
test.
3440

3541
* Make sure to cover edge cases: write tests for invalid inputs, null values,
3642
empty arrays, zero values, and off-by-one errors.
3743

38-
* Use asserts intelligently. Test assertions should be specific: instead of
39-
just asserting `true`, assert that a specific value equals an expected
40-
value. Provide meaningful failure messages.
44+
* Use asserts in tests intelligently. Test assertions should be specific:
45+
instead of just asserting `true`, assert that a specific value equals an
46+
expected value. Provide meaningful failure messages.
4147

4248
### Overall code format conventions
4349

@@ -77,7 +83,7 @@ present at the top level of this project repository):
7783

7884
* [`.yamllint.yaml`](../.yamllint.yaml) for YAML files.
7985

80-
### Overall code commenting conventions
86+
### Overall code comment conventions
8187

8288
Every source file must begin with a header comment with the copyright and
8389
license. We use the Apache 2.0 license. Here is an example of the required file
@@ -99,23 +105,20 @@ header for a Python language code file:
99105
# limitations under the License.
100106
```
101107

102-
License headers are necessary on Python, C++, Bash/shell, and other programming
108+
License headers are necessary in Python, C++, Bash/shell, and other programming
103109
language files, as well as configuration files in YAML, TOML, ini, and other
104110
config file formats. They are not necessary in Markdown or plain text files.
105111

106112
For comments in other parts of the files, follow these guidelines:
107113

108114
* _Write clear and concise comments_: Comments should explain the "why", not
109-
the "what". The code itself shows what it's doing. The comments should
110-
explain the intent, trade-offs, and reasoning behind the implementation.
115+
the "what". The comments should explain the intent, trade-offs, and
116+
reasoning behind the implementation.
111117

112118
* _Comment sparingly_: Well-written code should be self-documenting where
113119
possible. It's not necessary to add comments for code fragments that can
114120
reasonably be assumed to be self-explanatory.
115121

116-
* _Use complete sentences_: Start comments with a capital letter, use
117-
proper punctuation, and use proper grammar.
118-
119122
## Python-specific guidance
120123

121124
This section outlines coding conventions for Python code in this project.
@@ -161,9 +164,9 @@ naming, we can reduce cognitive load on human users and developers.
161164
amplitudes. If a function expects a NumPy array of amplitudes, its type
162165
annotation should be `np.ndarray`.
163166

164-
### Docstrings and documentation
167+
### Python docstrings and documentation
165168

166-
For Python code, this project uses [Google style doc strings](
169+
This project uses [Google style doc strings](
167170
http://google.github.io/styleguide/pyguide.html#381-docstrings) with a Markdown
168171
flavor and support for LaTeX. Docstrings use tripe double quotes, and the first
169172
line should be a concise one-line summary of the function or object.
@@ -227,7 +230,7 @@ The following programs can be used to perform some automated formatting.
227230

228231
### Python type annotations
229232

230-
This project makes extensive use of type annotations as defined by [PEP 484](
233+
This project uses type annotations as defined by [PEP 484](
231234
https://peps.python.org/pep-0484/). All new code should use type annotations
232235
where possible, especially on public classes and functions to serve as
233236
documentation, but also on internal code so that the `mypy` type checker can
@@ -298,3 +301,14 @@ To build tests without running them, instead use:
298301
```shell
299302
bzel build tests:all
300303
```
304+
305+
## Shell script-specific guidance
306+
307+
Shell scripts should use Bash.
308+
309+
### Shell script formatting
310+
311+
Use the [Google Shell Style Guide](
312+
https://google.github.io/styleguide/shellguide.html) with the following changes:
313+
314+
* Use indentation of 4 spaces, not 2.

0 commit comments

Comments
 (0)