当前位置:网站首页>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
边栏推荐
- The 5th Blue Bridge Cup single chip microcomputer provincial competition
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验1 LED 闪烁实验(学习笔记)
- [tips] use Matlab GUI to read files in dialog mode
- NLog使用
- Oracle 常用SQL
- Oracle viewing locked tables and unlocking
- Welcome the winter vacation multi school league game 2 partial solution (B, C, D, F, G, H)
- 近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
- 数据库文件逻辑结构形式指的是什么
- 5G时代全面到来,浅谈移动通信的前世今生
猜你喜欢
蓝桥杯单片机省赛第十一届
0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
滴滴开源DELTA:AI开发者可轻松训练自然语言模型
Unity脚本的基础语法(6)-特定文件夹
蓝桥杯单片机省赛第十二届第二场
u本位合约爆仓清算解决方案建议
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板,老板也有建设积分和捣乱积分, 排好队后,所有
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
蓝桥杯单片机省赛第九届
【DesignMode】建造者模式(Builder model)
随机推荐
[designmode] builder model
Influence of air resistance on the trajectory of table tennis
How about Ping An lifetime cancer insurance?
MySQL index, transaction and storage engine
FFMpeg AVFrame 的概念.
The second game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
First acquaintance with string+ simple usage (II)
What do you know about stock selling skills and principles
集成底座方案演示说明
The page in H5 shows hidden execution events
Kotlin basic learning 17
近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
蓝桥杯单片机省赛第七届
How should the team choose the feature branch development mode or trunk development mode?
数据库文件逻辑结构形式指的是什么
【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
Oracle viewing locked tables and unlocking
NLog使用
Kubernetes cluster storageclass persistent storage resource core concept and use