关键字采用的变量名——你的例子?
是否有过这样的情况:您想使用某个单词作为变量/函数名称,但由于它是您语言中的保留字而无法使用?
对我来说一次又一次出现的是 C# 中的 in
和 out
...这些对于流来说是很好的名称,但我总是被迫使用相反,inn
和outt
。
编辑:我并不是在寻求解决这个问题的帮助——我只是想从过去的语言设计者所犯的错误中吸取教训。您的答案将影响我正在设计的语言。
Have there been any cases where you wanted to use a word as a variable/function name, but couldn't because it was a reserved word in your language?
The ones that crop up over and over again for me are in
and out
in C#... Those would be great names for streams, but I'm always forced to use inn
and outt
instead.
EDIT: I'm not asking about help with this problem -- I'm trying to learn from mistakes that past language designers have made. Your answers will influence a language I'm designing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
类型
和对象
。我不喜欢我的编程语言窃取这些:(type
andobject
. I don't like when my programming languages steal those :(有些语言允许您在任何地方使用任何您想要的单词。例如,Clojure:
根据上下文,这可能有用也可能很糟糕。
Some languages let you use any words you want anywhere. Clojure, for example:
This could either be helpful or horrible depending on the context.
我非常喜欢在面向对象的 C 代码中使用
new
和delete
作为函数指针字段,这使得移植到 C++ 变得“有趣”......呃。不过,这对于 C# 来说并不是真正的问题:
现在您有一个名为
in
的变量。I like to use
new
anddelete
as function pointer fields in OO-ish C code a lot, which makes porting to C++ "fun"... ugh.This isn't really a problem for C#, though:
There, now you have a variable named
in
.不,不是真的。语言中的关键字往往简短而笼统——这两点很少能构成好的变量名。
No, not really. Keywords in a language tend to be short and general - two things that rarely make for good variable names.
在这些情况下,我将“in”和“out”视为形容词,并且通常会使用更具描述性的内容,例如“inStream”和“outStream”。
In those cases, I think of "in" and "out" as adjectives, and usually make something more descriptive, such as "inStream" and "outStream".