Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

让你最快速地改善代码质量的 20 条编程规范(上) #25

Open
NewBrandSTONE opened this issue Feb 17, 2020 · 0 comments
Open

Comments

@NewBrandSTONE
Copy link
Owner

命名

  1. 命名多长合适?

    • 在足够表达其含义的情况下,命名越短越好。
    • 特殊词汇, sec 表示 second、 str 表示 string、num 表示 number、doc 表示 document 等等可以使用缩写。
    • 作用域比较小也可以使用段命名,相反使用长命名。
    • **命名能准确表达目的。**学会换位思考,如果不熟悉的同事能看懂就说明可以。
  2. 利用上下文简化命名

    • User 类里面的属性、方法名不需要再加上 User 前缀。
  3. 命名要可读、可搜索

    • 不要使用偏僻英文单词来命名。
    • 统一使用 selectXXX 就不要再使用 queryXXX,拥有统一的规约。
  4. 命名接口和抽象类

    • 接口使用 IUserService 命名,对应实现类为 UserService;另外一种是接口不使用前缀,实现类使用 UserServiceImpl。
    • 使用 Abstract 命名抽象类
    • 关键是命名统一约束
  5. 注释

    • 注释内容表示这个类是做什么、为什么、怎么做
    • 类和函数一定要写注释。
    • 注释不是越多越好。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant