目录
BCPL、B、C语言比较
如果想要找到一种好的方式,来进行编程语言之间比较的话,那么非代码莫属。
3种语言代码示例
下面分别使用BCPL、B、C三种语言实现一个简单的程序:程序将三个数字a、b、c相加,并将结果赋值给sum,最后打印总和。
BCPL语言示例
BCPL https://zh.wikipedia.org/wiki/BCPL
GET "libhdr"
LET start() = VALOF
{ LET a, b, c = 1, 2, ,3
sum := a + b + c
writen(sum)
}
-
LET 声明变量
-
:=
符号为赋值符号 Go中也有该符号,表示函数内部局部变量。这里感觉很有意思的一点是:最初B语言之父肯.汤普逊
把:=
符号改成了=
符号。现在,也作为Go语言之父之一,又把:=
符号请回来了(冥冥之中的命运~)。
从BCPL到B的过渡中,决定使用单个字符 = 代替赋值 :=
Other fiddles in the transition from BCPL to B were introduced as a matter of taste, and some remain controversial,
for example the decision to use the single character = for assignment instead of :=
. Similarly, B uses /**/ to enclose comments, where BCPL uses //, to ignore text up to the end of the line. The legacy of PL/I is evident here. (C++ has resurrected the BCPL comment convention.) Fortran influenced the syntax of declarations: B declarations begin with a specifier like auto or static, followed by a list of names, and C not only followed this style but ornamented it by placing its type keywords at the start of declarations.https://www.bell-labs.com/usr/dmr/www/chist.html