当前位置:网站首页>go 语言命名规范
go 语言命名规范
2022-07-02 03:45:00 【UPythonFish】
go 语言命名规范
一 变量定义规范
Go语言中的函数名、变量名、常量名、类型名、语句标号和包名等所有的命名,都遵循一个简单的命名规则:
一个名字必须以一个字母(Unicode字母)或下划线开头,后面可以跟任意数量的字母、数字或下划线
大写字母和小写字母是不同的:Name和name是两个不同的变量
关键字和保留字都不建议用作变量名
并且一个项目中有且只有一个main包,多了或者少了都不能运行。学习基础阶段,可以再一个项目下有多个main函数,但是必须以file形式运行,不能以包的形式运行。
// 变量定义推荐用驼峰体
-AgeOfPerson go语言和java语言推荐,python不推荐
-age_of_person 下划线方式,不推荐(go不推荐,python推荐)
// go文件的名字,建议使用下划线(参照源码)
-java语言中:变量和文件名都推荐用驼峰
-Python中:变量名和文件名都推荐用下划线
二 关键字与保留字
Go语言中关键字有25个;关键字不能用于自定义名字,只能再特定语法结构中使用。37个保留字,主要对应内建的常量、类型和函数
// 25个关键字
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
//37个保留字
内建常量: true false iota nil
内建类型: int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64 uintptr
float32 float64 complex128 complex64
bool byte rune string error
内建函数: make len cap new append copy close delete
complex real imag
panic recover
边栏推荐
- 蓝桥杯单片机省赛第九届
- Unity脚本的基础语法(8)-协同程序与销毁方法
- Blue Bridge Cup single chip microcomputer sixth temperature recorder
- 蓝桥杯单片机第六届温度记录器
- Vite: scaffold assembly
- Suggestions on settlement solution of u standard contract position explosion
- 蓝桥杯单片机省赛第十一届
- 0基础如何学习自动化测试?按照这7步一步一步来学习就成功了
- L'avènement de l'ère 5G, une brève discussion sur la vie passée et présente des communications mobiles
- Jetpack之LiveData扩展MediatorLiveData
猜你喜欢
![[designmode] Prototype Pattern](/img/ee/c4e48c2ce8ff66f50f0bf13e5a0418.png)
[designmode] Prototype Pattern

Influence of air resistance on the trajectory of table tennis

Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs

【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真

Flutter中深入了解MaterialApp,常用属性解析
![[ibdfe] matlab simulation of frequency domain equalization based on ibdfe](/img/a1/441f400668e736b70cb36443f2267a.png)
[ibdfe] matlab simulation of frequency domain equalization based on ibdfe

Account management of MySQL

A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)

蓝桥杯单片机第六届温度记录器

【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)
随机推荐
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
UI (New ui:: MainWindow) troubleshooting
蓝桥杯单片机省赛第七届
[tips] use Matlab GUI to read files in dialog mode
蓝桥杯单片机省赛第六届
【DesignMode】原型模式(prototype pattern)
Haute performance et faible puissance Cortex - A53 Core Board | i.mx8m mini
微信小程序中 在xwml 中使用外部引入的 js进行判断计算
蓝桥杯单片机省赛第十一届第二场
Kotlin基础学习 15
Unity脚本的基础语法(7)-成员变量和实例化
[mv-3d] - multi view 3D target detection network
Basic operations of MySQL database (based on tables)
潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
Influence of air resistance on the trajectory of table tennis
JS generate random numbers
5G时代全面到来,浅谈移动通信的前世今生
潘多拉 IOT 开发板学习(RT-Thread)—— 实验1 LED 闪烁实验(学习笔记)
Review materials of project management PMP high frequency examination sites (8-1)
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini