回 帖 发 新 帖 刷新版面

主题:[讨论]给学 BASIC 的人泼一盆冷水

实际上如果一个程序员先学了BASIC,那就很难教会他好的编程技术了:作为一个
可能的程序员,他们的神经已经错乱了,而且无法康复。


          ------------------------  Dijkstra

    这句话是计算机科学家 迪克斯特拉 说的,他是计算机界的最高奖项《图灵奖》的获
得者之一。在软件开发上,是世界上屈指可数的大师之一,著名的最短路径
算法 dijkstra 算法就是他提出的。

下面是他的 goto 有害论

Go To Statement Considered Harmful

For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce. More recently I discovered why the use of the go to statement has such disastrous effects, and I became convinced that the go to statement should be abolished from all "higher level" programming languages (i.e. everything except, perhaps, plain machine code). At that time I did not attach too much importance to this discovery; I now submit my considerations for publication because in very recent discussions in which the subject turned up, I have been urged to do so.

My first remark is that, although the programmer's activity ends when he has constructed a correct program, the process taking place under control of his program is the true subject matter of his activity, for it is this process that has to accomplish the desired effect; it is this process that in its dynamic behavior has to satisfy the desired specifications. Yet, once the program has been made, the "making' of the corresponding process is delegated to the machine.

My second remark is that our intellectual powers are rather geared to master static relations and that our powers to visualize processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible.

Let us now consider how we can characterize the progress of a process. (You may think about this question in a very concrete manner: suppose that a process, considered as a time succession of actions, is stopped after an arbitrary action, what data do we have to fix in order that we can redo the process until the very same point?) If the program text is a pure concatenation of, say, assignment statements (for the purpose of this discussion regarded as the descriptions of single actions) it is sufficient to point in the program text to a point between two successive action descriptions. (In the absence of go to statements I can permit myself the syntactic ambiguity in the last three words of the previous sentence: if we parse them as "successive (action descriptions)" we mean successive in text space; if we parse as "(successive action) descriptions" we mean successive in time.) Let us call such a pointer to a suitable place in the text a "textual index."

When we include conditional clauses (if B then A), alternative clauses (if B then A1 else A2), choice clauses as introduced by C. A. R. Hoare (case[i] of (A1, A2,···, An)),or conditional expressions as introduced by J. McCarthy (B1 -> E1, B2 -> E2, ···, Bn -> En), the fact remains that the progress of the process remains characterized by a single textual index.

As soon as we include in our language procedures we must admit that a single textual index is no longer sufficient. In the case that a textual index points to the interior of a procedure body the dynamic progress is only characterized when we also give to which call of the procedure we refer. With the inclusion of procedures we can characterize the progress of the process via a sequence of textual indices, the length of this sequence being equal to the dynamic depth of procedure calling.

Let us now consider repetition clauses (like, while B repeat A or repeat A until B). Logically speaking, such clauses are now superfluous, because we can express repetition with the aid of recursive procedures. For reasons of realism I don't wish to exclude them: on the one hand, repetition clauses can be implemented quite comfortably with present day finite equipment; on the other hand, the reasoning pattern known as "induction" makes us well equipped to retain our intellectual grasp on the processes generated by repetition clauses. With the inclusion of the repetition clauses textual indices are no longer sufficient to describe the dynamic progress of the process. With each entry into a repetition clause, however, we can associate a so-called "dynamic index," inexorably counting the ordinal number of the corresponding current repetition. As repetition clauses (just as procedure calls) may be applied nestedly, we find that now the progress of the process can always be uniquely characterized by a (mixed) sequence of textual and/or dynamic indices.

The main point is that the values of these indices are outside programmer's control; they are generated (either by the write-up of his program or by the dynamic evolution of the process) whether he wishes or not. They provide independent coordinates in which to describe the progress of the process.

Why do we need such independent coordinates? The reason is - and this seems to be inherent to sequential processes - that we can interpret the value of a variable only with respect to the progress of the process. If we wish to count the number, n say, of people in an initially empty room, we can achieve this by increasing n by one whenever we see someone entering the room. In the in-between moment that we have observed someone entering the room but have not yet performed the subsequent increase of n, its value equals the number of people in the room minus one!

The unbridled use of the go to statement has an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress. Usually, people take into account as well the values of some well chosen variables, but this is out of the question because it is relative to the progress that the meaning of these values is to be understood! With the go to statement one can, of course, still describe the progress uniquely by a counter counting the number of actions performed since program start (viz. a kind of normalized clock). The difficulty is that such a coordinate, although unique, is utterly unhelpful. In such a coordinate system it becomes an extremely complicated affair to define all those points of progress where, say, n equals the number of persons in the room minus one!

The go to statement as it stands is just too primitive; it is too much an invitation to make a mess of one's program. One can regard and appreciate the clauses considered as bridling its use. I do not claim that the clauses mentioned are exhaustive in the sense that they will satisfy all needs, but whatever clauses are suggested (e.g. abortion clauses) they should satisfy the requirement that a programmer independent coordinate system can be maintained to describe the process in a helpful and manageable way.

It is hard to end this with a fair acknowledgment. Am I to judge by whom my thinking has been influenced? It is fairly obvious that I am not uninfluenced by Peter Landin and Christopher Strachey. Finally I should like to record (as I remember it quite distinctly) how Heinz Zemanek at the pre-ALGOL meeting in early 1959 in Copenhagen quite explicitly expressed his doubts whether the go to statement should be treated on equal syntactic footing with the assignment statement. To a modest extent I blame myself for not having then drawn the consequences of his remark

The remark about the undesirability of the go to statement is far from new. I remember having read the explicit recommendation to restrict the use of the go to statement to alarm exits, but I have not been able to trace it; presumably, it has been made by C. A. R. Hoare. In [1, Sec. 3.2.1.] Wirth and Hoare together make a remark in the same direction in motivating the case construction: "Like the conditional, it mirrors the dynamic structure of a program more clearly than go to statements and switches, and it eliminates the need for introducing a large number of labels in the program."

In [2] Guiseppe Jacopini seems to have proved the (logical) superfluousness of the go to statement. The exercise to translate an arbitrary flow diagram more or less mechanically into a jump-less one, however, is not to be recommended. Then the resulting flow diagram cannot be expected to be more transparent than the original one.




耐心的看完
就知道他在计算机上的造诣有多牛比了


BASIC语言容易使人养成不好的编程习惯
看看自己写的代码 注意缩进了么 层次分明么
还是乱七八糟只管实现功能呢

现在BASIC早就退出舞台了 招聘的时候要的都是 .net 的 或者 C++ Java的程序员
你见过招 BASIC程序员的么?

微软是BASIC的开拓者,但是下一代系统是基于 .net的,而.net下最合适的语言就是
C#了 VB.net是没有地位的。

其他平台下 BASIC 也没有什么好的表现
Free Pascal则为广大pascal用户提供了各种平台下的编译器,这点上说,BASIC还不如
pascal。


到底该学什么语言
心里要有个底

回复列表 (共14个回复)

沙发

這么講,BASIC是只適合非專業人員!程序員就不用學啦!

其实BASIC作為業余愛好是非常好玩的!

板凳

一.qbasic不提畅使用goto.你举的那段话我不懂啥意思.   二.生活中许多有用的程序都是普通程序员做的不是靠牛人做的.   三.牛人不是谁都能当的.所以就算你学了c.你未必有学basic的猛.    四.微软的那些例子是微软战略问题.   五.学编程又不都是为了找工作.我就是个业余的.我的专业是媒介经营管理.跟编程不搭界.所以学什么语言不影响我的工作

3 楼

呵呵,说得很有道理.
媒介经营管理,
是白领阶层哎,
难怪那么多时间上网了.

4 楼

goto 有害,这点我也承认 所以都在写结构化的编程。
goto 有害,并不等于goto毫无用处,事实上在某些地方没有比goto更合适的语句了。只是多数情况下对那些想用goto的程序,完全可以用结构化的语句实现。

看看流行的语言中谁没提供goto的
basic 提供了goto
C     提供了goto
C++ 提供了goto
java  提供了goto
pascal提供了goto
...

至于汇编下的 jmp 一族,那不都可以看作goto嘛

5 楼

说的好,想以编程为职业的人建议别学qbasic
而象我们这样的业余编程爱好者学学是非常好的,起码自己能做做想做的东西,然后学了编程也会对计算机也有很深刻的理解!对于处理一些计算机的故障就比没有学的人多一点点了。
由于自己也是一个电子爱好者,也自己动手制作过电路板,在计算机的故障处理比别人又多一点点,
很多东西一综合,别人就认为偶很强了!
所以建议大家的兴趣要广泛!

6 楼

兴趣广泛 对你的社会生活经济活动很有好处,
无论事与情,我从小就控制自己专一,
所以到了今天,我已经找不到多少自己感兴趣的事情了。
因此一事无成,已经对社会失去了适应能力了。

7 楼

其实 goto 有害论已经是几十年前的理论了,
Basic, 或是 Quick Basic 过时也是很明显的事情,
微软只是Basic的忠实拥护者,但不也出 VB .net 吗?
要跟随时代,当然要往高级的产品语言看齐。
但不可否认的是(这也是很多人为老语言辩护的理由)
再低级的语言,更能体现你对算法的理解和灵活运用。

但有一件事说得没错,如果你想投身新一代的编程潮流,
的确不应该从Basic学起,太接近地基了,
应该踩着前人的基础,从楼顶开始往上建筑。

8 楼

其实我们高级语言的IF...THEN语句转化为汇编也是JMP类的代码来的。只不过是编译程序自动转换,而不是人为的使用Goto 。

9 楼

“basic”有什么不好,我是纯自学,学会了basic,独立写出一个福彩双色球分析程序,并用这个程序中奖“7000元”。
任何一种语言的算法都是相通的,只是看你如何理解basic

10 楼

学了总比不学得好!!!
先了解一下啊,又不是让你学甲骨文。

我来回复

您尚未登录,请登录后再回复。点此登录或注册