新的编码标准:在命令(和标识符)名称中使用下划线,连字符或混合大小写 [英] New coding standards: use underscores, hyphens or mixed case in command (and identifier) names

查看:72
本文介绍了新的编码标准:在命令(和标识符)名称中使用下划线,连字符或混合大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我开始一个新的长期项目之前,我将非常感谢你就如何分割

长名称提出建议。我想保持命令名称的标准与

变量名称的标准相同。看下面的例子,哪些看起来更好?


直的名字

echoclient

lastcharoffset

helloworld


内部下划线

echo_client

last_char_offset

hello_world

我也可以使用嵌入式连字符,因为我的减号必须用空格包围

(请在看这些时暂停怀疑。我知道它们看起来会不熟悉!)

echo-client

last-char-offset

hello-world


混合案例

EchoClient

LastCharOffset

HelloWorld


初始小写然后混合

echoClient
lastCharOffset

helloWorld


在某些方面,我喜欢使用初始资本的混合案例版本,特别是因为我可能

想要为某些名称添加一个抽象数据类型的代码,当存在时,

可以从较低的开始案件。这是否太过微软了?它是否已经到了
匈牙利语?当与抽象数据类型而不是内置数据类型一起使用时,匈牙利语是否会变坏?


我们非常感谢您认为可接受或不被认可的建议。请

请记住,我打算将这些名称用于命令/指令以及变量和

类型。常数将全部上限。


-

谢谢,

詹姆斯


Before I embark on a new long-term project I''d appreciate your advice on how to split up
long names. I would like to keep the standards for command names the same as that for
variable names. Looking at the examples below, which ones seem better?

Straight names
echoclient
lastcharoffset
helloworld

Internal underscores
echo_client
last_char_offset
hello_world

I could also use embedded hyphens as my minus sign must be surrounded by whitespace
(please suspend disbelief while looking at these. I know they will look unfamiliar!)
echo-client
last-char-offset
hello-world

Mixed case
EchoClient
LastCharOffset
HelloWorld

Initial lower case then mixed
echoClient
lastCharOffset
helloWorld

In some ways I like the mixed case versions using an inital capital, especially as I may
want to prefix some names with a code for an abstract data type, which, when present,
could begin with a lower case. Is this getting too Microsoft-ish? Is it getting to
Hungarian? Is Hungarian bad when used with abstract data types rather than inbuilt ones?

Advice on which is or is not thought to be acceptable would be much appreciated. Please
bear in mind that I intend these names for commands/instructions as well as variables and
types. Constants would be in all caps.

--
Thanks,
James

推荐答案

James Harris aformulélademande:
James Harris a formulé la demande :
在我开始一个新的长期项目之前,我将非常感谢您对如何使用
拆分长名。我想保持命令名称的标准



的标准相同没有标准。它可能有公司规则你是b $ b应该跟随(或创建)

变量名。看看下面的例子,哪些似乎更好?


''命令名'是什么意思?没有像''命令''这样的东西在C.中


直的名字
echoclient
lastcharoffset
helloworld


我不能读(和其他人一样)。

内部下划线
echo_client
last_char_offset
hello_world


好​​的

我也可以使用嵌入式连字符,因为我的减号必须用
空格包围


没有这样的C中的东西。

混合案例
EchoClient
LastCharOffset
HelloWorld


好​​

最初的小写然后混合了
echoClient
lastCharOffset
你好世界


对我来说听起来很难看,但谁在乎...

在某些方面,我喜欢使用初始资本的混合大小写版本,特别是因为我可能想要为一些名称添加一个抽象的数据类型的代码,如果存在,可以从一个小写。这是否太过微软了?它是匈牙利人吗?当与抽象数据类型而不是内置数据类型一起使用时,匈牙利语是不是很糟糕?
Before I embark on a new long-term project I''d appreciate your advice on how
to split up long names. I would like to keep the standards for command names
the same as that for
There is not standard about that. It may have company rules you are
supposed to follow (or create)
variable names. Looking at the examples below, which ones seem better?
What do you mean by ''command name'' ? No such a thing like a ''command''
in C.
Straight names
echoclient
lastcharoffset
helloworld
Unreadable to me (and others, I guess).
Internal underscores
echo_client
last_char_offset
hello_world
Ok
I could also use embedded hyphens as my minus sign must be surrounded by
whitespace
No such a thing in C.
Mixed case
EchoClient
LastCharOffset
HelloWorld
Ok
Initial lower case then mixed
echoClient
lastCharOffset
helloWorld
Sounds ugly to me, but who cares...
In some ways I like the mixed case versions using an inital capital,
especially as I may want to prefix some names with a code for an abstract
data type, which, when present, could begin with a lower case. Is this
getting too Microsoft-ish? Is it getting to Hungarian? Is Hungarian bad when
used with abstract data types rather than inbuilt ones?




原始的Hugarian很好,


a_xxx:数组

p_yyy:指针

s_zzz:字符串



但匈牙利语à-la-微软(键入)是邪恶的,难以阅读和

维持。


-

Ceci est une signature automatique de MesNews 。

网站: http://mesnews.no-ip.com



Original Hugarian is good,

a_xxx : array
p_yyy : pointer
s_zzz : string
etc.
but Hungarian à-la-Microsoft (typed) is evil and hard to read and
maintain.

--
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com


James Harris< no.email.please>潦草地写了下面的内容:
James Harris <no.email.please> scribbled the following:
在我开始一个新的长期项目之前,我会感谢你就如何拆分长名称提出建议。我想保持命令名称的标准与
变量名称的标准相同。看看下面的例子,哪些似乎更好?
我也可以使用嵌入式连字符,因为我的减号必须被空白包围
(请在看这些时暂停怀疑。我知道它们看起来会不熟悉!)
echo-client
last-char-offset
hello-world
Before I embark on a new long-term project I''d appreciate your advice on how to split up
long names. I would like to keep the standards for command names the same as that for
variable names. Looking at the examples below, which ones seem better? I could also use embedded hyphens as my minus sign must be surrounded by whitespace
(please suspend disbelief while looking at these. I know they will look unfamiliar!)
echo-client
last-char-offset
hello-world




因为连字符何时是C标识符中的合法字符?


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰--- ----- \

\ - http: //www.helsinki.fi/~palaste ---------------------规则! -------- /

我们怎样才能用性来获得我们想要的东西?性是我们想要的。

- Frasier Crane博士



Since when was the hyphen a legal character in a C identifier?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane


James Harris< no.email.please>写道:
James Harris <no.email.please> wrote:
在我开始一个新的长期项目之前,我会感谢你对如何拆分长名称的建议。我想保持
命令名称的标准与变量名称的标准相同。看看下面的例子,哪些看起来更好?


请将你的行长度修改为大约70左右(我重新格式化了

文本以使其可读)。

Straight姓名
echoclient
lastcharoffset
helloworld
内部下划线
echo_client
last_char_offset
hello_world


我我会更喜欢第二种,因为它更容易阅读,而b
拼写错误更易于识别。只需比较


lastcharoffset< - > last_char_offset

lastcharofset< - > last_char_of_set


我应该立即明白为什么我会这样。

我也可以使用嵌入式连字符,因为我的减号必须被包围
通过空白(请在看这些时暂停怀疑。我知道
他们看起来会不熟悉!)
echo-client
last-char-offset
hello-world


嗯?除非你在

之前对源代码进行一些自动转换,否则你将它传递给你不会做你期望的编译器......

混合案例 EchoClient
LastCharOffset
HelloWorld
初始小写然后混合
echoClient
lastCharOffset
helloWorld
在某些方面我喜欢混合大小写版本使用一个初始资本,


好​​吧,我仍然更喜欢带有下划线的版本,因为它们好像b $ b似乎更容易阅读(你立即看到
单词,因为我们受过训练以期待单词之间的空格)但

在单词开头的大写字母给你至少很多

更多的视觉线索然后没有。

使用大写字符的问题是当你想要编写一些额外的

时,意味着使用大写/小写,例如:有全局变量

总是以大写字母开头但是其他所有内容都是

小写和大写所有单词的开头是typedef''的东西

喜欢


Var_array< - 全局变量

Var_Type< - 标题中某处带有typedef的类型

