erlang编程规范

来源:互联网 发布:js 获取style display 编辑:程序博客网 时间:2024/05/16 17:52

http://www.erlang.se/doc/programming_rules.shtml


3 SW Engineering Principles
    3.1 Export as few functions as possible from a module
    3.2 Try to reduce intermodule dependencies
    3.3 Put commonly used code into libraries
    3.4 Isolate "tricky" or "dirty" code into separate modules
    3.5 Don't make assumptions about what the caller will do with the results of a function
    3.6 Abstract out common patterns of code or behavior
    3.7 Top-down
    3.8 Don't optimize code
    3.9 Use the principle of "least astonishment"
    3.10 Try to eliminate side effects
    3.11 Don't allow private data structure to "leak" out of a module
    3.12 Make code as deterministic as possible
    3.13 Do not program "defensively"
    3.14 Isolate hardware interfaces with a device driver
    3.15 Do and undo things in the same function
4 Error Handling
    4.1 Separate error handling and normal case code
    4.2 Identify the error kernel
5 Processes, Servers and Messages
    5.1 Implement a process in one module
    5.2 Use processes for structuring the system
    5.3 Registered processes
    5.4 Assign exactly one parallel process to each true concurrent activity in the system
    5.5 Each process should only have one "role"
    5.6 Use generic functions for servers and protocol handlers wherever possible
    5.7 Tag messages
    5.8 Flush unknown messages
    5.9 Write tail-recursive servers
    5.10 Interface functions
    5.11 Time-outs
    5.12 Trapping exits
6 Various Erlang Specific Conventions
    6.1 Use records as the principle data structure
    6.2 Use selectors and constructors
    6.3 Use tagged return values
    6.4 Use catch and throw with extreme care
    6.5 Use the process dictionary with extreme care
    6.6 Don't use import
    6.7 Exporting functions
7 Specific Lexical and Stylistic Conventions
    7.1 Don't write deeply nested code
    7.2 Don't write very large modules
    7.3 Don't write very long functions
    7.4 Don't write very long lines
    7.5 Variable names
    7.6 Function names
    7.7 Module names
    7.8 Format programs in a consistent manner
8 Documenting Code
    8.1 Attribute code
    8.2 Provide references in the code to the specifications
    8.3 Document all the errors
    8.4 Document all the principle data structures in messages
    8.5 Comments
    8.6 Comment each function
    8.7 Data structures
    8.8 File headers, copyright
    8.9 File headers, revision history
    8.10 File Header, description
    8.11 Do not comment out old code - remove it
    8.12 Use a source code control system

原创粉丝点击