swift-api-design-guidelines
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwift API Design Guidelines
Swift API设计指南
Apply the Swift API Design Guidelines when naming types, methods, properties, parameters, and argument labels. Targets Swift 6.3. For language features and syntax, see . For concurrency patterns, see .
swift-languageswift-concurrency在命名类型、方法、属性、参数和参数标签时,请遵循Swift API设计指南。适配Swift 6.3版本。如需了解语言特性和语法,请参考。如需了解并发模式,请参考。
swift-languageswift-concurrencyContents
目录
Argument Label Rules
参数标签规则
Argument labels determine how a call site reads. Apply these rules in order.
参数标签决定了调用点的可读性。请按顺序应用以下规则。
When to omit the first argument label
何时省略首个参数标签
Grammatical phrase rule. When the first argument forms a grammatical phrase with the base name, omit the label. Move any leading words from what would be the label into the base name instead.
swift
// GOOD — reads as "add subview y"
view.addSubview(y)
// BAD — redundant label breaks the phrase
view.add(subview: y)Value-preserving type conversions. When an initializer performs a value-preserving (widening) conversion, omit the first argument label.
swift
// GOOD — widening conversion, no label
let value = Int64(someUInt32)
let str = String(someCharacter)
// Narrowing or lossy conversions keep a label
let approx = Int64(truncating: someDecimal)
let str = String(describing: someObject)Indistinguishable arguments. When all arguments cannot be usefully distinguished, omit all labels.
swift
// GOOD — arguments are peers
let smaller = min(x, y)
zip(sequence1, sequence2)语法短语规则(Grammatical phrase rule)。当首个参数与基础名称构成语法短语时,省略标签。将原本标签中的前置词移至基础名称中。
swift
// 良好示例 — 读起来像"add subview y"
view.addSubview(y)
// 不良示例 — 冗余标签破坏了短语结构
view.add(subview: y)值保留类型转换。当初始化器执行值保留(拓宽)转换时,省略首个参数标签。
swift
// 良好示例 — 拓宽转换,无标签
let value = Int64(someUInt32)
let str = String(someCharacter)
// 窄化或有损转换需保留标签
let approx = Int64(truncating: someDecimal)
let str = String(describing: someObject)无法区分的参数。当所有参数无法有效区分时,省略所有标签。
swift
// 良好示例 — 参数是对等的
let smaller = min(x, y)
zip(sequence1, sequence2)When to use a prepositional label
何时使用介词标签
Prepositional phrase rule. When the first argument completes a prepositional phrase with the base name, label it with the preposition.
swift
// GOOD — "remove boxes having length 12"
x.removeBoxes(havingLength: 12)
// GOOD — "fade from red"
view.fade(from: red)
// GOOD — "relative path from root"
path.relativePath(from: root)Exception — abstraction boundary. When the first two arguments represent parts of a single abstraction, fold the preposition into the base name so each component gets its own label.
swift
// GOOD — x and y are parts of a single abstraction (a point)
a.moveTo(x: b, y: c)
// BAD — preposition attaches to first arg, leaving y unlabeled
a.move(toX: b, y: c)介词短语规则(Prepositional phrase rule)。当首个参数与基础名称构成介词短语时,用介词作为标签。
swift
// 良好示例 — "remove boxes having length 12"
x.removeBoxes(havingLength: 12)
// 良好示例 — "fade from red"
view.fade(from: red)
// 良好示例 — "relative path from root"
path.relativePath(from: root)例外情况 — 抽象边界。当前两个参数代表单一抽象的组成部分时,将介词融入基础名称,使每个组件都有自己的标签。
swift
// 良好示例 — x和y是单一抽象(点)的组成部分
a.moveTo(x: b, y: c)
// 不良示例 — 介词附加到首个参数,导致y无标签
a.move(toX: b, y: c)Default: label everything else
默认规则:为其他所有参数添加标签
When no special rule above applies, label the argument.
swift
// GOOD
array.split(maxSplits: 2)
button.setTitle("OK", for: .normal)
controller.dismiss(animated: true)
array.sorted(by: >)当上述特殊规则均不适用时,为参数添加标签。
swift
// 良好示例
array.split(maxSplits: 2)
button.setTitle("OK", for: .normal)
controller.dismiss(animated: true)
array.sorted(by: >)Argument label decision table
参数标签决策表
| Situation | Rule | Example |
|---|---|---|
| First arg completes grammatical phrase | Omit label, merge words into base name | |
| Value-preserving init conversion | Omit first label | |
| Arguments are indistinguishable peers | Omit all labels | |
| First arg completes prepositional phrase | Label with preposition | |
| First two args form a single abstraction | Fold preposition into base name | |
| Everything else | Label it | |
For extended examples and edge cases, see references/argument-labels-and-parameters.md.
| 场景 | 规则 | 示例 |
|---|---|---|
| 首个参数构成语法短语 | 省略标签,将词汇合并到基础名称中 | |
| 值保留初始化转换 | 省略首个标签 | |
| 参数是无法区分的对等项 | 省略所有标签 | |
| 首个参数构成介词短语 | 用介词作为标签 | |
| 前两个参数构成单一抽象 | 将介词融入基础名称 | |
| 其他所有情况 | 添加标签 | |
如需扩展示例和边缘案例,请参考references/argument-labels-and-parameters.md。
Side-Effect Naming
副作用命名
Name functions and methods by their side effects.
根据函数和方法的副作用进行命名。
Functions with side effects — imperative verbs
有副作用的函数 — 祈使动词
When a function mutates state, name it as an imperative verb phrase.
swift
// Mutates — imperative verb
array.sort()
array.append(newElement)
list.remove(at: index)
timer.invalidate()当函数会修改状态时,将其命名为祈使动词短语。
swift
// 修改状态 — 祈使动词
array.sort()
array.append(newElement)
list.remove(at: index)
timer.invalidate()Functions without side effects — nouns or adjective phrases
无副作用的函数 — 名词或形容词短语
When a function returns a result without mutating anything, name it as a noun phrase, adjective phrase, or read as a description of what it returns.
swift
// Pure — noun/description
let d = point.distance(to: origin)
let area = rect.intersection(other)
let line = text.trimmingCharacters(in: .whitespaces)当函数返回结果但不修改任何内容时,将其命名为名词短语、形容词短语,或描述其返回内容的短语。
swift
// 纯函数 — 名词/描述性短语
let d = point.distance(to: origin)
let area = rect.intersection(other)
let line = text.trimmingCharacters(in: .whitespaces)Boolean properties and methods
布尔属性和方法
Boolean properties and methods read as assertions about the receiver.
swift
// GOOD — reads as "line is empty"
line.isEmpty
set.contains(element)
url.isFileURL
// BAD — not an assertion
line.empty // verb? adjective?
set.includes // incomplete phraseFor more examples, see references/side-effects-and-mutating-pairs.md.
布尔属性和方法应读起来像是对接收者的断言。
swift
// 良好示例 — 读起来像"line is empty"
line.isEmpty
set.contains(element)
url.isFileURL
// 不良示例 — 不是断言
line.empty // 动词?形容词?
set.includes // 短语不完整如需更多示例,请参考references/side-effects-and-mutating-pairs.md。
Mutating and Nonmutating Pairs
可变与不可变方法对
When an operation has both mutating and nonmutating variants, name them as a pair.
当一个操作同时存在可变和不可变变体时,将它们命名为一对。
Verb-described operations — -ed/-ing suffix
动词描述的操作 — -ed/-ing后缀
When the operation is naturally described by a verb:
- Mutating: imperative verb (,
sort,append)reverse - Nonmutating: past participle or present participle
-ed-ing
Default to (past participle). When is ungrammatical — typically when the verb does not form a natural past participle, or when adding produces an awkward phrase — use (present participle) instead.
-ed-ed-ed-ing| Mutating | Nonmutating | Why |
|---|---|---|
| | |
| | |
| | |
| | |
当操作自然地用动词描述时:
- 可变方法:祈使动词(、
sort、append)reverse - 不可变方法:过去分词或现在分词
-ed-ing
默认使用(过去分词)。当不符合语法时(通常是动词无法自然构成过去分词,或添加后短语显得生硬),改用(现在分词)。
-ed-ed-ed-ing| 可变方法 | 不可变方法 | 原因 |
|---|---|---|
| | |
| | |
| | |
| | |
Noun-described operations — form- prefix
名词描述的操作 — form-前缀
When the operation is naturally described by a noun:
- Nonmutating: the noun itself (,
union)intersection - Mutating: prefix (
form,formUnion)formIntersection
swift
// Nonmutating — returns new value
let combined = a.union(b)
// Mutating — modifies in place
a.formUnion(b)当操作自然地用名词描述时:
- 不可变方法:名词本身(、
union)intersection - 可变方法:前缀(
form、formUnion)formIntersection
swift
// 不可变方法 — 返回新值
let combined = a.union(b)
// 可变方法 — 原地修改
a.formUnion(b)Factory methods — make- prefix
工厂方法 — make-前缀
Factory methods that create a new value start with .
makeswift
let iterator = collection.makeIterator()
let buffer = parser.makeBuffer()创建新值的工厂方法以开头。
makeswift
let iterator = collection.makeIterator()
let buffer = parser.makeBuffer()Pair decision table
方法对决策表
| Operation described by | Mutating name | Nonmutating name | Example pair |
|---|---|---|---|
| Verb (default) | verb | verb + | |
Verb ( | verb | verb + | |
| Noun | | noun | |
For the full -ed/-ing decision tree and stdlib examples, see references/side-effects-and-mutating-pairs.md.
| 操作描述方式 | 可变方法名称 | 不可变方法名称 | 示例对 |
|---|---|---|---|
| 动词(默认) | 动词 | 动词 + | |
动词( | 动词 | 动词 + | |
| 名词 | | 名词 | |
如需完整的-ed/-ing决策树和标准库示例,请参考references/side-effects-and-mutating-pairs.md。
Documentation Comments
文档注释
Every public declaration must have a documentation comment.
每个公共声明都必须有文档注释。
Summary rules by declaration kind
按声明类型制定的摘要规则
| Declaration | Summary describes |
|---|---|
| Function / method | What it does and what it returns |
| Subscript | What it accesses |
| Initializer | What it creates |
| Type / property / variable | What it is |
Write summaries as a single sentence fragment, beginning with a verb (for actions) or a noun phrase (for entities), ending in a period.
swift
/// Returns the element at the specified index.
func element(at index: Int) -> Element { ... }
/// The number of elements in the collection.
var count: Int { ... }
/// Creates a new array with the given elements.
init(_ elements: some Sequence<Element>) { ... }
/// Accesses the element at the specified position.
subscript(index: Int) -> Element { ... }| 声明类型 | 摘要描述内容 |
|---|---|
| 函数/方法 | 功能和返回值 |
| 下标 | 访问的内容 |
| 初始化器 | 创建的对象 |
| 类型/属性/变量 | 是什么 |
摘要写为单个句子片段,以动词(针对操作)或名词短语(针对实体)开头,以句号结尾。
swift
/// 返回指定索引处的元素。
func element(at index: Int) -> Element { ... }
/// 集合中的元素数量。
var count: Int { ... }
/// 使用给定元素创建一个新数组。
init(_ elements: some Sequence<Element>) { ... }
/// 访问指定位置的元素。
subscript(index: Int) -> Element { ... }Symbol markup
符号标记
Use standard symbol markup after the summary when relevant:
- for individual parameters
- Parameter name: - block for multiple parameters
- Parameters: - for the return value
- Returns: - for errors thrown
- Throws: - for algorithmic complexity
- Complexity:
swift
/// Removes and returns the element at the specified position.
///
/// - Parameter index: The position of the element to remove.
/// - Returns: The removed element.
/// - Complexity: O(*n*), where *n* is the length of the collection.
mutating func remove(at index: Int) -> Element { ... }相关情况下,在摘要后使用标准符号标记:
- 用于单个参数
- Parameter name: - 块用于多个参数
- Parameters: - 用于返回值
- Returns: - 用于抛出的错误
- Throws: - 用于算法复杂度
- Complexity:
swift
/// 移除并返回指定位置的元素。
///
/// - Parameter index: 要移除的元素的位置。
/// - Returns: 被移除的元素。
/// - Complexity: O(*n*),其中*n*是集合的长度。
mutating func remove(at index: Int) -> Element { ... }O(1) complexity rule
O(1)复杂度规则
Document the complexity of any computed property that is not O(1). Callers assume properties are O(1) by default. If a property does more than constant-time work, state the complexity explicitly.
swift
/// The total weight of all items.
///
/// - Complexity: O(*n*), where *n* is the number of items.
var totalWeight: Double {
items.reduce(0) { $0 + $1.weight }
}For documentation patterns and examples, see references/conventions-and-special-rules.md.
记录任何非O(1)复杂度的计算属性。调用者默认认为属性是O(1)复杂度。如果属性的操作时间不是常数级,请明确说明其复杂度。
swift
/// 所有物品的总重量。
///
/// - Complexity: O(*n*),其中*n*是物品的数量。
var totalWeight: Double {
items.reduce(0) { $0 + $1.weight }
}如需文档模式和示例,请参考references/conventions-and-special-rules.md。
Clarity and Naming
清晰度与命名
Clarity at the point of use is the most important goal. Every design decision serves the person reading a call site.
Clarity over brevity. Longer names are acceptable when they remove ambiguity. Do not abbreviate.
swift
// GOOD
employees.remove(at: position)
// BAD — ambiguous: remove the element? remove at position?
employees.remove(position)Include words needed to avoid ambiguity. If omitting a word makes the call site unclear, keep it.
swift
// GOOD — "at" clarifies the argument's role
friends.remove(at: index)
// BAD — is "index" the element to remove or the position?
friends.remove(index)Omit needless words. Do not repeat type information already available from the context.
swift
// GOOD
allViews.remove(cancelButton)
// BAD — "Element" repeats the type
allViews.removeElement(cancelButton)Name variables and parameters by role, not type. Use the entity's role in the current context, not its type name.
swift
// GOOD — describes the role
var greeting: String
func add(_ observer: NSObject, for keyPath: String)
// BAD — names the type
var string: String
func add(_ object: NSObject, for string: String)Compensate for weak type information. When a parameter type is , , or a fundamental type like or , add role-clarifying words to the name.
AnyAnyObjectIntStringswift
// GOOD — role is clear despite weak types
func addObserver(_ observer: NSObject, forKeyPath path: String)
// BAD — what does "string" mean here?
func add(_ object: NSObject, for string: String)For extended naming examples and patterns, see references/naming-and-clarity.md.
调用点的清晰度是最重要的目标。每个设计决策都服务于阅读调用点的人。
清晰度优先于简洁性。当长名称能消除歧义时,使用长名称是可接受的。请勿缩写。
swift
// 良好示例
employees.remove(at: position)
// 不良示例 — 歧义:移除元素?还是移除position位置的元素?
employees.remove(position)添加避免歧义所需的词汇。如果省略某个词汇会使调用点不清晰,请保留该词汇。
swift
// 良好示例 — "at"明确了参数的作用
friends.remove(at: index)
// 不良示例 — "index"是要移除的元素还是位置?
friends.remove(index)省略不必要的词汇。不要重复上下文已有的类型信息。
swift
// 良好示例
allViews.remove(cancelButton)
// 不良示例 — "Element"重复了类型
allViews.removeElement(cancelButton)按角色而非类型命名变量和参数。使用实体在当前上下文中的角色,而非其类型名称。
swift
// 良好示例 — 描述角色
var greeting: String
func add(_ observer: NSObject, for keyPath: String)
// 不良示例 — 命名类型
var string: String
func add(_ object: NSObject, for string: String)弥补弱类型信息。当参数类型为、或、等基础类型时,在名称中添加明确角色的词汇。
AnyAnyObjectIntStringswift
// 良好示例 — 尽管类型较弱,但角色清晰
func addObserver(_ observer: NSObject, forKeyPath path: String)
// 不良示例 — "string"在这里是什么意思?
func add(_ object: NSObject, for string: String)如需扩展命名示例和模式,请参考references/naming-and-clarity.md。
Fluent Usage and Protocols
流畅用法与协议
Call sites read as grammatical English. Prefer names that form grammatical phrases at the point of use.
swift
// GOOD — reads fluently
x.insert(y, at: z) // "x, insert y at z"
x.subviews.remove(at: i) // "x's subviews, remove at i"
x.makeIterator() // "x, make iterator"
// BAD — ungrammatical
x.insert(y, position: z)
x.subviews.remove(i)Initializer first argument. The first argument to an initializer should not form a phrase continuing the type name.
swift
// GOOD
let foreground = Color(red: 32, green: 64, blue: 128)
// BAD — "Color with red" reads awkwardly
let foreground = Color(havingRGBValuesRed: 32, green: 64, blue: 128)Protocol naming conventions:
| Protocol describes | Naming pattern | Examples |
|---|---|---|
| What something is | Noun | |
| A capability | | |
调用点读起来像符合语法的英语。优先选择在调用点能构成语法短语的名称。
swift
// 良好示例 — 读起来流畅
x.insert(y, at: z) // "x, insert y at z"
x.subviews.remove(at: i) // "x's subviews, remove at i"
x.makeIterator() // "x, make iterator"
// 不良示例 — 不符合语法
x.insert(y, position: z)
x.subviews.remove(i)初始化器首个参数。初始化器的首个参数不应与类型名称构成连续短语。
swift
// 良好示例
let foreground = Color(red: 32, green: 64, blue: 128)
// 不良示例 — "Color with red"读起来生硬
let foreground = Color(havingRGBValuesRed: 32, green: 64, blue: 128)协议命名约定:
| 协议描述内容 | 命名模式 | 示例 |
|---|---|---|
| 描述事物是什么 | 名词 | |
| 描述能力 | | |
General Conventions
通用约定
Casing. Types and protocols use . Everything else uses . Acronyms that are commonly all-caps in American English appear uniformly upper- or lower-cased based on position.
UpperCamelCaselowerCamelCaseswift
var utf8Bytes: [UTF8.CodeUnit]
var isRepresentableAsASCII = true
var userSMTPServer: SMTPServerMethods and properties over free functions. Prefer methods and properties. Use free functions only when:
- There is no obvious —
selfmin(x, y) - The function is an unconstrained generic —
print(value) - The function syntax is established domain notation —
sin(x)
Default arguments over method families. Prefer a single method with default parameters over a family of methods that differ only in which parameters they accept. Place defaulted parameters at the end. Parameters with default values should always have argument labels — defaulted parameters are usually omitted at call sites, so their labels must be clear when they do appear.
swift
// GOOD — labeled with defaults
func decode(_ data: Data, encoding: String.Encoding = .utf8) -> String?
// BAD — method family
func decode(_ data: Data) -> String?
func decode(_ data: Data, encoding: String.Encoding) -> String?Overload safety. Methods may share a base name when they operate in different type domains or when their meaning is clear from context. Avoid return-type-only overloads that cause ambiguity at the call site.
For casing edge cases, overload patterns, and tuple/closure naming, see references/conventions-and-special-rules.md.
大小写。类型和协议使用。其他所有元素使用。在美国英语中通常全大写的首字母缩写词,根据位置统一使用大写或小写。
UpperCamelCaselowerCamelCaseswift
var utf8Bytes: [UTF8.CodeUnit]
var isRepresentableAsASCII = true
var userSMTPServer: SMTPServer优先使用方法和属性而非自由函数。优先选择方法和属性。仅在以下情况使用自由函数:
- 没有明显的—
selfmin(x, y) - 函数是无约束泛型 —
print(value) - 函数语法是已确立的领域符号 —
sin(x)
优先使用默认参数而非方法族。优先选择带有默认参数的单个方法,而非仅在参数接受上有差异的方法族。将带默认值的参数放在末尾。带默认值的参数应始终有参数标签 — 默认参数通常在调用点被省略,因此当它们出现时,标签必须清晰。
swift
// 良好示例 — 带标签和默认值
func decode(_ data: Data, encoding: String.Encoding = .utf8) -> String?
// 不良示例 — 方法族
func decode(_ data: Data) -> String?
func decode(_ data: Data, encoding: String.Encoding) -> String?重载安全性。当方法在不同类型域中操作,或其含义从上下文清晰可见时,可共享基础名称。避免仅返回类型不同的重载,以免在调用点造成歧义。
如需大小写边缘案例、重载模式以及元组/闭包命名,请参考references/conventions-and-special-rules.md。
Common Mistakes
常见错误
-
Omitting needed argument labels. Usinginstead of
remove(position)when the role of the argument is ambiguous without the label.remove(at: position) -
Using -ed when -ing is correct. Applyingwhen the past participle is ungrammatical — use
stripped()instead. Test: does "a [verb]-ed [noun]" read naturally?stripping() -
Using verb names for side-effect-free operations. Naming a nonmutating methodthat returns a new collection — use
sort()to signal no mutation.sorted() -
Naming by type instead of role. Usinginstead of
string, orgreetinginstead ofarray, when the role would be more informative.elements -
Missing documentation comments. Leaving public declarations undocumented, or writing summaries that describe the implementation rather than the purpose.
-
Not documenting non-O(1) computed properties. Exposing a linear-time computed property without anote, causing callers to assume O(1) and use it in loops.
Complexity: -
Applying form- prefix to verb-based operations. Writinginstead of just
formSort()— thesort()prefix is only for noun-based operations (form).formUnion -
Factory methods without make- prefix. Naming factory methods asor
createIterator()instead ofbuildBuffer()andmakeIterator().makeBuffer() -
Repeating type information in names. Writingor
removeElement(cancelButton)when the type is already evident from context.stringValue: String -
Return-type-only overloads. Defining overloads that differ only in return type, creating ambiguity when the compiler cannot infer the expected type.
-
Unlabeled tuple members and closure parameters. Exposing tuples or closures in public API without naming their components, forcing callers to use positional access.
- 省略必要的参数标签。当参数的作用没有标签会产生歧义时,使用而非
remove(position)。remove(at: position) - 在应使用-ing时使用-ed。当过去分词不符合语法时使用— 应改用
stripped()。测试:“a [verb]-ed [noun]”读起来是否自然?stripping() - 为无副作用的操作使用动词名称。将返回新集合的不可变方法命名为— 应使用
sort()来表示无修改。sorted() - 按类型而非角色命名。当角色更具信息性时,使用而非
string,或greeting而非array。elements - 缺少文档注释。公共声明未编写文档,或摘要描述的是实现而非用途。
- 未记录非O(1)的计算属性。暴露线性时间的计算属性但未添加注释,导致调用者默认认为是O(1)并在循环中使用。
Complexity: - 将form-前缀应用于动词描述的操作。编写而非
formSort()—sort()前缀仅适用于名词描述的操作(form)。formUnion - 工厂方法未使用make-前缀。将工厂方法命名为或
createIterator()而非buildBuffer()和makeIterator()。makeBuffer() - 在名称中重复类型信息。当类型已从上下文明显可知时,编写或
removeElement(cancelButton)。stringValue: String - 仅返回类型不同的重载。定义仅返回类型不同的重载,导致编译器无法推断预期类型时产生歧义。
- 未标记的元组成员和闭包参数。在公共API中暴露元组或闭包但未命名其组件,迫使调用者使用位置访问。
Review Checklist
评审检查清单
Argument Labels
参数标签
- First argument follows the correct label rule (grammatical phrase, prepositional, conversion, or labeled)
- Prepositional labels do not incorrectly group independent arguments
- Value-preserving conversion initializers omit the first label
- All non-special-case arguments have labels
- 首个参数遵循正确的标签规则(语法短语、介词短语、转换或添加标签)
- 介词标签未错误地分组独立参数
- 值保留转换初始化器省略了首个标签
- 所有非特殊情况的参数都有标签
Naming Semantics
命名语义
- Mutating methods use imperative verb form
- Nonmutating methods use -ed/-ing or noun form
- Mutating/nonmutating pairs follow the correct pattern (verb pair or noun/form-noun pair)
- Boolean properties read as assertions (,
isEmpty,isValid)contains - Variables and parameters are named by role, not type
- 可变方法使用祈使动词形式
- 不可变方法使用-ed/-ing或名词形式
- 可变/不可变方法对遵循正确的模式(动词对或名词/form-名词对)
- 布尔属性读起来像是断言(、
isEmpty、isValid)contains - 变量和参数按角色而非类型命名
Documentation
文档
- Every public declaration has a doc comment
- Summaries are single sentence fragments ending in a period
- Summaries describe the correct thing per declaration kind (action, access, creation, entity)
- Non-O(1) computed properties document their complexity
- Parameters, return values, and thrown errors are documented with symbol markup
- 每个公共声明都有文档注释
- 摘要是单个句子片段并以句号结尾
- 摘要按声明类型描述正确的内容(操作、访问、创建、实体)
- 非O(1)的计算属性记录了其复杂度
- 参数、返回值和抛出的错误使用符号标记记录
Conventions
约定
- Types and protocols use UpperCamelCase; everything else uses lowerCamelCase
- Acronyms are uniformly cased based on position
- Default arguments are preferred over method families
- Overloads do not differ only in return type
- Protocol names follow the noun (is-a) or suffix (capability) convention
- 类型和协议使用UpperCamelCase;其他所有元素使用lowerCamelCase
- 首字母缩写词根据位置统一大小写
- 优先使用默认参数而非方法族
- 重载并非仅返回类型不同
- 协议名称遵循名词(是一种)或后缀(能力)约定
References
参考资料
- Naming clarity, role-based naming, weak-type compensation, and terminology: references/naming-and-clarity.md
- Argument label edge cases, parameter naming, and default argument strategy: references/argument-labels-and-parameters.md
- Side-effect naming examples, -ed/-ing decision tree, form- prefix patterns, and factory methods: references/side-effects-and-mutating-pairs.md
- Casing edge cases, complexity documentation, overload safety, tuple/closure naming, and free function exceptions: references/conventions-and-special-rules.md
- 命名清晰度、基于角色的命名、弱类型弥补和术语规范:references/naming-and-clarity.md
- 参数标签边缘案例、参数命名和默认参数策略:references/argument-labels-and-parameters.md
- 副作用命名示例、-ed/-ing决策树、form-前缀模式和工厂方法:references/side-effects-and-mutating-pairs.md
- 大小写边缘案例、复杂度文档、重载安全性、元组/闭包命名和自由函数例外情况:references/conventions-and-special-rules.md