什么叫甲沟炎| 高铁座位为什么没有e| 小五行属什么| 白醋和白米醋有什么区别| 4月17是什么星座| 乳房胀痛是什么原因| 抓拍是什么意思| 聪明的人有什么特征| 静脉曲张手术后吃什么| 宝宝流鼻涕吃什么药| 花荣的绰号是什么| 饭前吃药和饭后吃药有什么区别| 阴道内壁是什么样的| 什么的夏天| 为什么睡觉会突然抖一下| 门槛石有什么讲究| 站久了脚后跟疼是什么原因| 獭尾肝是什么病| 三月六号是什么星座| 筋膜提升术是什么| 嘴唇淡紫色是什么原因| 着凉感冒吃什么药| hi什么意思| 蚯蚓的血是什么颜色的| 为什么睡觉| 阿玛尼属于什么档次| 宫颈炎用什么药| 隽字五行属什么| 孩子疱疹性咽峡炎吃什么药| 晗字五行属什么| 打劫是什么意思| 脚趾长痣代表什么意思| 百香果配什么好喝| 妥瑞氏症是什么病| 情难自禁是什么意思| 拔智齿后吃什么消炎药| 放屁是热的是什么原因| 压疮用什么药最快能好| 高什么阔什么| 什么水果含维c最多| 吃靶向药不能吃什么| 频繁流鼻血是什么原因| 莫欺少年穷是什么意思| 吃什么美容养颜抗衰老| 吃什么药去体内湿气| 蛇吃什么食物| 两个人可以玩什么游戏| 什么东西吃蟑螂| 开庭前家属做什么准备| abo血型是什么意思| 胃气不足吃什么中成药| 鞘是什么意思| 天蝎座和什么星座不合| 吉加页读什么| 红色和蓝色混合是什么颜色| 头晕视力模糊是什么原因| 心脏下边是什么器官| 丹毒是什么| 混剪是什么意思| 雏菊的花语是什么| 吊儿郎当什么意思| 小满是什么季节| 上火流鼻血吃什么降火| 宫外孕出血是什么颜色| 眼睛肿胀是什么原因| 朱迅是什么民族| 戊日是什么意思| 什么飞机| 颉在姓氏里念什么| 保胎吃什么药| 有迹可循什么意思| 轶字五行属什么| 一字马是什么意思| 麻辣拌里面都有什么菜| 感冒流鼻涕吃什么药好得快| 急得什么| 1129是什么星座| 狗女和什么属相最配| 黄芪和什么泡水壮阳| 牛肉和什么菜炒好吃| 尿分叉是什么原因引起的| 秀女是什么意思| 水漫金山什么意思| 欧阳修字什么| 脊柱疼是什么原因| 腋毛癣用什么药膏最好| 肝炎是什么| 月非念什么| 宫腔灌注是治疗什么的| 偏头痛是什么| 素海参是什么做的| 痛经吃什么食物| 令人唏嘘是什么意思| 为什么射出的精子里有淡红色| 歪理是什么意思| 脱口秀是什么意思| 梦见考试是什么意思| 整个手掌发红是什么原因| 试管移植后吃什么容易着床| 艾叶是什么| 财神是什么生肖| 梦见自己哭了是什么意思| 海姆立克急救法是什么| 6月30日是什么座| 什么情况会染上鼠疫| 牙齿抛光是什么意思| 不孕不育应检查什么| 羊膜囊是什么| d二聚体高是什么原因| 普贤菩萨保佑什么生肖| 右肺小结节是什么意思| 同型半胱氨酸是什么意思| 虎皮羊质是指什么生肖| 点睛之笔是什么意思| 十岁小孩尿床是什么原因| 红细胞偏高是什么病| 放飞自我是什么意思| 卓玛什么意思| blossom是什么意思| 肚子咕噜响是什么原因| 96100是什么电话| 左肾积水是什么意思| 藿香正气水不能和什么药一起吃| 全身骨头疼是什么原因| 拜阿司匹林和阿司匹林有什么区别| 儿童超敏c反应蛋白高说明什么| les什么意思| 害喜是什么意思| 长颈鹿的脖子为什么那么长| 适宜是什么意思| 什么东东是什么意思| 尿蛋白高是什么病| 手上长水泡是什么原因| 读书的意义是什么| 5个月宝宝可以吃什么水果| 小孩上户口需要什么材料| 尿蛋白是什么| 马可以加什么偏旁| 国字脸适合什么发型男| cook是什么意思| 健脾丸和归脾丸有什么区别| 夏天为什么容易拉肚子| 嘘寒问暖是什么意思| 心肌酶谱是查什么的| 6月23号是什么星座| 12.24是什么星座| 万中无一什么意思| 丙烯颜料用什么洗掉| 闪购是什么| 祖师爷是什么意思| 晚上8点到9点是什么时辰| 经常吃莲子有什么好处| 双侧下鼻甲肥大是什么意思| 鸡和什么相冲| 不解什么| 药剂师是做什么的| 开挖掘机需要什么证| 牙龈一直出血是什么原因| 脑梗原因是什么引起的| 优五行属性是什么| 视力5.3是什么概念| 吃中药不能吃什么| 胸疼挂什么科室| 牙肿了吃什么消炎药| 梦见别人给自己剪头发是什么意思| 首饰是什么意思| 两个火念什么| 遥字五行属什么| 中观是什么意思| 骨折吃什么消炎药| 画画用什么铅笔| lt是什么意思| 浪是什么意思| 空囊是什么意思| 甲状腺1度肿大是什么意思| 腹部彩超可以检查什么| 精液长什么样| 膀胱炎什么症状| 景泰蓝是什么地方的特种工艺| 妇科tct检查什么| 空调嗡嗡响是什么原因| 斑秃吃什么药效果好| 银杏是什么| 甲苯是什么东西| 禁的部首是什么| 肝内点状钙化灶什么意思| 安全监察是一种带有什么的监督| 故人什么意思| 色是什么结构| 肾水不足是什么意思| 什么样的手相最有福气| 嗜碱性粒细胞偏高是什么原因| 吃得苦中苦方为人上人是什么意思| 麻烦别人说什么礼貌用语| 下体瘙痒是什么原因| 一黑一白是什么蛇| 疤痕增生是什么| 狗不能吃什么| 认知障碍是什么意思| 莲蓬是什么| 4c是什么| 腿硬邦邦的是什么原因| 金刚经讲的是什么| 顶礼是什么意思| 关节痛去医院挂什么科| 寿司的米饭是什么米| 公因数是什么意思| 射精太快吃什么好| 身体冒虚汗什么原因| 病毒感染有什么症状| 羊排和什么一起炖好吃| 子宫内膜回声不均匀是什么意思| 踩雷是什么意思| cps是什么| 曹曦月演过什么电视剧| 63年的兔是什么命| 黑洞是什么| 来姨妈头疼是什么原因| 梦见和亲人吵架是什么意思| 为什么性生活会出血| 心脏不好挂什么科| 事无巨细是什么意思| 跑步对身体有什么好处| 单鞋是什么鞋| 萘是什么| 光是什么意思| 养神经吃什么食物最好| 什么牌子的保温杯好| 生殖科检查什么| 黄泉是什么意思| 窦房结是什么意思| oioi是什么牌子| 玳瑁是什么| 鼻屎多是什么原因| 天年是什么意思| 结扎后需要注意什么| 身体湿气重吃什么药| 肾积水有什么症状表现| 梦到下雨是什么意思| 小便多是什么原因男性| 三句半是什么意思| 天行健下一句是什么| lake是什么意思| 湫是什么意思| 身上长湿疹是什么原因导致| 左手臂发麻是什么原因| 马云属什么| 脚趾痒用什么药| 疳积是什么| 什么是高嘌呤食物| 神经纤维是什么| 布谷鸟长什么样| 梦到吃屎是什么意思| 扎西德勒是什么意思| 喉咙发炎吃什么消炎药| 白天不懂夜的黑是什么意思| 决明子是什么东西| lsil什么意思| 九二年属猴的是什么命| 木耳不能和什么食物一起吃| 奶奶的弟弟叫什么| 祥云是什么意思| 还有什么寓言故事| 凉面是用什么面做的| 百度Jump to content

美团打车登陆上海 滴滴将携外卖“迎敌”

From Wikipedia, the free encyclopedia
百度 在研发和制造高品质的产品的同时,我们也需要为未来的出行储备力量。

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

Reasons for using a naming convention (as opposed to allowing programmers to choose any character sequence) include the following:

  • To reduce the effort needed to read and understand source code;[1]
  • To enable code reviews to focus on issues more important than syntax and naming standards.
  • To enable code quality review tools to focus their reporting mainly on significant issues other than syntax and style preferences.

The choice of naming conventions can be a controversial issue, with partisans of each holding theirs to be the best and others to be inferior. Colloquially, this is said to be a matter of dogma.[2] Many companies have also established their own set of conventions.

Potential benefits

[edit]

Benefits of a naming convention can include the following:

  • to provide additional information (i.e., metadata) about the use to which an identifier is put;
  • to help formalize expectations and promote consistency within a development team;
  • to enable the use of automated refactoring or search and replace tools with minimal potential for error;
  • to enhance clarity in cases of potential ambiguity;
  • to enhance the aesthetic and professional appearance of work product (for example, by disallowing overly long names, comical or "cute" names, or abbreviations);
  • to help avoid "naming collisions" that might occur when the work product of different organizations is combined (see also: namespaces);
  • to provide meaningful data to be used in project handovers which require submission of program source code and all relevant documentation;
  • to provide better understanding in case of code reuse after a long interval of time.

