为什么大多数语言中的函数调用都选择括号?

发布于 2024-12-23 08:48:47 字数 607 浏览 3 评论 0原文

在梦想一种新的编程语言(关键词:梦想)时,我想知道为什么为函数调用选择括号。例如,在大多数编程语言中,函数调用看起来像这样:

print("Hello, world!");

这个决定是基于编程出现之前的代数函数吗?如果这是真的,也许可以用不同的方式来问这个问题。在我看来,括号更容易输入。它们通常与括号键更接近或一样接近;另外,它们不需要 Shift 键。为什么括号放在键盘上比括号更容易的位置?无论是否编程,圆括号的使用都比方括号多得多(除非您是铁杆 Objective-C 程序员)。

编辑:这与我的问题的后半部分非常相关,但仍然没有涵盖第一部分:为什么打字难吗在标准键盘上,括号 () 比方括号 [] 更好吗?

编辑2:我不太确定这不是建设性的。它不符合非建设性投票结束选项下的描述。

Whilst dreaming up a new programming language (keyword: dreaming), I wondered why parentheses were chosen for function calls. For example, in most programming languages, a function call would look like this:

print("Hello, world!");

Was this decision based on algebraic functions from the time before programming was around? Perhaps the question could be asked in a different way if this were true. In my opinion, brackets are easier to type. They are typically closer or just as close as the parentheses keys; plus, they don't require a shift key. Why were brackets placed in an arguably easier location on the keyboard than parentheses? Programming or not, parentheses are used much more than brackets (unless you are a hardcore Objective-C programmer).

EDIT: This is very related for the second half of my question but still doesn't cover the first part: Why is it harder to type parentheses () than square brackets [] on a standard keyboard?

EDIT 2: I'm not too sure how this isn't constructive. It does not fit the description under the not constructive vote-to-close option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

避讳 2024-12-30 08:48:47

曲线可以通过一个动作来书写,使它们更容易书写。

即使方括号最初是由古典数学家使用的,快速书写也会将它们变成更圆润的字符。从那时起,这种风格就转移到了编程语言中。我想同样的理论可以回答为什么括号是英语中的主要括号。

Curves can be written in a single motion, making them easier to write.

Even if square brackets had originally been used by classical mathematicians, writing quickly would transform these into more rounded characters. From then the style was transferred to programming languages. I would imagine the same theory answers why parentheses are the dominant bracket in English.

冰雪之触 2024-12-30 08:48:47

语言最初的创建是为了帮助我们让计算机执行其名称所暗示的功能:计算。今天使用的各种括号(“圆括号”更多是一个美国术语)最初都存在于数学中。我们用大括号表示集合,用方括号表示数量和闭区间,用括号表示列表、开区间、坐标等。目标是能够自然地表达我们现有的公式,这是合乎逻辑的。这可能在现代使用中发挥了直接作用,就像新语言从之前的语言借用了概念一样。这不仅仅是符号,还有我们今天在计算机科学中使用的许多单词。

我不同意这样的论点,即按键布局和手指接近度应该在改变当时使用的符号方面发挥作用。 回顾键盘的历史将向我们展示,有许多不同的键盘布局。像 Apple II 这样的计算机甚至没有专用的方括号键。另外,众所周知,如今的主流布局(QWERTY)就是这样设计的,更注重防止打字栏堵塞,而不是轻松打字。

庆幸的是你没有使用德沃夏克。这些方括号就在括号旁边。 ;)

Languages were initially created to help us make computers do what their name implied: compute. The various brackets ('parenthesis' is more of an American term) used today all existed in mathmatics originally. We had curly brackets for sets, square brackets for quantities and closed intervals, parenthesis for lists, open intervals, coordinates, etc. It makes logical sense that the goal was to be able to naturally express our existing formulas. That likely played a direct role in the modern usage much like newer languages borrow concepts from the languages before them. It's not just the symbols, it's also many of the words we use in computer science today.

I would disagree with the argument that key layout and finger proximity should've played a role in changing which symbols were used at that time. As a look back at the history of keyboards will show us, there have been many different layouts. Computers like the Apple II didn't even have dedicated square bracket keys whatsoever. Plus, as we all know, the dominate layout these days (QWERTY) was made that way with more focus on preventing type bar jamming than easy typing.

Just be happy you don't use Dvorak. Those square brackets are right next to the parenthesis. ;)

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