Skip to content

Commit

Permalink
[docs] Add code style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao committed Aug 26, 2021
1 parent e94a256 commit f7a86b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ Addax 19890604 1989-06-04 00:00:00 true test
- [online](https://addax.readthedocs.io)
- [project](docs/src/main/sphinx/index.rst)

## Code Style

We recommend you use IntelliJ as your IDE. The code style template for the project can be found in the [codestyle](https://github.com/airlift/codestyle) repository along with our general programming and Java guidelines. In addition to those you should also adhere to the following:

* Alphabetize sections in the documentation source files (both in table of contents files and other regular documentation files). In general, alphabetize methods/variables/sections if such ordering already exists in the surrounding code.
* When appropriate, use the Java 8 stream API. However, note that the stream implementation does not perform well so avoid using it in inner loops or otherwise performance sensitive sections.
* Categorize errors when throwing exceptions. For example, PrestoException takes an error code as an argument, `PrestoException(HIVE_TOO_MANY_OPEN_PARTITIONS)`. This categorization lets you generate reports so you can monitor the frequency of various failures.
* Ensure that all files have the appropriate license header; you can generate the license by running `mvn license:format`.
* Consider using String formatting (printf style formatting using the Java `Formatter` class): `format("Session property %s is invalid: %s", name, value)` (note that `format()` should always be statically imported). Sometimes, if you only need to append something, consider using the `+` operator.
* Avoid using the ternary operator except for trivial expressions.
* Use an assertion from Airlift's `Assertions` class if there is one that covers your case rather than writing the assertion by hand. Over time we may move over to more fluent assertions like AssertJ.
* When writing a Git commit message, follow these [guidelines](https://chris.beams.io/posts/git-commit/).

## License

This software is free to use under the Apache License [Apache license](/LICENSE).
Expand Down
13 changes: 13 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ Addax 19890604 1989-06-04 00:00:00 true test
- [在线文档](https://addax.readthedocs.io)
- [项目内文档](docs/src/main/sphinx/index.rst)

## 代码风格

建议使用 IntelliJ 作为开发 IDE。项目的代码风格模板可以在[codestyle](https://github.com/airlift/codestyle)资源库中找到,还有我们的一般编程和Java指南。除了这些之外,你还应该遵守以下几点。

* 在文档源文件中按字母顺序排列章节(包括目录文件和其他常规文档文件)。一般来说,如果周围的代码中已经存在这样的排序,就按字母顺序排列方法/变量/部分。
* 在适当的时候,使用Java 8的流API。然而,请注意,流的实现并不是很好,所以避免在内循环或其他对性能敏感的部分使用它。
* 在抛出异常时对错误进行分类。例如,AddaxException需要一个错误代码作为参数,`AddaxException(RdbmsReaderErrorCode)`。这种分类可以让你生成报告,这样你就可以监控各种故障的频率。
* 确保所有文件都有适当的许可证头;你可以通过运行`mvn license:format`生成许可证。
* 考虑使用字符串格式化(使用Java`Formatter`类的printf风格格式化):`format("Session property %s is invalid: %s", name, value)`(注意,`format()`应该总是静态导入)。有时,如果你只需要附加一些东西,可以考虑使用`+`运算符。
* 除了琐碎的表达式,避免使用三元操作符。
* 如果有涵盖你的情况的断言,就使用Airlift的`Assertions`类,而不是手工写断言。随着时间的推移,我们可能会转移到更流畅的断言,如AssertJ。
* 在编写Git提交信息时,请遵循这些[指南]https://chris.beams.io/posts/git-commit/)。

## License

This software is free to use under the Apache License [Apache license](/license.txt).
Expand Down

0 comments on commit f7a86b1

Please sign in to comment.