美文网首页SAP
一份我们团队Java开发的开发规范,参考了阿里巴巴Java开发手

一份我们团队Java开发的开发规范,参考了阿里巴巴Java开发手

作者: _扫地僧_ | 来源:发表于2021-03-12 09:53 被阅读0次

    编程规约

    1. For variable name, always use English with lowerCamelCase.

    space in comment:

    bad example:

    Suggestion: 与其“半吊子”英文来注释,不如用中文注释把问题说清楚。专有名词与关键字保持英文原文即可。

    谨慎注释掉代码。在上方详细说明,而不是简单地注释掉。如果无用,则删除。 说明:代码被注释掉有两种可能性:1)后续会恢复此段代码逻辑。2)永久不用。前者如果没有备注信息,难以知晓注释动机。后者建议直接删掉(代码仓库保存了历史代码)。

    1. Do not mix production code with test code. All testing codes must be put to folder src\test\java.

    2. Constant:




    1. For boolean variable in POJO, no "is" prefix is allowed.

    2. Always use meaningful naming for self-descriptive purpose.

    Bad example: no prefix for local variable.


    1. Naming per layer

    1. Bracket usage
    if( XXX ){
        yyy;    
    }
    
    if( XXX ){
        yyy;
    } else{
        
    }
    

    1. space usage

    bad example:

    space between method and argument:

    bad example:


    1. new line usage

    guideline:

    bad example:


    1. text file encoding

    IDE text file encoding: UTF-8; IDE new line format: use Unix instead of Windows
    IDE setting:

    why we should set this property


    1. basic type and wrapper object

    1. No business logic is allowed in constructor. If initialization logic is needed, put it in init().

    2. class method sequence

    public method > protected > private > getter / setter


    1. No business logic in setter/getter

    1. Bracket is mandatory in if/else/for/while/do.

    Bad example:

    if (condition) statements;
    

    Better to use if XXX return; instead of if XXX else YYY:

    参考文档

    阿里巴巴Java开发手册终极版v1.3.0

    更多Jerry的原创文章,尽在:"汪子熙":


    相关文章

      网友评论

        本文标题:一份我们团队Java开发的开发规范,参考了阿里巴巴Java开发手

        本文链接:https://www.haomeiwen.com/subject/ijygwktx.html