-
Notifications
You must be signed in to change notification settings - Fork 5.3k
【更新】编码规范 #4990
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
【更新】编码规范 #4990
Conversation
documentation/coding_style_cn.md
Outdated
| - 以 `/**` 开头,以 ` */` 结尾,中间写入函数注释 | ||
| - 第一部分:一个段落介绍函数的作用 | ||
| - 第二部分:参数采用 @param + 参数 + 介绍参数 的方式 | ||
| - 第三部分:返回采用 @return + 返回值 + 介绍返回值 的方式 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 直接介绍返回值即可,不用+返回值,实践过程中发现会有开发者直接写成返回类型
@return + 介绍返回值 的方式
开头大写,末尾加句号
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么意思,RT_EOK for success,这样也不行吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦哦 这种可以, @return + 枚举返回值 + 介绍该返回值的意义 例如 RT_EOK for success;若返回值为数据,则直接介绍数据的功能。
documentation/coding_style_cn.md
Outdated
| **函数注释**: | ||
|
|
||
| - 以 `/**` 开头,以 ` */` 结尾,中间写入函数注释 | ||
| - 第一部分:一个段落介绍函数的作用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加入:
注意每句话开头大写,末尾加句号。
documentation/coding_style_cn.md
Outdated
|
|
||
| - 以 `/**` 开头,以 ` */` 结尾,中间写入函数注释 | ||
| - 第一部分:一个段落介绍函数的作用 | ||
| - 第二部分:参数采用 @param + 参数 + 介绍参数 的方式 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加入:
开头无需大写,以param为主语+be动词+描述+句号
documentation/coding_style_cn.md
Outdated
| * @param sem the semaphore object | ||
| * @param name the name of semaphore | ||
| * @param value the initial value of semaphore | ||
| * @param flag the flag of semaphore | ||
| * | ||
| * @return the operation status, RT_EOK on successful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个例程不规范。用这个
/**
* @brief This function will suspend a thread to a IPC object list.
*
* @param list is a pointer to a suspended thread list of the IPC object.
*
* @param thread is a pointer to the thread object to be suspended.
*
* @param flag is a flag for the thread object to be suspended. It determines how the thread is suspended.
* The flag can be ONE of the following values:
*
* RT_IPC_FLAG_PRIO The pending threads will queue in order of priority.
*
* RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method
* (also known as first-come-first-served (FCFS) scheduling strategy).
*
* NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use
* RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
* the first-in-first-out principle, and you clearly understand that all threads involved in
* this semaphore will become non-real-time threads.
*
* @return Return the operation status. When the return value is RT_EOK, the function is successfully executed.
* When the return value is any other values, it means the initialization failed.
*
* @warning This function can ONLY be called in the thread context, you can use RT_DEBUG_IN_THREAD_CONTEXT to
* check the context.
* In addition, this function is generally called by the following functions:
* rt_sem_take(), rt_mutex_take(), rt_event_recv(), rt_mb_send_wait(),
* rt_mb_recv(), rt_mq_recv(), rt_mq_send_wait()
*/| { | ||
| .... | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加入:
注释模版请参见:src/ipc.c 源码文件
documentation/coding_style_cn.md
Outdated
| 在创建一个新的对象时,应该思考好,对象的内存操作处理:是否允许一个静态对象存在,或仅仅支持从堆中动态分配的对象。 | ||
|
|
||
| ## 14. 用 astyle 自动格式化代码 | ||
| ## 14.用 astyle 自动格式化代码 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请把formatting也加进去https://github.com/mysterywolf/formatting
astyle功能更强大;formatting可以满足rtt编码规则的基本要求,更方便。二者可以让用户自行选择。
|
|
||
| - drv_spi.c | ||
| - drv_gpio.c | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个驱动框架以:
dev_iic.c命名?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个没确定,所以没加
| ## 8.注释编写 | ||
| 请使用英文做为注释,使用中文注释将意味着在编写代码时需要来回不停的切换中英文输入法从而打断编写代码的思路。并且使用英文注释也能够比较好的与中国以外的技术者进行交流。 | ||
| 请使用**英文**做为注释,使用中文注释将意味着在编写代码时需要来回不停的切换中英文输入法从而打断编写代码的思路。并且使用英文注释也能够比较好的与中国以外的技术者进行交流。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BSP由贡献者或芯片厂商自行决定使用何种语言,因为有些芯片厂商连英文芯片手册都没有,要英文注释没有任何意义,汉语请确保为UTF-8编码。
RTT相关,强烈建议使用英文,若因语言能力问题,无法使用英文的,可以采用中文,后期RTT再自行翻译成英文。
mysterywolf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他没有问题了
documentation/coding_style_cn.md
Outdated
| 在创建一个新的对象时,应该思考好,对象的内存操作处理:是否允许一个静态对象存在,或仅仅支持从堆中动态分配的对象。 | ||
|
|
||
| ## 14. 用 astyle 自动格式化代码 | ||
| ## 14.用 astyle 自动格式化代码 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改为:
14. 格式化代码
格式化代码是指通过脚本自动整理你的代码,并使其符合RT-Thread的编码规范。本文提供以下两种自动格式化代码方法,可以自行选择或配合使用。
documentation/coding_style_cn.md
Outdated
|
|
||
| 能满足函数空格、缩进、函数语句等的规范。 | ||
|
|
||
| ### 使用 formatting 格式化 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting后面多了一个空格
documentation/coding_style_cn.md
Outdated
|
|
||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除多余的空行
9e3a486 to
7da5c8d
Compare
7da5c8d to
1bb7ded
Compare
拉取/合并请求描述:(PR description)
[
更新编码规范,增加函数命名方法、注释方法
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up