Challenges

[edit]

The choice of naming conventions (and the extent to which they are enforced) is often a contentious issue, with partisans holding their viewpoint to be the best and others to be inferior. Moreover, even with known and well-defined naming conventions in place, some organizations may fail to consistently adhere to them, causing inconsistency and confusion. These challenges may be exacerbated if the naming convention rules are internally inconsistent, arbitrary, difficult to remember, or otherwise perceived as more burdensome than beneficial.

Readability

[edit]

Well-chosen identifiers make it significantly easier for developers and analysts to understand what the system is doing and how to fix or extend the source code to apply for new needs.

For example, although

 a = b * c;

is syntactically correct, its purpose is not evident. Contrast this with:

 weekly_pay = hours_worked * hourly_pay_rate;

which implies the intent and meaning of the source code, at least to those familiar with the context of the statement.

Experiments suggest that identifier style affects recall and precision and that familiarity with a style speeds recall.[3]

Common elements

[edit]

The exact rules of a naming convention depend on the context in which they are employed. Nevertheless, there are several common elements that influence most if not all naming conventions in common use today.

Length of identifiers

[edit]

Fundamental elements of all naming conventions are the rules related to identifier length (i.e., the finite number of individual characters allowed in an identifier). Some rules dictate a fixed numerical bound, while others specify less precise heuristics or guidelines.

Identifier length rules are routinely contested in practice, and subject to much debate academically.

Some considerations:

  • shorter identifiers may be preferred as more expedient, because they are easier to type (although many IDEs and text-editors provide text-completion, which mitigates this)
  • extremely short identifiers (such as 'i' or 'j') are very difficult to uniquely distinguish using automated search and replace tools (although this is not an issue for regex-based tools)
  • longer identifiers may be preferred because short identifiers cannot encode enough information or appear too cryptic
  • longer identifiers may be disfavored because of visual clutter

It is an open research issue whether some programmers prefer shorter identifiers because they are easier to type, or think up, than longer identifiers, or because in many situations a longer identifier simply clutters the visible code and provides no perceived additional benefit.

Brevity in programming could be in part attributed to:

  • early linkers which required variable names to be restricted to 6 characters to save memory. A later "advance" allowed longer variable names to be used for human comprehensibility, but where only the first few characters were significant. In some versions of BASIC such as TRS-80 Level 2 Basic, long names were allowed, but only the first two letters were significant. This feature permitted erroneous behaviour that could be difficult to debug, for example when names such as "VALUE" and "VAT" were used and intended to be distinct.
  • early source code editors lacking autocomplete
  • early low-resolution monitors with limited line length (e.g. only 80 characters)
  • much of computer science originating from mathematics, where variable names are traditionally only a single letter

Letter case and numerals

[edit]

Some naming conventions limit whether letters may appear in uppercase or lowercase. Other conventions do not restrict letter case, but attach a well-defined interpretation based on letter case. Some naming conventions specify whether alphabetic, numeric, or alphanumeric characters may be used, and if so, in what sequence.

Multiple-word identifiers

[edit]

A common recommendation is "Use meaningful identifiers." A single word may not be as meaningful, or specific, as multiple words. Consequently, some naming conventions specify rules for the treatment of "compound" identifiers containing more than one word.

As most programming languages do not allow whitespace in identifiers, a method of delimiting each word is needed (to make it easier for subsequent readers to interpret which characters belong to which word). Historically some early languages, notably FORTRAN (1955) and ALGOL (1958), allowed spaces within identifiers, determining the end of identifiers by context. This was abandoned in later languages due to the difficulty of tokenization. It is possible to write names by simply concatenating words, and this is sometimes used, as in mypackage for Java package names,[4] though legibility suffers for longer terms, so usually some form of separation is used.

Delimiter-separated words

[edit]

One approach is to delimit separate words with a non-alphanumeric character. The two characters commonly used for this purpose are the hyphen ("-") and the underscore ("_"); e.g., the two-word name "two words" would be represented as "two-words" or "two_words".

The hyphen is used by nearly all programmers writing COBOL (1959), Forth (1970), and Lisp (1958); it is also common in Unix for commands and packages, and is used in CSS.[5] This convention has no standard name, though it may be referred to as lisp-case or COBOL-CASE (compare Pascal case), kebab-case, brochette-case, or other variants.[6][7][8][9] Of these, kebab-case, dating at least to 2012,[10] has achieved some currency since.[11][12]

By contrast, languages in the FORTRAN/ALGOL tradition, notably languages in the C and Pascal families, used the hyphen for the subtraction infix operator, and did not wish to require spaces around it (as free-form languages), preventing its use in identifiers.

An alternative is to use underscores; this is common in the C family (including Python), with lowercase words, being found for example in The C Programming Language (1978), and has come to be known as snake case or snail case. Underscores with uppercase, as in UPPER_CASE, are commonly used for C preprocessor macros, hence known as MACRO_CASE, and for environment variables in Unix, such as BASH_VERSION in bash. Sometimes this is humorously referred to as SCREAMING_SNAKE_CASE (alternatively SCREAMING_SNAIL_CASE).

Letter case-separated words

[edit]

Another approach is to indicate word boundaries using medial capitalization, called "camelCase", "PascalCase", and many other names, thus respectively rendering "two words" as "twoWords" or "TwoWords". This convention is commonly used in Pascal, Java, C#, and Visual Basic. Treatment of initialisms in identifiers (e.g. the "XML" and "HTTP" in XMLHttpRequest) varies. Some dictate that they be lowercase (e.g. XmlHttpRequest) to ease typing, readability and ease of segmentation, whereas others leave them uppercased (e.g. XMLHTTPRequest) for accuracy.

Examples of multiple-word identifier formats

[edit]
Multiple-word identifier formats
Formatting Name(s)
twowords flatcase[13][14]
TWOWORDS UPPERCASE, SCREAMINGCASE[13]
twoWords (lower) camelCase, dromedaryCase
TwoWords PascalCase, UpperCamelCase
two_words snake_case, snail_case, pothole_case
TWO_WORDS ALL_CAPS, SCREAMING_SNAKE_CASE,[15] MACRO_CASE, CONSTANT_CASE
two_Words camel_Snake_Case
Two_Words Pascal_Snake_Case, Title_Case
two-words kebab-case, dash-case, lisp-case, spinal-case
TWO-WORDS TRAIN-CASE, COBOL-CASE, SCREAMING-KEBAB-CASE
Two-Words Train-Case,[13] HTTP-Header-Case[16]

Metadata and hybrid conventions

[edit]

Some naming conventions represent rules or requirements that go beyond the requirements of a specific project or problem domain, and instead reflect a greater overarching set of principles defined by the software architecture, underlying programming language or other kind of cross-project methodology.

Hungarian notation

[edit]

Perhaps the most well-known is Hungarian notation, which encodes either the purpose ("Apps Hungarian") or the type ("Systems Hungarian") of a variable in its name.[17] For example, the prefix "sz" for the variable szName indicates that the variable is a null-terminated string.

Positional notation

[edit]

A style used for very short (eight characters and less) could be: LCCIIL01, where LC would be the application (Letters of Credit), C for COBOL, IIL for the particular process subset, and the 01 a sequence number.

This sort of convention is still in active use in mainframes dependent upon JCL and is also seen in the 8.3 (maximum eight characters with period separator followed by three character file type) MS-DOS style.

Composite word scheme (OF Language)

[edit]

IBM's "OF Language" was documented in an IMS (Information Management System) manual.

It detailed the PRIME-MODIFIER-CLASS word scheme, which consisted of names like "CUST-ACT-NO" to indicate "customer account number".

PRIME words were meant to indicate major "entities" of interest to a system.

