{Elements of Programming}

原创 2015年11月24日 00:39:34

Chap 1 Foundations

Introduce notions of value, object, type, procedure and concept that represent different categories of ideas in the computer. A central notion, Regularity enables us to apply equational reasoning (substituting equals for equals) to transform and optimize programs.


1.1 Categories of Ideas: Entity, Species, Genus

Abstract Entity: eternal and unchangeable. 

E.g Blue and 12.


Concrete Entity: comes into and out of existence in space and time. 

E.g  China and Amy.


Attribute: a correspondence between a concrete entity and an abstract entity --- describes some property, measurement or quality of the concrete entity. 

E.g the number of China


Identity: a primitive notion of our perception of reality, determines the sameness of a thing changing over time.


Abstract Species: common propertites of equivalent abstract entities. 

E.g natural number and color.


Concrete Species: the set of attributes of essentially equivalent concrete entities. 

E.g  man and Hubei province.


Function: a rule that associates one or more abstract entities, called arguments from corresponding species with an abstract entity, called the result from another species.


Abstract Genus: different abstract species that are similar in some respect. 

E.g  number.


Concrete Genus: different concrete species that are similar. 

E.g  mammal


An entity belongs to a single species, and several genera.



1.2 Values

A datum is a finite sequence of 0s and 1s.


A value type: a correspondence between a species and a set of datums. 


A datum correponding to a particular entity is called a representation of the entity, and the entity is called the interpretation of the datum.

Value: a datum together with its interpretation. 

E.g integers are represented in a 32-bit format, and interpreted as integer numerator.


A datum is well formed if and only if that datum represents an abstract entity.

E.g integer is well formed, but float is not.


A value type is properly partial if its values represent a proper subset of the abstract entities in the corresponding species and uniquely represented. otherwise it is total

E.g integer is properly partial, and boolean is total.


A value type is uniquely represented if and only if at most one value corresponds to each abstract entity. 

E.g an integer in 2's complement is uniquely represented, but boolean is not.


A value type is ambiguous if and only if a value of the type has more than one interpretation. 

E.g true values.


Two values of a value type are equal if and only if they represent the same abstract entity. 

They are representational equal if and only if their datums are identical sequences of 0s and 1s.


Lemma 1.1 

If a value type is uniquely represented, equality implies representational equality.


Lemma 1.2 

If a value type is not ambiguous, representational equality implies equality.


A function defined on a value is regular if and only if it represents equality: substituting an equal value for an argument gives an equal result.

Regular functions allow equational reasoning: substituting equals for equals.

When designing the representation of a value type, 2 tasks: implementing equality and deciding which functions will be regular.


1.3 Objects

Memory: a set of words each with an address and a content. The content is obtained by a load operation and changed by a store operation.


An object: a representation of a concrete entity as a value in memory. 

It has a state that is a value of some value type and is changeable.It owns a set of resources such as memory words and records in a file to hold its state.


An object type is a pattern for storing and modifying values in memory.


A value type describes states of objects of that type.


Values are unchanging and are independent of any particular implementation in the computer.

Objects are changeable and have computer-specific implementations.


Describing the states of objects in terms of values allows us to abstract from the particular implementations of the objects when discussing equality.

Functional programming deals with values, imperative programming deals with objects.


We use values to represent abstract entities, sequences of values can also represent snapshots of concrete entities.

We use objects to represent concrete entities, and abstract entities: staying constant or taking on different approximations to the abstract.


We use objects because:

1. Objects model changeable concrete entities, such as employee records in a payroll application.

2. Objects provide a powerful way to implement functions on values, such as procedure to calculate square.

3. Computers with memory constitute the only available realization of a universal computational device.


1.4 Procedures

A sequence of instructions that modifies the state of some objects, it may also construct or destroy objects.


1. Input/Output consists of objects passed to/from a procedure directly or indirectly through its arguments or returned result.

2. Local State: objects created, destroyed, and usually modified during a single invocation of the procedure.

3. Global State: accessible across many invocations.

4. Own State: accessible only to this procedure but shared across multiple invocations.


A computational basis for a type is a finite set of procedures that enable the construction of any other procedure on the type.

A basis is efficient if and only if any procedure implemented using it is as efficient as an equivalent procedure written in terms of an alternative basis.

A basis is expressive if and only if it allows compact and convenient definitions of procedures on the type.


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

The Elements of Programming Style

《The Elements of Programming Style 》是一本很古老的书。30 年的岁月依旧无法掩盖其中的真知灼见。 把代码写清楚,别耍小聪明。想干什么,讲的简单点、直接点。只要...

Elements of Programming:追溯数学原理,探求编程的本质

《编程原本》预订网址【互动网】【当当网】【卓越网】【京东网】 《编程原本》(Elements of Programming)前言 《编程原本》将演绎方法应用于程序设计,讨论程序与保证它们能正确...
  • hzbooks
  • hzbooks
  • 2011年12月26日 14:47
  • 764

Excerpts from The Elements of Programming Style

SUMMARY OF RULES This summary is designed to give a quick review of the points we covered inthe boo...

The elements of programming style

Write clearly - don't be too clever  清晰是最重要的,不要耍聪明 Say waht you mean, simply and directly 词要达意 Use...

[SICP Notes] 1.1 The Elements of Programming

About the Book To know more about programming, I have decided to start reading the famous Structu...

The Elements of Programming Style 编程风格要素 中文英文中英对照

【转自:http://www.cnblogs.com/clive/archive/2010/01/03/The_Elements_of_Programming_Style.html#1739537】 ...

The Elements of Cache Programming Style

Chris B. Sears Google Inc. Those who cannot remember the past are condemned to repeat it -...

The Elements of Programming Style (编程风格的元素)读书总结

这是一本关于编程风格经典的老书了,一些经典的CS著作里面都提过此书,而且都是强烈推荐阅读,当初就是因为些书评价非常高,所以才想读的,不过很可惜,由于此书出版年月太早,而且书中使用的语言为fortran...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:{Elements of Programming}
举报原因:
原因补充:

(最多只允许输入30个字)