当前位置:网站首页>【愚公系列】2022年7月 Go教学课程 004-Go代码注释
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
2022-07-05 20:20: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总结
注释在程序中的作用是对程序进行注解和说明,便于对源码的阅读。编译系统在对源代码进行编译时会自动忽略注释的部分,因此注释对于程序的功能实现不起任何作用。在源码中适当地添加注释,能够提高源码的可读性。
边栏推荐
猜你喜欢

CTF reverse Foundation

Leetcode skimming: binary tree 12 (all paths of binary tree)

【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)

14、Transformer--VIT TNT BETR
![[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods](/img/3a/7eaff0bf819c129b4f866388e57b87.png)
[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods

Leetcode(695)——岛屿的最大面积

leetcode刷题:二叉树15(找树左下角的值)

【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标

IC科普文:ECO的那些事儿

CVPR 2022 | 常见3D损坏和数据增强
随机推荐
物联网智能家居基本方法实现之经典
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
ICTCLAS用的字Lucene4.9捆绑
Go language learning tutorial (XV)
小程序项目结构
CTF reverse Foundation
信息学奥赛一本通 1340:【例3-5】扩展二叉树
model方法
mongodb文档间关系
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
Leetcode(347)——前 K 个高频元素
CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
Reinforcement learning - learning notes 4 | actor critical
Mongodb/ document operation
强化学习-学习笔记4 | Actor-Critic
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
Go language | 02 for loop and the use of common functions
ffplay文档[通俗易懂]
Ffplay document [easy to understand]