MODIFIER words were used for additional refinement, qualification and readability.

CLASS words ideally would be a very short list of data types relevant to a particular application. Common CLASS words might be: NO (number), ID (identifier), TXT (text), AMT (amount), QTY (quantity), FL (flag), CD (code), W (work) and so forth. In practice, the available CLASS words would be a list of less than two dozen terms.

CLASS words, typically positioned on the right (suffix), served much the same purpose as Hungarian notation prefixes.

The purpose of CLASS words, in addition to consistency, was to specify to the programmer the data type of a particular data field. Prior to the acceptance of BOOLEAN (two values only) fields, FL (flag) would indicate a field with only two possible values.

Language-specific conventions

[edit]

ActionScript

[edit]

Adobe's Coding Conventions and Best Practices suggests naming standards for ActionScript that are mostly consistent with those of ECMAScript.[18] The style of identifiers is similar to that of Javascript.

Ada

[edit]

In Ada, the only recommended style of identifiers is Mixed_Case_With_Underscores.[19]

APL

[edit]

In APL dialects, the delta (Δ) is used between words, e.g. PERFΔSQUARE (no lowercase traditionally existed in older APL versions). If the name used underscored letters, then the delta underbar (?) would be used instead.

C and C++

[edit]

In C and C++, keywords and standard library identifiers are mostly lowercase. In the C standard library, abbreviated names are the most common (e.g. isalnum for a function testing whether a character is alphanumeric), while the C++ standard library often uses an underscore as a word separator (e.g. out_of_range). Identifiers representing macros are, by convention, written using only uppercase letters and underscores, for example NULL and EINVAL (this is related to the convention in many programming languages of using all-upper-case identifiers for constants). Names containing double underscore or beginning with an underscore and a capital letter are reserved for implementation (compiler, standard library) and should not be used (e.g. __reserved or _Reserved).[20][21] This is superficially similar to stropping, but the semantics differ: the underscores are part of the value of the identifier, rather than being quoting characters (as is stropping): the value of __foo is __foo (which is reserved), not foo (but in a different namespace).

C#

[edit]

C# naming conventions generally follow the guidelines published by Microsoft for all .NET languages[22] (see the .NET section, below), but no conventions are enforced by the C# compiler.

The Microsoft guidelines recommend the exclusive use of only PascalCase and camelCase, with the latter used only for method parameter names and method-local variable names (including method-local const values). A special exception to PascalCase is made for two-letter acronyms that begin an identifier; in these cases, both letters are capitalized (for example, IOStream); this is not the case for longer acronyms (for example, XmlStream). The guidelines further recommend that the name given to an interface be PascalCase preceded by the capital letter I, as in IEnumerable.

The Microsoft guidelines for naming fields are specific to static, public, and protected fields; fields that are not static and that have other accessibility levels (such as internal and private) are explicitly not covered by the guidelines.[23] The most common practice is to use PascalCase for the names of all fields, except for those which are private (and neither const nor static), which are given names that use camelCase preceded by a single underscore; for example, _totalCount.

Any identifier name may be prefixed by the commercial-at symbol (@), without any change in meaning. That is, both factor and @factor refer to the same object. By convention, this prefix is only used in cases when the identifier would otherwise be either a reserved keyword (such as for and while), which may not be used as an identifier without the prefix, or a contextual keyword (such as from and where), in which cases the prefix is not strictly required (at least not at its declaration; for example, although the declaration dynamic dynamic; is valid, this would typically be seen as dynamic @dynamic; to indicate to the reader immediately that the latter is a variable name).

Dart/Flutter

[edit]

In the Dart language, used in the Flutter SDK, the conventions are similar to those of Java, except that constants are written in lowerCamelCase. Dart imposes the syntactic rule that non-local identifiers beginning with an underscore (_) are treated as private (since the language does not have explicit keywords for public or private access). Additionally, source file names do not follow Java's "one public class per source file, name must match" rule, instead using snake_case for filenames.[24]

Go

[edit]

In Go, the convention is to use MixedCaps or mixedCaps rather than underscores to write multiword names. When referring to structs or functions, the first letter specifies the visibility for external packages. Making the first letter uppercase exports that piece of code, while lowercase makes it only usable within the current scope.[25]

Java

[edit]