特别是因为我可能想要为某些名称添加一个抽象数据类型的代码,如果存在,可以从较低的
情况开始。这是否太过微软了?是匈牙利人吗?
匈牙利人在使用抽象数据类型而不是内置的数据时是不是很糟糕?


好​​吧,很多人都不喜欢匈牙利表示法(我承认其中一个是b $ b b)因为


a )一开始所有的东西都让你更难阅读,因为你总是要扫描真正的变量名,特别是在没有介入下划线的情况下使用
并且你结束了名字好像

喜欢''rgbsyHash''或''rgwDic''(直接来自一篇文章

http://cm-solutions.com/cms/technica...convention.htm

由它的发明者Simonyi,它很好地显示了为什么不使用它,

示例代码主要看起来好像它已经腐烂13',


b)如果你离一个变量的定义那么远,那么它很难看起来很繁琐(而且你不能记住它然后

你的功能可能已经变得太长了


c)或者,如果这是一个在其他地方定义的变量,那么

应该有一个至少给你一个名字的名字它的

类型的线索是什么。

对于或不被认为可接受的建议将非常感激。请记住,我打算将这些名称用于
命令/指令以及变量和类型。常量将全部上限。
Before I embark on a new long-term project I''d appreciate your advice
on how to split up long names. I would like to keep the standards for
command names the same as that for variable names. Looking at the
examples below, which ones seem better?
Please fix your line lenghts to something of around 70 (I reformatted
the text to make things readable).
Straight names
echoclient
lastcharoffset
helloworld Internal underscores
echo_client
last_char_offset
hello_world
I would much prefer the second since it''s way easier to read and
typos are easier to recognize. Just compare

lastcharoffset <-> last_char_offset
lastcharofset <-> last_char_of_set

and it should become clear immediately why I feel that way.
I could also use embedded hyphens as my minus sign must be surrounded
by whitespace (please suspend disbelief while looking at these. I know
they will look unfamiliar!)
echo-client
last-char-offset
hello-world
Huh? Unless you do some automatic conversion of the source code before
you pass it to the compiler that won''t do what you expect...
Mixed case
EchoClient
LastCharOffset
HelloWorld Initial lower case then mixed
echoClient
lastCharOffset
helloWorld In some ways I like the mixed case versions using an inital capital,
Well, I still would prefer the version with underscores since they
seem still easier to read (you immediately see the subdivision in
words because we''re trained to expect spaces between words) but
having the upper case at the start of words gives you at least a lot
more visual clues then without. What becomes a problem with the
use of upper case characters is when you want to code some extra
meaning into the use of upper/lower case, e.g. have global variables
always start with an upper case character but everything else in
lower case and upper case for all word starts for typedef''ed stuff
like in

Var_array <- a global variable
Var_Type <- a type with a typedef somewhere in the headers
especially as I may want to prefix some names with a code for an
abstract data type, which, when present, could begin with a lower
case. Is this getting too Microsoft-ish? Is it getting to Hungarian?
Is Hungarian bad when used with abstract data types rather than
inbuilt ones?
Well, lots of people loath Hungarian notation (and I am admittedly
one of them) because

a) all that stuff at the start makes it harder to read since you
always have to scan for the real variable name, especially when
used without an intervening underscore and you end up with names
like ''rgbsyHash'' or ''rgwDic'' (as taken directly from an article

http://cm-solutions.com/cms/technica...convention.htm

by its inventor Simonyi, it shows rather nicely why not to use it,
the example code mostly looks to me as if it had been rot13''ed),

b) if you''re that far away from the definition of a variable that
it gets tedious to look it up (and you can''t remember it) then
your function probably has already become too long

c) or, if this is a variable that is defined somewhere else, it
should have a name that at least gives you a clue to what its
type is.
Advice on which is or is not thought to be acceptable would be much
appreciated. Please bear in mind that I intend these names for
commands/instructions as well as variables and types. Constants would
be in all caps.




我倾向于只用小写字母写函数名 - 这是一个

功能通常是明显的,因为括号后面是

它。

问候,Jens

-

\\ \\ Jens Thoms Toerring ___ Je***********@physik.fu -berlin.de

\ __________________________ http:// www .toerring.de


这篇关于新的编码标准:在命令(和标识符)名称中使用下划线,连字符或混合大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