var名称中的分隔符 [英] Separators inside a var name
问题描述
我有一个风格问题。在大多数语言中,var。名称是由下划线或上限字母分隔的
,导致var名称如
var_name,VarName和varName。我不是那么喜欢,因为所有的命名方式都很糟糕和/或很难打字。据我所知,
方案可以有像var-name这样的变量。我很好奇python选择禁止这个的原因
。我的另一个问题是
其他语言是否允许这种命名方案?是否有任何语言
允许空格作为分隔符?在这种情况下,从关键字中分离变量的实际方法是什么? 一些长变量
name",''只是一个字符串'',或者可能使用2个空格:一个var + other
var + third var?我认为能够轻松拥有很长的名字
对于易于打字的变量来说,这将是一个相当重要的优势。我知道我可能对此过于痴迷,但
并没有阻止我发布。评论?
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don''t like that very much because all
3 ways of naming look bad and/or hard to type. From what I understand,
scheme can have variables like var-name. I''m curious about reasons
that python chose to disallow this. Another question I have is what
other languages allow this naming scheme? Were there any languages
that allowed space as a separator? What would be a practical way to
separate variables from keywords in that case? "some long variable
name", ''just a string'', or maybe using 2 spaces: one var + other
var + third var ? I think being able to easy have very long names
for vars that are easy to type would be a fairly significant
advantage. I know I''m probably being too obsessive about this, but
that didn''t stop me from posting. Comments?
推荐答案
Rainy写道:
Rainy wrote:
我有一个风格问题。在大多数语言中,var。名称是由下划线或上限字母分隔的
,导致var名称如
var_name,VarName和varName。我不是那么喜欢,因为所有的命名方式都很糟糕和/或很难打字。据我所知,
方案可以有像var-name这样的变量。我很好奇python选择禁止这个的原因
。
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don''t like that very much because all
3 ways of naming look bad and/or hard to type. From what I understand,
scheme can have variables like var-name. I''m curious about reasons
that python chose to disallow this.
因为我们更喜欢var-name表示减去值:var minus
name。如果你想在名字中使用那个字符,你更喜欢减法的语法是什么?b $ b你认为lisp / scheme( - b)在Python中是合理的吗?
Because we''d prefer var-name to mean subtraction of values: var minus
name. If you want to use a that character in names, what syntax would
you prefer for subtraction? Do you consider lisp/scheme (- a b) to be
reasonable in Python?
我的另一个问题是
其他语言是否允许这种命名方案?是否有任何语言
允许空格作为分隔符?
Another question I have is what
other languages allow this naming scheme? Were there any languages
that allowed space as a separator?
Fortran曾经。 (多年来我没有检查过它,所以我现在不知道
)。它不是允许空间,因为它*忽略*所有
空格。现在这被认为是一个非常糟糕的想法,并且据传传闻要对一颗撞毁卫星的错误负责。 (至少
这就是一个不错的都市传奇所说的。)
Fortran used to. (Haven''t checked in on it in years though so I don''t
know now). And it not so much as allowed spaces as it *ignored* all
spaces. This was now-a-days considered a *really* bad idea, and is
rumored to be responsible for a bug that crashed a satellite. (At least
that''s the way a nice urban legend tells it.)
什么是实用的方式来/>
在这种情况下,与关键字分开的变量是什么? 一些长变量
name",''只是一个字符串'',或者可能使用2个空格:一个var + other
var + third var?我认为能够轻松拥有很长的名字
对于易于打字的变量来说,这将是一个相当重要的优势。我知道我可能对此过于痴迷但是
并没有阻止我发布。评论?
-
http://mail.python.org/mailman/listinfo/python-list
6月9日,1:42 * pm, Gary Herron< gher ... @ islandtraining.comwrote:
On Jun 9, 1:42*pm, Gary Herron <gher...@islandtraining.comwrote:
Rainy写道:
Rainy wrote:
我有一个风格问题。在大多数语言中,var。名称是由下划线或上限字母分隔的
,导致var名称如
var_name,VarName和varName。我不是那么喜欢,因为所有的命名方式都很糟糕和/或很难打字。据我所知,
方案可以有像var-name这样的变量。我很好奇python选择禁止这个的原因
。
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don''t like that very much because all
3 ways of naming look bad and/or hard to type. From what I understand,
scheme can have variables like var-name. I''m curious about reasons
that python chose to disallow this.
因为我们更喜欢var-name表示减去值:var minus
name。 *如果你想在名字中使用那个字符,你希望减法使用什么语法?b $ b? *你认为lisp / scheme( - b)在Python中是合理的吗?
Because we''d prefer var-name to mean subtraction of values: var minus
name. *If you want to use a that character in names, what syntax would
you prefer for subtraction? *Do you consider lisp/scheme (- a b) to be
reasonable in Python?
我会认为var - var2是减法和var-name
将是
a var名称。我不喜欢( - b)但我可能更喜欢它,如果它允许在var名称中使用破折号,如果我已经习惯了它。很难说。
I would make it that var - var2 would be subtraction and var-name
would be
a var name. I don''t like (- a b) but I might have preferred it if it
allowed dashes inside var names, if I got used to it. Hard to say.
>
>
我的另一个问题是
其他语言是否允许这种命名方案?是否有任何语言
允许空格作为分隔符?
Another question I have is what
other languages allow this naming scheme? Were there any languages
that allowed space as a separator?
Fortran曾经。 *(多年来我没有检查过它,所以我现在不知道
)。 *它不是允许的空间,因为它*忽略*所有
空格。 *现在这被认为是一个非常糟糕的想法,并且传闻要对导致卫星坠毁的错误负责。 *(至少
,这是一个不错的都市传奇所说的。)
Fortran used to. *(Haven''t checked in on it in years though so I don''t
know now). *And it not so much as allowed spaces as it *ignored* all
spaces. *This was now-a-days considered a *really* bad idea, and is
rumored to be responsible for a bug that crashed a satellite. *(At least
that''s the way a nice urban legend tells it.)
好吧,如果我理解正确,fortran用过很多东西?我是
不确定
如果它忽略了所有空格,它是如何分开的。我会相信你
这是不是一个好主意:-)。然而,这不是我的意思,我只想
使用
(或者更确切地说,尝试使用)var名称中的空格。
Well, if I understand right, fortran used caps for many things? I''m
not sure
how it separated things if it ignored all spaces. I''ll trust you that
it''s
not a good idea :-). However that''s not what I meant, I''d just like to
use
(or rather try using) spaces inside var names.
Rainy< an ******** @ gmail.comat Montag 09 Juni 2008 19:29:
Rainy <an********@gmail.comat Montag 09 Juni 2008 19:29:
我有一个风格问题。在大多数语言中,var。名称是由下划线或上限字母分隔的
,导致var名称如
var_name,VarName和varName。我不是那么喜欢,因为所有的命名方式都很糟糕和/或很难打字。
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don''t like that very much because all
3 ways of naming look bad and/or hard to type.
然后你最好习惯这样的名字,因为它们很常见于许多广泛的b
传播语言,包括C,C ++,C#,Java ,Python,Ruby,Perl和许多
更多;)你可能会喜欢这些或不喜欢这些名字,但你不会来这周围来的
;)
Then you better get used to such names, as they are common for many widely
spread languages including C, C++, C#, Java, Python, Ruby, Perl and many
more ;) You may like these or dislike these names, but you won''t come
around them ;)
据我所知,scheme可以包含var-name等变量。我很好奇,因为python选择不允许这样做的原因。
From what I understand, scheme can have variables like var-name. I''m
curious about reasons that python chose to disallow this.
" - "是Python中的运算符。解析器应该如何知道,
是否var-name表示绑定到var_dash_name的对象或者减去
从绑定到var的对象绑定名称的对象?
Scheme可以允许这样的名称,因为它是一种函数式编程语言。
用这种语言减法不是通过运算符来完成的,而是通过
函数完成的。因此,引用
名称或减去两个名称之间存在明显差异:var-name vs( - var name)。
"-" is an operator in Python. How should the parser know,
whether "var-name" means "the object bound to var_dash_name" or "subtract
the object bound to name from the object bound to var"?
Scheme can allows such names, because its a functional programming language.
Subtracting in this language is not done through operators, but through
functions. Therefore there is a clear difference between referencing a
name or subtracting two ones: var-name vs (- var name).
Another问题我有其他语言允许这种命名方案吗?
Another question I have is what other languages allow this naming scheme?
其他lisp方言,由于与方案相同的原因。
Other lisp dialects do, due to the same reasons as scheme.
是否有任何语言允许空格作为分隔符?
Were there any languages that allowed space as a separator?
我不知道。也许有人可以使用unicode字符,看起来就像语言中的空格一样,它允许标识符中的unicode字符
(如Java或C#,iirc),但我怀疑这一点。无论如何,即使允许,这个
也会很愚蠢,因为它会使代码模糊到读者眼中。
None that I know of. Probably one could use unicode characters, that look
like a space in languages, which allow unicode characters in identifiers
(as Java or C#, iirc), but I doubt this. Anyway, even if allowed, this
would be silly, since it obscures code to the eyes of the reader.
什么是在
案例中将变量与关键字分开的实用方法? 一些长变量名称,只是一个字符串,或者可能使用2个空格:
一个var +其他var +第三个var?
What would be a practical way to separate variables from keywords in that
case? "some long variable name", ''just a string'', or maybe using 2 spaces:
one var + other var + third var ?
我不能用实际的方式想象一个空格作为名字中的字符,而
仍然保持它的分离语法元素的名字。行情是
通常用于字符串或字符文字,双空格很难
来区分单个空格,例如
I can''t image a practical way to allow a space as character in names, while
still maintaining it syntactic element for separation of names. Quotes are
normally used for string or characters literals and a double space is hard
to distinguish from a single space, and things like
这篇关于var名称中的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!