In Java, naming conventions for identifiers have been established and suggested by various Java communities such as Sun Microsystems,[26] Netscape,[27] AmbySoft,[28] etc. A sample of naming conventions set by Sun Microsystems are listed below, where a name in "CamelCase" is one composed of a number of words joined without spaces, with each word's -- excluding the first word's -- initial letter in capitals – for example "camelCase".

Identifier type Rules for naming Examples
Classes Class names should be nouns in UpperCamelCase, with the first letter of every word capitalised. Use whole words – avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
  • class Raster {}
  • class ImageSprite {}
Methods Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase.
  • run();
  • runFast();
  • getBackground();
Variables Local variables, instance variables, and class variables are also written in lowerCamelCase. Variable names should not start with underscore (_) or dollar sign ($) characters, even though both are allowed. This is in contrast to other coding conventions that state that underscores should be used to prefix all instance variables.

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic — that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

  • int i;
  • char c;
  • float myWidth;
Constants Constants should be written in SCREAMING_SNAKE_CASE. Constant names may also contain digits if appropriate, but not as the first character.
  • static final int MAX_PARTICIPANTS = 10;

Java compilers do not enforce these rules, but failing to follow them may result in confusion and erroneous code. For example, widget.expand() and Widget.expand() imply significantly different behaviours: widget.expand() implies an invocation to method expand() in an instance named widget, whereas Widget.expand() implies an invocation to static method expand() in class Widget.

One widely used Java coding style dictates that UpperCamelCase be used for classes and lowerCamelCase be used for instances and methods.[26] Recognising this usage, some IDEs, such as Eclipse, implement shortcuts based on CamelCase. For instance, in Eclipse's content assist feature, typing just the upper-case letters of a CamelCase word will suggest any matching class or method name (for example, typing "NPE" and activating content assist could suggest NullPointerException).

Initialisms of three or more letters are CamelCase instead of uppercase (e.g., parseDbmXmlFromIPAddress instead of parseDBMXMLFromIPAddress). One may also set the boundary at two or more letters (e.g. parseDbmXmlFromIpAddress).

JavaScript

[edit]

The built-in JavaScript libraries use the same naming conventions as Java. Data types and constructor functions use upper camel case (RegExp, TypeError, XMLHttpRequest, DOMObject) and methods use lower camel case (getElementById, getElementsByTagNameNS, createCDATASection). In order to be consistent most JavaScript developers follow these conventions.[29] See also: Douglas Crockford's conventions

Lisp

[edit]

Common practice in most Lisp dialects is to use dashes to separate words in identifiers, as in with-open-file and make-hash-table. Dynamic variable names conventionally start and end with asterisks: *map-walls*. Constants names are marked by plus signs: +map-size+.[30][31]

.NET

[edit]

Microsoft .NET recommends UpperCamelCase, also known as PascalCase, for most identifiers. (lowerCamelCase is recommended for parameters and variables) and is a shared convention for the .NET languages.[32] Microsoft further recommends that no type prefix hints (also known as Hungarian notation) are used.[33] Instead of using Hungarian notation it is recommended to end the name with the base class' name; LoginButton instead of BtnLogin.[34]

Objective-C

[edit]

Objective-C has a common coding style that has its roots in Smalltalk .

Top-level entities, including classes, protocols, categories, as well as C constructs that are used in Objective-C programs like global variables and functions, are in UpperCamelCase with a short all-uppercase prefix denoting namespace, like NSString, UIAppDelegate, NSApp or CGRectMake. Constants may optionally be prefixed with a lowercase letter "k" like kCFBooleanTrue.

Instance variables of an object use lowerCamelCase prefixed with an underscore, like _delegate and _tableView.

Method names use multiple lowerCamelCase parts separated by colons that delimit arguments, like: application:didFinishLaunchingWithOptions:, stringWithFormat: and isRunning.

Pascal, Modula-2 and Oberon

[edit]

Wirthian languages Pascal, Modula-2 and Oberon generally use Capitalized or UpperCamelCase identifiers for programs, modules, constants, types and procedures, and lowercase or lowerCamelCase identifiers for math constants, variables, formal parameters and functions.[35] While some dialects support underscore and dollar signs in identifiers, snake case and macro case is more likely confined to use within foreign API interfaces.[36]

Perl

[edit]

Perl takes some cues from its C heritage for conventions. Locally scoped variables and subroutine names are lowercase with infix underscores. Subroutines and variables meant to be treated as private are prefixed with an underscore. Package variables are title cased. Declared constants are all caps. Package names are camel case excepting pragmata—e.g., strict and mro—which are lowercase. [37] [38]

