Skip to content

Conversation

@yangjie11
Copy link
Contributor

@yangjie11 yangjie11 commented Aug 31, 2021

拉取/合并请求描述:(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):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并符合RT-Thread代码规范 This PR complies with RT-Thread code specification

-`/**` 开头,以 ` */` 结尾,中间写入函数注释
- 第一部分:一个段落介绍函数的作用
- 第二部分:参数采用 @param + 参数 + 介绍参数 的方式
- 第三部分:返回采用 @return + 返回值 + 介绍返回值 的方式
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 直接介绍返回值即可,不用+返回值,实践过程中发现会有开发者直接写成返回类型
@return + 介绍返回值 的方式
开头大写,末尾加句号

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么意思,RT_EOK for success,这样也不行吗

Copy link
Member

@mysterywolf mysterywolf Aug 31, 2021

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;若返回值为数据,则直接介绍数据的功能。

**函数注释**

-`/**` 开头,以 ` */` 结尾,中间写入函数注释
- 第一部分:一个段落介绍函数的作用
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加入:
注意每句话开头大写,末尾加句号。


-`/**` 开头,以 ` */` 结尾,中间写入函数注释
- 第一部分:一个段落介绍函数的作用
- 第二部分:参数采用 @param + 参数 + 介绍参数 的方式
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加入:
开头无需大写,以param为主语+be动词+描述+句号

Comment on lines 135 to 140
* @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
Copy link
Member

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()
 */

{
....
}
```
Copy link
Member

@mysterywolf mysterywolf Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加入:
注释模版请参见:src/ipc.c 源码文件

在创建一个新的对象时,应该思考好,对象的内存操作处理:是否允许一个静态对象存在,或仅仅支持从堆中动态分配的对象。

## 14. 用 astyle 自动格式化代码
## 14.用 astyle 自动格式化代码
Copy link
Member

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编码规则的基本要求,更方便。二者可以让用户自行选择。

@mysterywolf mysterywolf added in progress PR/issue in progress. v4.0.4 labels Aug 31, 2021

- drv_spi.c
- drv_gpio.c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一个驱动框架以:
dev_iic.c命名?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个没确定,所以没加

## 8.注释编写
请使用英文做为注释,使用中文注释将意味着在编写代码时需要来回不停的切换中英文输入法从而打断编写代码的思路。并且使用英文注释也能够比较好的与中国以外的技术者进行交流。
请使用**英文**做为注释,使用中文注释将意味着在编写代码时需要来回不停的切换中英文输入法从而打断编写代码的思路。并且使用英文注释也能够比较好的与中国以外的技术者进行交流。
Copy link
Member

@mysterywolf mysterywolf Aug 31, 2021

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再自行翻译成英文。

Copy link
Member

@mysterywolf mysterywolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他没有问题了

在创建一个新的对象时,应该思考好,对象的内存操作处理:是否允许一个静态对象存在,或仅仅支持从堆中动态分配的对象。

## 14. 用 astyle 自动格式化代码
## 14.用 astyle 自动格式化代码
Copy link
Member

@mysterywolf mysterywolf Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改为:
14. 格式化代码
格式化代码是指通过脚本自动整理你的代码,并使其符合RT-Thread的编码规范。本文提供以下两种自动格式化代码方法,可以自行选择或配合使用。


能满足函数空格、缩进、函数语句等的规范。

### 使用 formatting 格式化
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting后面多了一个空格

Comment on lines 309 to 313





Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除多余的空行

@mysterywolf mysterywolf added +1 Agree +1 and removed in progress PR/issue in progress. labels Sep 2, 2021
@BernardXiong BernardXiong merged commit 93b17bf into RT-Thread:master Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+1 Agree +1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants