[閒聊] 00
To understand what object-oriented programming entails, we need to place it
in the context of other styles.
Historically, the first computer programs were written in an *imperative
programming* style. A program was construed as a series of instructions,
where each instruction performs some action: changing the value of a
memory location, printing a result, and so forth. Assembly language is an
example of an imperative language.
As experience (and ambition) grew, programmers looked for ways of controlling
the complexity of programs. The invention of subroutines marked the *algo-
rithmic* or *procedural programming* style, a subclass of the imperative
style. Subroutines are helpful for two reasons: breaking up the problem into
small pieces makes each piece easier to understand, and it also makes it
possible to reuse pieces. Examples of procedural languages are FORTRAN, C,
Pascal, and Lisp with setf.
Subroutines are still dependent on gloabal state, so they are not completely
separate pieces. The use of a large number of global variables has been
criticized as a factor that makes it difficult to develop and maintain large
programs. To eliminate this problem, the *functional programming* style
insists that functions access only the parameters that are passed on them,
and always return the same result for the same imputs. Functional programs
have the advantage of being mathematically clean -- it is easy to prove
properties about them. However, some applications are more naturally seen
as taking action rather than calculating functional values, and are therefore
unnatural to program in a functional style. Examples of funtional languages
are FP and Lisp without setf.
In contrast to imperative languages are *declarative* languages, which
attempt to express "what to do" rather than "how to do it". One type of
declarative programming is *rule-based* programming, where a set of rules
states how to transform a problem into a solution. Examples of rule-based
systems are ELIZA and STUDENT.
An important kind of declarative programming is *logic programming*, where
axioms are used to describe constraints, and computation is done by a
constructive proof of a goal. An example of logic language is Prolog.
*Object-oriented programming* is another way to tame the problem of global
state. Instead of prohibiting global states (as functional programming does)
, object-oriented programming breaks up the unruly mass of global state and
encapsulates it into samll, manageable pieces, or objects.
Chapter 13, PAIP
Peter Norvig
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.150.216.198
※ 編輯: caml 來自: 211.150.216.198 (03/27 10:07)
※ 編輯: caml 來自: 211.150.216.198 (03/27 10:11)
→
03/27 10:12, , 1F
03/27 10:12, 1F
PLT 近期熱門文章
PTT數位生活區 即時熱門文章