PHP

[edit]

PHP recommendations are contained in PSR-1 (PHP Standard Recommendation 1) and PSR-12.[39] According to PSR-1, class names should be in PascalCase, class constants should be in MACRO_CASE, and function and method names should be in camelCase.[40]

Python and Ruby

[edit]

Python and Ruby both recommend UpperCamelCase for class names, CAPITALIZED_WITH_UNDERSCORES for constants, and snake_case for other names.

In Python, if a name is intended to be "private", it is prefixed by one or two underscores. Private variables are enforced in Python only by convention. Names can also be suffixed with an underscore to prevent conflict with Python keywords. Prefixing with double underscores changes behaviour in classes with regard to name mangling. Prefixing and suffixing with double underscores - the so-called "dunder" ("double under") methods in Python - are reserved for "magic names" which fulfill special behaviour in Python objects.[41]

R

[edit]

While there is no official style guide for R, the tidyverse style guide from R-guru Hadley Wickham sets the standard for most users.[42] This guide recommends using only numbers, lowercase letters and underscores for file, variable and function names e.g. fit_models.R. The Bioconductor style guide recommends UpperCamelCase for class names and lowerCamelCase for variable and function names.

Its predecessors S and S-PLUS did not allow underscores in variable and function names, but instead used the period as a delimiter. As a result, many base functions in R still have a period as delimiter e.g. as.data.frame().

Hidden objects can be created with the dot prefix e.g. .hidden_object. These objects do not appear in the global environment. The dot prefix is often used by package developers for functions that are purely internal and are not supposed to be used by end users. It is similar to the underscore prefix in Python.

Raku

[edit]

Raku follows more or less the same conventions as Perl, except that it allows an infix hyphen - or an apostrophe ' (or single quote) within an identifier (but not two in a row), provided that it is followed by an alphabetic character. Raku programmers thus often use kebab case in their identifiers; for example, fish-food and don't-do-that are valid identifiers. [43]

Rust

[edit]

Rust recommends UpperCamelCase for type aliases and struct, trait, enum, and enum variant names, SCREAMING_SNAKE_CASE for constants or statics and snake_case for variable, function and struct member names.[44]

Swift

[edit]

Swift has shifted its naming conventions with each individual release. However a major update with Swift 3.0 stabilised the naming conventions for lowerCamelCase across variables and function declarations. Constants are usually defined by enum types or constant parameters that are also written this way. Class and other object type declarations are UpperCamelCase.

As of Swift 3.0 there have been made clear naming guidelines for the language in an effort to standardise the API naming and declaration conventions across all third party APIs. [45]

See also

[edit]

References

