blob: a8c7b603959e73b29a29c4094a8ba42dcf91a3d1 [file] [log] [blame] [view]
Konrad Grochowski3bc64242015-02-04 16:43:26 +01001# Thrift Coding Standards
2
3 Any fool can write code that a computer can understand.
4 Good programmers write code that humans can understand.
5 -- Martin Fowler, 1999
6
7The purpose of this document is to make everyone's life easier.
8
PoojaChandak20205b82020-11-06 11:33:40 +01009It's easier when you read good, well-formatted, with a clearly defined purpose, code.
Konrad Grochowski3bc64242015-02-04 16:43:26 +010010But the only way to read clean code is to write such.
11
12This document can help achieve that, but keep in mind that
13those are not silver-bullet, fix-all-at-once rules. Just think about readability while writing code.
PoojaChandak20205b82020-11-06 11:33:40 +010014Write code like you would have to read it ten years from now.
Konrad Grochowski3bc64242015-02-04 16:43:26 +010015
16## General Coding Standards
17
18Thrift has some history. Not all existing code follows those rules.
19But we want to improve over time.
PoojaChandak20205b82020-11-06 11:33:40 +010020When making a small change / bugfix - like a single line fix - do *not* refactor the whole function.
Konrad Grochowski3bc64242015-02-04 16:43:26 +010021That disturbs code repository history.
22Whenever adding something new and / or making bigger refactoring
23 - follow those rules as strictly as you can.
24
25When in doubt - contact other developers (using dev@ mailing list or IRC).
26Code review is the best way to improve readability.
27
28### Basics
PoojaChandak20205b82020-11-06 11:33:40 +010029 * Use spaces, not tabs
Konrad Grochowski3bc64242015-02-04 16:43:26 +010030 * Use only ASCII characters in file and directory names
PoojaChandak20205b82020-11-06 11:33:40 +010031 * Commit to the repository using Unix-style line endings (LF)
Konrad Grochowski3bc64242015-02-04 16:43:26 +010032 On Windows:
33 git config core.autocrlf true
34 * Maximum line width - 100 characters
35 * If not specified otherwise in language specific standard - use 2 spaces as indent/tab
36
37### Comments
PoojaChandak20205b82020-11-06 11:33:40 +010038 * Each file has to start with a comment containing [Apache License](http://www.apache.org/licenses/LICENSE-2.0)
39 * Public API of a library should be documented, preferably using format native for language-specific documentation generation tools (Javadoc, Doxygen etc.)
Konrad Grochowski3bc64242015-02-04 16:43:26 +010040 * Other comments are discouraged - comments are lies. When one has to make comment it means one failed to write readable code. Instead of "I should write a comment here" think "I should clean it up"
41 * Do not leave "TODO/FIXME" comments - file [Jira](http://issues.apache.org/jira/browse/THRIFT) issue instead
42
43### Naming
44 Finding proper names is the most important and most difficult task in software development.
45
PoojaChandak20205b82020-11-06 11:33:40 +010046## Language-Specific Coding Standards
Konrad Grochowski3bc64242015-02-04 16:43:26 +010047
48For detailed information see `lib/LANG/coding_standards.md`