前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >搭建企业级app架构(3)-开发规范

搭建企业级app架构(3)-开发规范

作者头像
用户1974410
发布2022-09-20 16:35:39
2860
发布2022-09-20 16:35:39
举报
文章被收录于专栏:flutter开发精选

介绍

本指南与👉Flutter Coding Guidelines.搭配使用

编码指南

  • DO NOT 不要提交包含warning的代码
  • DO 遵循 S.O.L.I.D. code design principles
  • DO 所有公开 API要写清楚注释
  • DO NOT 不要写辅助的静态方法
  • DO 所有异常案例需要写单元测试
  • 需要100% 测试覆盖率
    • 不要求覆盖所有行, 但是所有逻辑分支需要覆盖 (e.g., switch-case, if-else, etc.)
  • DO NOT 强制展开可选参数
    • You can use optional-chaining, or validate that the content isn’t null
  • DO 移除你能看到的所有dead-code
    • 项目不要出现任何注释掉的代码或者为用到的代码
    • 我们有git版本记录There’s no point thinking “Well, maybe we’ll use this function in the future”. We have commit history for a reason ;)
  • DO NOT 一些情况下不需要指定变量类型
    • Bad:
    • Good:
    • let theUltimateAnswer: int = 42
    • let theUltimateAnswer = 42
    • Rely on type-inference if the language supports this. Example:
  • DO NOT 构造函数尽量不要超过5个参数
  • DO NOT 不要忽略异常
    • Otherwise, you are leaving land-mines for someone else to trip over someday
  • DO NOT generically catch errors
  • DO NOT 不要超出代码行限制 (150 characters)
  • DO NOT 不要超出文件行数限制 (400 lines)
    • Consider breaking up classes and files into smaller pieces, we don’t want huge, monolithic classes
  • DO NOT 函数参数类型要明确不要使用 Pair 或其他类似
    • A nice alternative would be to create a model class, data class, or struct

命名规范

  • DO 命名要描述清楚
    • “Clarity over Brevity”, we aren’t coding on 👉CRT Monitors
    • Examples:

Bad:

Good:

user.ser.excSrv()

user.service.executeService()

  • DO 好的参数名相当于注释
  • DO 包含所有必要的单词
    • DO NOT include useless words, like type / class information
    • Examples:

Bad:

Good:

var string1 = "Good one!"

var successMessage = ...

var string2 = "Ya don' goofed"

var failureMessage = ...

  • DO 布尔值读起来像一个断言
    • Use a question format, such as “is/was/has…?”
    • Examples:

Bad:

Good:

var done = false

var isDone = false

  • DO NOT 不要使用否定判断命名
    • This puts extra cognitive load on future developers
    • Examples:

Bad:

Good:

var isNotDone = true, if isNotDone...

var isDone = false, if !isDone...

  • DO 使用命名惯例
    • This will help keep the codebase as coherent as possible
    • If there is common naming convention in a file or module, please follow the conventions
  • DO NOT 不要使用缩写
    • Acronyms are okay though
    • class BmwPhevInfo { ... is better than class BayerischeMotorenWerkePluginHybridElectricVehicleInfo { ...
    • “Clarity over Brevity”
    • Examples:

Bad:

Good:

var usrIdx = 1

var userIndex = 1


本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-01-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 flutter开发精选 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 介绍
  • 编码指南
    • 命名规范
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档