[edit]
  1. ^ Derek M. Jones "Operand names influence operator precedence decisions" An experiment investigating the effect of variable names on operator precedence selection
  2. ^ Raymond, Eric S. (1 October 2004). "religious issues". The Jargon File (version 4.4.8 ed.). Retrieved 7 November 2011.
  3. ^ Binkley, Dave; Davis, Marcia (2009). "To camelcase or under_score" (PDF). 2009 IEEE 17th International Conference on Program Comprehension. pp. 158–167. doi:10.1109/ICPC.2009.5090039. ISBN 978-1-4244-3998-0. S2CID 1450798.
  4. ^ Naming a Package
  5. ^ "CSS reference". Mozilla Developer Network. Retrieved 18 June 2016.
  6. ^ "StackOverflow – What's the name for snake_case with dashes?".
  7. ^ "Programmers – If this is camelCase what-is-this?". Archived from the original on 7 August 2016. Retrieved 13 August 2015.
  8. ^ "Camel_SNAKE-kebab". GitHub. September 2019.
  9. ^ UnderscoreVersusCapitalAndLowerCaseVariableNaming
  10. ^ jwfearn (5 September 2012). "Revisions to jwfearn's answer to What's the name for dash-separated case?".
  11. ^ Living Clojure (2015), by Carin Meier, p. 91
  12. ^ lodash: kebabCase
  13. ^ a b c "naming - What are the different kinds of cases?". Stack Overflow. Retrieved 16 August 2020.
  14. ^ "A brief list of programming naming conventions". deanpugh.com. 20 March 2018. Retrieved 16 August 2020.
  15. ^ "Naming conventions". doc.rust-lang.org. Retrieved 2 May 2023.
  16. ^ "camel-snake-kebab". camel-snake-kebab. Retrieved 16 August 2020.
  17. ^ "Making Wrong Code Look Wrong". Joel on Software. 11 May 2005.
  18. ^ "Flex SDK coding conventions and best practices". SourceForge.
  19. ^ "3.2.1 Names - Chapter 3 - Ada 95 QUALITY AND STYLE Guide".
  20. ^ "ISO/IEC 9899:1999 Programming languages – C". ISO.
  21. ^ "ISO/IEC 14882:2011 Information technology – Programming languages – C++". ISO.
  22. ^ "Naming Guidelines". Microsoft. 15 September 2021.
  23. ^ "Names of Type Members". Microsoft. 15 September 2021.
  24. ^ "Effective Dart - the Dart Style Guide".
  25. ^ "Effective Go - the Go Programming Language".
  26. ^ a b "Code Conventions for the Java Programming Language", Section 9: "Naming Conventions"
  27. ^ "NETSCAPE'S SOFTWARE CODING STANDARDS GUIDE FOR JAVA",Collab Software Coding Standards Guide for Java Archived 3 March 2009 at the Wayback Machine
  28. ^ "AmbySoft Inc. Coding Standards for Java v17.01d"
  29. ^ Morelli, Brandon (17 November 2017). "5 JavaScript Style Guides – Including AirBnB, GitHub, & Google". codeburst.io. Retrieved 17 August 2018.
  30. ^ "Variables".
  31. ^ Naming conventions on CLiki
  32. ^ Microsoft .NET Framework Capitalization Styles
  33. ^ .NET Framework Developer's Guide – General Naming Conventions
  34. ^ [Framework Design Guidelines, Krzysztof Cwalina, Brad Abrams Page 62]
  35. ^ Modula-2 Name Convention
  36. ^ "Foreign API Identifiers in Modula-2 Name Convention". Archived from the original on 10 September 2016. Retrieved 15 June 2016.
  37. ^ "Perl style guide".
  38. ^ "perlmodlib – constructing new Perl modules and finding existing ones".
  39. ^ "PHP standards recommendations".
  40. ^ "PSR-1: Basic Coding Standard - PHP-FIG".
  41. ^ Style Guide for Python Code PEP8
  42. ^ Style Guide for RCode
  43. ^ "General rules of Perl 6 syntax".
  44. ^ "Naming conventions". doc.rust-lang.org. Retrieved 4 February 2018.
  45. ^ "swift.org API Design Guidelines".
[edit]
东北大拉皮是什么做的 什么的野鸡 喝什么茶去湿气最好 冬虫夏草有什么作用 什么叫总胆固醇
菊花和枸杞泡水喝有什么功效 映景是什么意思 菠萝和凤梨有什么区别 为什么这么热 st是什么单位
小孩记忆力差需要补充什么营养 包子有什么馅的 氡气是什么 癫痫病是什么症状 同性恋是什么
fb是什么意思 梦见和死人说话是什么意思 总蛋白偏低是什么原因 柠檬配什么泡水喝最好 婚姻是爱情的坟墓是什么意思
排骨焖什么好吃hcv8jop8ns6r.cn 富贵病是什么病hcv8jop0ns7r.cn 美林是什么药hcv7jop4ns8r.cn 猪肉不能和什么一起吃hcv7jop5ns6r.cn 为什么睡不着觉会胡思乱想hcv7jop9ns0r.cn
濯清涟而不妖的濯是什么意思hcv8jop2ns6r.cn 1月出生是什么星座hcv7jop6ns0r.cn 什么花在什么时间开hcv8jop8ns1r.cn 母字是什么结构hcv8jop3ns4r.cn 女人脸肿是什么原因引起的hcv8jop6ns1r.cn
吃红薯有什么好处cl108k.com 感冒发烧挂什么科室hcv7jop7ns4r.cn 四妙丸有什么功效与作用hcv9jop0ns0r.cn 燕子喜欢吃什么hcv9jop7ns3r.cn 靖康耻指的是什么历史事件hcv8jop1ns6r.cn
人的三观是什么hcv9jop1ns7r.cn 飞机上可以带什么吃的liaochangning.com 慢性肾炎是什么原因引起的hcv8jop3ns2r.cn 布洛芬不能和什么一起吃hcv8jop1ns9r.cn 桃花有什么颜色hcv7jop9ns7r.cn
百度