FIT9131 Coding Guidelines
FIT9131 编码准则
1. Naming 1. 命名
1.1 Use descriptive names for all identifiers (names of variables, methods, and classes).
1.1 对所有标识符(变量、方法和类的名称)使用描述性名称。
1.2 Avoid abbreviations and ambiguity. For example, use number instead of num or no.
1.2 避免缩写和歧义。例如,使用 number 而不是 num 或 no
1.3 Use camel case for names with multiple words to increase readability. With camel case the second and subsequent words begin with a capital letter. For example, numberOfItems.
1.3 对包含多个单词的名称使用驼峰式大小写以提高可读性。使用 camel case,第二个和后续单词以大写字母开头。例如,numberOfItems。
See below further guidelines for specific naming of variables, methods, and classes.
有关变量、方法和类的特定命名,请参阅下面的进一步指南。
2. Operators: 2. 操作员:
2.1 When defining expressions using operators, there should be a single space before and after the operator for the following types of operators: arithmetic (+, -, *, /, %), relational (>, >=, <, <=, ==, !=), logical (&&, ||, !), conditional ( ? :), assignment (=), and compound assignment (= += -= *= /= %=).
2.1 使用运算符定义表达式时,以下类型的运算符在运算符前后应有一个空格:算术 (+, -, *, /, %)、关系 (+, -, *, /, %)、关系 (+>、>=、<、<=、==、!=)、逻辑 (&&、||、!)、条件 ( ? :)、赋值 (=) 和复合赋值 (= += -= *= /= %=)。
3. Variables: 3. 变量:
3.1 Fields must only be initialised in the constructor, unless they are static or final.
3.1 字段只能在构造函数中初始化,除非它们是 static 或 final。
3.2 Local variables must be initialised when they are declared.
3.2 局部变量必须在声明时初始化。
3.3 The use of public fields must be justified.
3.3 使用公共字段必须有正当理由。
3.4 Variable names must use camel casing with the first character always in lowercase.
3.4 变量名称必须使用驼峰式大小写,第一个字符始终为小写。
3.5 Variable names must not contain an underscore ( _ ) (except final variables).
3.5 变量名称不得包含下划线 ( _ ) (final variables 除外)。
3.6 Final variables must be in all capital letters and must use an underscore to split up multiple words in the name.
3.6 final 变量必须全部大写,并且必须使用下划线分隔名称中的多个单词。
4. Methods: 4. 方法:
4.1 Methods must have exactly one blank line between each method, and between the start and end of the class's delimiter ({ })'s.
4.1 方法在每个方法之间以及类的分隔符 ({ }) 的开头和结尾之间必须只有一个空行。
4.2 Method names must be or contain action verbs. Names should be descriptive and convey a high level idea of the purpose of the method.
4.2 方法名称必须是或包含动作动词。名称应该是描述性的,并传达方法目的的高级概念。
4.3 Method names must use camel casing with the first character always lowercase.
4.3 方法名称必须使用驼峰式大小写,第一个字符始终小写。
4.4 Methods must be sorted alphabetically (except constructors, which always appear first).
4.4 方法必须按字母顺序排序(构造函数除外,它总是首先出现)。
4.5 Simple mutator methods should be named setSomething and accessor methods should be named getSomething. Accessor methods with boolean return values are often called isSomething
4.5 简单的 mutator 方法应该命名为 setSomething,访问器方法应该命名为 getSomething。具有布尔返回值的访问器方法通常称为 isSomething.
5. Classes: 5. 类别:
5.1 Class names must be nouns and must be singular.
5.1 类名必须是名词,并且必须是单数。
5.2 Class names must follow camel casing with the first character always uppercase.
5.2 类名必须跟在 Camel 大小写之后,第一个字符始终大写。
5.3 Each file must only contain one class definition.
5.3 每个文件只能包含一个类定义。
5.4 A complete class template must include:
5.4 完整的类模板必须包括:
one default constructor 一个默认构造函数
at least one non-default constructor (if the class has fields)
至少一个非默认构造函数(如果类具有字段)accessors for each field 每个字段的访问器
mutators for each field 每个字段的 mutators
a display/toString method.
display/toString 方法。
5.5 The components of a class must be defined in the following order: fields, constructors, methods
5.5 类的组件必须按以下顺序定义:字段、构造函数、方法
6. Brackets and indentation:
6. 括号和缩进:
6.1 All code within a specific block must have exactly one indent. One indent is equal to one tab or four spaces.
6.1 特定块中的所有代码必须只有一个缩进。1 次缩进等于 1 个制表符或 4 个空格。
6.2 The placement of { }'s to start and end a block must appear on their own line. Opening braces ({) especially should not be placed on the same line as the header.
6.2 用于开始和结束块的 { } 的位置必须出现在它们自己的行上。左大括号 ({) 尤其不应与 Headers 放在同一行。
7. Code: 7. 代码:
7.1 Access modifiers are not optional and must be explicitly defined for methods and fields.
7.1 访问修饰符不是可选的,必须为方法和字段显式定义。
7.2 The maximum code line length should be 80 characters. To prevent code going off the screen, consider breaking the code across multiple lines.
7.2 代码行长度上限为 80 个字符。为了防止代码脱离屏幕,请考虑跨多行中断代码。
7.3 Any code that has been copied from another source must be otherwise appropriately credited.
7.3 任何从其他来源复制的代码必须以其他方式适当注明出处。
8. Documentation: 8. 文档:
8.1 Every class should have a comment at the top, which should include a general description of the class, the author's name and version number.
8.1 每个类的顶部都应该有一个注释,其中应包括类的一般描述、作者的姓名和版本号。
8.2 Every person who has contributed to a class must be named as an author or must be otherwise appropriately credited.
8.2 每个为课程做出贡献的人都必须被命名为作者,或者必须以其他方式适当地注明。
8.3 Every method should have a comment at the top with a general description of the method.
8.3 每个方法的顶部都应该有一个注释,其中包含该方法的一般描述。
8.4 Inline comments should only be included where they are necessary to explain a key concept. Excessive inline comments must be avoided as they affect code readability.
8.4 内嵌注释应仅在解释关键概念所必需的情况下包含。必须避免过多的内联注释,因为它们会影响代码的可读性。
The above is a finite list of conventions that must be followed when programming in this unit. Failing to adhere to these standards will generally cost marks on all assessed submissions after this module.
以上是在本单元中编程时必须遵循的约定的有限列表。不遵守这些标准通常会在本模块之后的所有评估提交中扣分。