当前位置:网站首页>【愚公系列】2022年7月 Go教学课程 004-Go代码注释
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
2022-07-05 21:48:00 【愚公搬代码】
前言
1.注释的定义
注释就是对代码的解释和说明。目的是为了让别人和自己很容易看懂,一看就知道这段代码是做什么用的。正确的程序注释一般包括序言性注释和功能性注释。序言性注释的主要内容包括模块的接口、数据的描述和模块的功能。模块的功能性注释的主要内容包括程序段的功能、语句的功能和数据的状态。
2.注释的作用
注释只是为了提高可读性,不会被计算机编译。
一、Go代码注释
Go语言的注释主要分成两类,分别是单行注释和多行注释。
1.单行注释
单行注释简称行注释,是最常见的注释形式,可以在任何地方使用以//开头的单行注释;
快捷键:ctrl+c
// Add 两数相加(这一行会被截取为简短介绍)
// 两数相加的注意事项以及原理(这一行作为超级详细的介绍)
func Add(n1,n2 int)int{
return n1+n2
}
2.多行注释
多行注释简称块注释,以/*开头,并以*/结尾,且不可以嵌套使用,多行注释一般用于包的文档描述或注释成块的代码片段。
快捷键:shift+ctrl+c
/* regexp 包为正则表达式实现了一个简单的库。 该库接受的正则表达式语法为: regexp: concatenation { '|' concatenation } concatenation: { closure } closure: term [ '*' | '+' | '?' ] term: '^' '$' '.' character '[' [ '^' ] character-ranges ']' '(' regexp ')' */
package regexp
总结
注释在程序中的作用是对程序进行注解和说明,便于对源码的阅读。编译系统在对源代码进行编译时会自动忽略注释的部分,因此注释对于程序的功能实现不起任何作用。在源码中适当地添加注释,能够提高源码的可读性。
边栏推荐
- PIP install beatifulsoup4 installation failed
- Scenario interview: ten questions and ten answers about distributed locks
- Codeforces 12D ball tree array simulation 3 sorting elements
- Chapter 05_ Storage engine
- HYSBZ 2243 染色 (树链拆分)
- 办公遇到的问题--
- 总结出现2xx、3xx、4xx、5xx状态码的原因
- 让开发效率提升的跨端方案
- Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
- "Grain mall" -- Summary and induction
猜你喜欢

Making global exception handling classes with aspect

"Grain mall" -- Summary and induction

MMAP学习

R language learning notes

Cold violence -- another perspective of objective function setting

Huawei fast game failed to call the login interface, and returned error code -1

Yolov5 training custom data set (pycharm ultra detailed version)

Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)

PIP install beatifulsoup4 installation failed

MMAP learning
随机推荐
Drawing HSV color wheel with MATLAB
854. 相似度为 K 的字符串 BFS
Problems encountered in office--
Defect detection - Halcon surface scratch detection
oracle 控制文件的多路复用
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Chap2 steps into the palace of R language
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
使用Aspect制作全局异常处理类
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
怎么利用Tensorflow2进行猫狗分类识别
Clickhouse copy paste multi line SQL statement error
Poj3414 extensive search
冯唐“春风十里不如你”数字藏品,7月8日登录希壤!
Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
xlrd常见操作
Poj3414广泛搜索
Four components of logger
Net small and medium-sized enterprise project development framework series (one)
123456