Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

程序变量命名的几种叫法 #7

Open
whinc opened this issue Mar 16, 2018 · 0 comments
Open

程序变量命名的几种叫法 #7

whinc opened this issue Mar 16, 2018 · 0 comments

Comments

@whinc
Copy link
Owner

whinc commented Mar 16, 2018

计算机语言很多,无论哪种语言编写代码时都会遇到变量命名、方法命名等问题,网上关于代码命名风格的讨论已经多到无法形容了,甚至成为了程序员的一种价值观。今天不讨论命名风格孰优孰劣,仅整理下已有的命名风格作为了解,方便相互之间沟通。

camel case (驼峰式)

特点:名称中间没有空格和标点,除第一个单词外后面的单词首字母均大写。

如果第一个单词首字母大写,称之为upper camel caseCamelCase,大驼峰式),例如"GetUserName"
如果第一个单词首字母小写,称之为lower camel casecamelCase,小驼峰式),例如"getUserName"

upper camel case还有一个称呼Pascal case

snake case (蛇式)

特点:名称中间的标点被替换成下划线(_)。

如果所有单词都小写,称之为lower snake case(小蛇式),例如"get_user_name"
如果所有单词都大写,称之为upper snake case(大蛇式),例如"GET_USER_NAME"

kebab case (烤肉串式)

特点:名称中间的标点被替换成连字符(-),所有单词都小写,例如"get-user-name"

参考

@whinc whinc changed the title 计算机语言命名风格 程序变量命名的几种叫法 Mar 29, 2018
@whinc whinc added the Misc label Dec 14, 2019
@whinc whinc added 软件设计 and removed Misc labels Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant