在 var id 的左边还是右边输入 id?
许多流行语言使用的两种常见变量声明语法背后的原因是什么,例如: int foo = 0; 和 foo:int = 0;
我对第二个选项的一个问题是,它看起来几乎就像你正在做的那样,“int = 0;”。为什么语言使用特定的方式?是否更容易解析或类似的东西?
What is the reasoning behind the two common variable declaration syntax that many popular languages use, such as:
int foo = 0;
and
foo:int = 0;
One problem I have with the second option, is that it almost looks like you are doing, "int = 0;". Why do languages use a particular way? Is it easier to parse or something of the like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我研究了编译器开发的基础知识,并且在给出实际解决方案和技术的情况下,我认为解析器在这两种情况下都没有任何问题。
对我来说,这显然是人眼可读性的问题。 更容易阅读。
我认为
int foo = 0
比
foo:int = 0
事实上,我想说,简单地编写
foo = 0< 更容易/code>,因为人们可以识别
0
是一个整数:) 我个人喜欢这种方法,而不是使用类型标识符。I have studied the basics of compiler development and I do not think that parsers have any problem at all in both cases given actual solutions and techniques.
For me it's clearly a matter of readability from human eyes. I think it's easier to read
int foo = 0
than
foo:int = 0
In fact, I would say that it's even easier to simply write
foo = 0
, since one can recognize that0
is an integer number :) I personally like this approach, instead of having type identifiers.