大家编程,是自上而下还是自下而上?

2020-01-30 14:01发布

整了2年嵌入式了,在初学的时候都是先编函数,然后搭主程序(自下而上)

最近才体会到,自上而下的编程方式可以清晰不少!~先写结构框架、想好需要哪些函数和参数、最后只是实现的过程了~

这样不容易犯错

呵呵 ,坛子里大家都是怎么处理这个问题的呢?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
25条回答
snoopyzz
1楼-- · 2020-02-01 08:21
一会自上而下....一会自下而上....
上下上下...上上下下...
NJ8888
2楼-- · 2020-02-01 10:37
骨架在心中
Sendzimir
3楼-- · 2020-02-01 15:05
It's worth emphasizing that bottom-up design doesn't mean just writing the same program in a different order. When you work bottom-up, you usually end up with a different program. Instead of a single, monolithic program, you will get a larger language with more abstract operators, and a smaller program written in it. Instead of a lintel, you'll get an arch.

需要强调的是自下而上的设计并不仅仅只是调个方向来写出同样的代码。当你自下而上的工作时,往往最后写出来的代码也是不一样的。程序不再是很大一坨,而语言会变得更强大,拥有更多的抽象操作符,这样程序本身将会变得更小。换斗移星,去直梁,得弧拱。

In typical code, once you abstract out the parts which are merely bookkeeping, what's left is much shorter; the higher you build up the language, the less distance you will have to travel from the top down to it. This brings several advantages:

通常写代码时,当我们从一些流水帐般的逻辑(如增删改查)中抽象时,其实其它逻辑所剩无几。对于语言层面的构建层次越多,每次所需其它表达越少。这带来诸多好处:

1. By making the language do more of the work, bottom-up design yields programs which are smaller and more agile. A shorter program doesn't have to be divided into so many components, and fewer components means programs which are easier to read or modify. Fewer components also means fewer connections between components, and thus less chance for errors there. As industrial designers strive to reduce the number of moving parts in a machine, experienced Lisp programmers use bottom-up design to reduce the size and complexity of their programs.

1. 让语言来承担更多的工作,自下而上的设计逼着程序更简洁与灵活。一段本来就简短的代码不需要再被切分成更小的模块了。更少的模块数量也意味着程序更易读和修改。更少的模块也意味着更少的模块间的依赖和耦合,也减少了错误发生的可能性。就像工业设计者努力的减少机器中运动部件的数量一样,资深的Lisp程序员用自下而上的设计来减少代码的大小与复杂度。

2. Bottom-up design promotes code re-use. When you write two or more programs, many of the utilities you wrote for the first program will also be useful in the succeeding ones. Once you've acquired a large substrate of utilities, writing a new program can take only a fraction of the effort it would require if you had to start with raw Lisp.

2. 自下而上的设计能促进代码重用。当你写很很多的程序时,往往为第一个程序写的Utility类也可以应用到其它后来的程序上。当你积累了很多底层Utility类之后,比起用最原始的Lisp,写新的程序往往只需很少的工作了。

3. Bottom-up design makes programs easier to read. An instance of this type of abstraction asks the reader to understand a general-purpose operator; an instance of functional abstraction asks the reader to understand a special-purpose subroutine. [1]

3. 自下而上的设计能让程序更易读。读程序的人只需理解抽象出的通用操作符,与抽象出的底层逻辑即可。[1]

4. Because it causes you always to be on the lookout for patterns in your code, working bottom-up helps to clarify your ideas about the design of your program. If two distant components of a program are similar in form, you'll be led to notice the similarity and perhaps to redesign the program in a simpler way.

4. 自下而上的工作可以帮助你更专注于代码的设计模式,从而理清程序设计思路。比如你很容易就能注意到,同一个程序中的两段八杆子打不着的代码居然长得很像,并且能用简单的方式重新设计。

Bottom-up design is possible to a certain degree in languages other than Lisp. Whenever you see library functions, bottom-up design is happening. However, Lisp gives you much broader powers in this department, and augmenting the language plays a proportionately larger role in Lisp style-- so much so that Lisp is not just a different language, but a whole different way of programming.

自下而上的设计不仅仅只能在Lisp中才能达到。任何当你看到库函数的时候,自下而上的设计就自然出现了。但是Lisp能给你更大的力量,在Lisp编程风格中,代码量的增加能带来对应功能的增加。因此Lisp不仅仅是种语言,也是一种全新的编程方式。

——自下而上的编程 | Programming Bottom-Up      Paul Graham
Sendzimir
4楼-- · 2020-02-01 20:14
yixin1851
5楼-- · 2020-02-01 20:25
 精彩回答 2  元偷偷看……
wuguoyan
6楼-- · 2020-02-02 02:10
自顶向上和自底向上同时使用,一般是先搭好框架,然后底层每部分功能实现好了,验证过了,在放到框架里面去调试。

一周热门 更多>