---
id: 487
lang: en
translation_of: index.md
source_sha256: 39cb68b6733639b9e7581d8f95409767ec01e6a4a8931f42be528ff308fbda5d
title: "The Code Style of Yours Truly"
description: "My rules for braces, naming, constants and formatting in contest code, plus a table of the variable names I use."
tags: ["OI","Code Style"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "鄙人 (a humble, archaic “I”) in the title rendered as “Yours Truly”."
  - "生成周期 in rule 4 is read as a typo for 生命周期 (lifecycle) and translated as “long lifecycle”."
  - "小驼峰 rendered as “lowerCamelCase”."
  - "Rules 1 and 6 have no closing full stop in the Chinese; the English keeps them without one."
---

## A Few General Rules

1. Braces go on a new line (at least in C-family languages; in JavaScript, whatever, but I've never seen anyone use JavaScript in competitions)
2. Use the variable names from the problem statement whenever possible.
3. Temporary variables (loop variables, say) can be named with a single letter or a two-letter abbreviation.
4. Global variables and fields with a long lifecycle should be in lowerCamelCase whenever possible.
5. Functions and function variables are named in lowerCamelCase.
6. Constructors that assign values and initialization functions get done in one line (for example initializing an edge, or initializing a disjoint-set union)
7. Use #define less, use const more.
8. Inside loops or conditional statements, <span class="slang" data-zh="压行" data-gloss="yāháng, “pressing lines”. Cramming several statements onto one line to keep code short.">squash lines together</span> with commas (not too long).
9. Use a modern editor for automatic formatting (<span class="slang" data-zh="墙裂安利" data-gloss="qiángliè ānlì, “wall-crack Amway”: 墙裂 is a pun on 强烈 “strongly”, and 安利 (Amway) means pushing something on others. Strongly recommending something.">strongly recommend</span> VSCode, say goodbye to the F\*\*K debugging method).

Sample code:

```cpp
// snippet.cpp
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX_N = 100;
int n, seqa[MAX_N], seqb[MAX_N], ans;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &seqa[i]), scanf("%d", &seqb[i]);
    for (int i = 1; i <= n; i++)
        ans += seqa[i] - seqb[i];
    printf("%d", ans);
    return 0;
}
```

## Variable Name Table

| Meaning | Variable name |
|---|---|
| Answer | ans |
| Stack | st |
| Queue | q |
| Maximum | MAX_??? |
| Minimum | MIN_??? |
| Array | arr[] |
| Multiple arrays or sequences | seq?[] |
| Source data/start point | src |
| Target data/end point | dst |
| Distance | dist |
