关键字采用的变量名——你的例子?

发布于 2024-08-10 09:07:59 字数 269 浏览 2 评论 0原文

是否有过这样的情况:您想使用某个单词作为变量/函数名称,但由于它是您语言中的保留字而无法使用?

对我来说一次又一次出现的是 C# 中的 inout...这些对于流来说是很好的名称,但我总是被迫使用相反,innoutt

编辑:我并不是在寻求解决这个问题的帮助——我只是想从过去的语言设计者所犯的错误中吸取教训。您的答案将影响我正在设计的语言。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我很OK 2024-08-17 09:07:59

类型对象。我不喜欢我的编程语言窃取这些:(

type and object. I don't like when my programming languages steal those :(

江湖正好 2024-08-17 09:07:59

有些语言允许您在任何地方使用任何您想要的单词。例如,Clojure:

(let [let "what?"] let)
=> "what?"

根据上下文,这可能有用也可能很糟糕。

Some languages let you use any words you want anywhere. Clojure, for example:

(let [let "what?"] let)
=> "what?"

This could either be helpful or horrible depending on the context.

瑶笙 2024-08-17 09:07:59

我非常喜欢在面向对象的 C 代码中使用 newdelete 作为函数指针字段,这使得移植到 C++ 变得“有趣”......呃。

不过,这对于 C# 来说并不是真正的问题:

int @in;

现在您有一个名为 in 的变量。

I like to use new and delete 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:

int @in;

There, now you have a variable named in.

夜吻♂芭芘 2024-08-17 09:07:59

不,不是真的。语言中的关键字往往简短而笼统——这两点很少能构成好的变量名。

No, not really. Keywords in a language tend to be short and general - two things that rarely make for good variable names.

与酒说心事 2024-08-17 09:07:59

在这些情况下,我将“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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文