Thursday, December 01, 2011

Excerpt from “Computers,People and Programming”,chapter 1 of 《Programming--principles and practice using C++》

General characteristics of software:
correctness,reliability,relevant,good designed,affordable and maintainability

Keep in mind features which can be appreciated from outside by non-programmers;

The structures of program must be such that other programmers who didn't write it can understand it and make changes to it.To be maintainable,a program must be simple relative to its requirements and code must directly represent the idears expressed.Complexity can be intrinsic to a problem, but can also arise from  poor expressions of idear in code.

Programming is understanding. If we can program a task,we fully understand it.Conversely,we can see programming as part of the effort to thoroughly understand a problem.A program is a precise representation of our understanding of a topic.

4 stages of programming
  • analyze:what's the problem? what does the user want? what does the user need? what can the user afford? what reliability do they need?
  • design: how to solve the problem? what's the overall structure of the problem? which parts dose it consist of? How do they communicate with each other? How dose the system communicate with its user?
  • programming: express the solution of the problem in code. Write the code in a way that meet all the constraints(time,space,money,reliability and etc).The code must be correct and maintainable.
  • testing:make sure the system work correctly under all circumstances required by systematically trying it out.
We learn from experiences and modify our behaviour based on what we learn. So the crucial concept here is feedback.
Try to explain the design ideas to others  before coding, no matter weather they know software and business or not.
And while coding, from time to time, to think about the problem, articulate the idears or problems to others.



Much of problem solving is recognizing a known problem and apply a known solution technique.

This book focuse on expressing idears clearly in code.

Tuesday, November 15, 2011

Structure and Interpretation of Computer Program初探

本书是麻省理工计算机科学的入门级教材
昨天花了点时间读了序言和作者的两版前言,感觉只能看懂初版的前言,篇幅不长,几乎字字珠玑,摘录如下:
  • a computer language is not just a way of getting a computer to perform operations but rather that it is a novel formal medium for expressing ideas about methodology. Thus, programs must be written for people to read, and only incidentally for machines to execute. 
  • the essential material to be addressed by a subject at this level is not the syntax of particular programming-language constructs, nor clever algorithms for computing particular functions efficiently, nor even the mathematical analysis of algorithms and the foundations of computing, but rather the techniques used to control the intellectual complexity of large software systems.
  • students should have command of the major techniques for controlling complexity in a large system.
  • ``computer science'' is not a science and that its significance has little to do with computers. The computer revolution is a revolution in the way we think and in the way we express what we think. The essence of this change is the emergence of what might best be called procedural epistemology -- the study of the structure of knowledge from an imperative point of view, as opposed to the more declarative point of view taken by classical mathematical subjects. Mathematics provides a framework for dealing precisely with notions of ``what is.'' Computation provides a framework for dealing precisely with notions of ``how to.''

所谓控制复杂度的主要技术包括:
  • We control complexity by building abstractions that hide details when appropriate.
  • We control complexity by establishing conventional interfaces that enable us to construct systems by combining standard, well-understood pieces in a ``mix and match'' way.
  • We control complexity by establishing new languages for describing a design, each of which emphasizes particular aspects of the design and deemphasizes others.

几乎与目录中各章对应起来:
  1. 过程抽象
  2. 数据抽象、
  3. 模块、对象及状态
  4. 元语言(metalinguistic ?)抽象
  5. 用寄存器机器计算
从前言的字里行间,可以看出作者对LISP/Scheme的激赏;只是时至今日,该门课程所使用的语言已经换成了Python,由此可见,理论与现实间的差距还是巨大的。

该门课程的视频在这里

Friday, November 11, 2011

C++之父的妙论

因为喜欢pongba博客的缘故,去他csdn上的老巢拜访了一下;看了其中关于c++语言的几篇博文,颇有些旧情复炽。顺手捎带,拜读了Bill Venners对Bjarne Stroustroup的访谈(一共4部分),一读之下,惊为天人。
Bjarne的语言朴实无华,但是味道极深,有时需要慢慢品味,趁自己还记得住,赶紧贴几句:
  • Just because you don’t need OOP or GP for a project doesn’t imply that C is better for that.
  • "I wouldn't like to build a tool that could only do what I had been able to imagine for it."
  • Design tools don't give you much feedback, so therefore I tend towards the view that you should build a smaller system and grow it into a bigger one. There is a rule of thumb that says that every successful large system is a development of a slightly smaller working system. You apply that rule recursively. 
  • "I wouldn't like to build a tool that could only do what I had been able to imagine for it." 
  • To quote Kristen Nygaard, programming is understanding. The meaning is: if you don't understand something, you can't code it, and you gain understading trying to code it.  
从访谈内容来看,在兼顾开发效率和运行效率上,c++似乎做得不错。

Wednesday, November 09, 2011

TAOCP Vol1 3rd Edtion 之蜻蜓点水

阅读Knuth的书有一种愉悦感,即使是前言,即便仅限于前言;
老先生的技术水准当如泰山北斗,非我辈可以置喙,可贵的是:文笔清晰流畅,态度诚恳,间或还小幽默一句,读之不禁让人莞尔;
本书内容囊括非数值类算法分析中最为经典的部分,计划出7卷,目前出到第四卷(以分册形式);
老先生写作本书的目的有二:
  • 是对算法各领域的知识进行总结,属参考手册类(reference)
  • 作为教材使用,配备了大量习题和答案(出乎我的意料)
全书总体结构如下

  • 基本算法
  • 半数值算法
  • 排序和搜索
  • 组合算法
  • 句法算法
  • 语言理论
  • 编译器

 前言特别指出:本书对读者的数学水平要求不高,掌握初等代数即可应付本书的大部分内容;此外,只对编程感兴趣的读者可将数学推导及证明略去不看,但要记住结论;pongba似乎不赞同这一说法;
可将本书第一卷视为3类教材的合集:数据结构、离散数学以及机器语言编程(是描述计算机体系结构、还是介绍MIX编程,还是兼而有之?存疑

由前言后的流程图可知:本卷为必读卷,是后续各卷的基石,后续各卷则可独立阅读。

此外,本书的独特之处在于:算法描述采用的计算机语言为MIX(后续有MMIX,见第一卷第1分册),以一种虚拟计算机为模型构建,可谓胆大包天、匠心独具;回顾起来,这一抽象还真摆脱了对历史的依附。在其所罗列的6点理由中,我尤其对a与f印象深刻,a充分点出计算机语言在人与机器间所处的两难境地(虽然此处是站在机器和算法的角度来表述的,换言之,在语言的设计中,不是简单的选队、站队问题,而是复杂的折中、权衡问题);f则是历史更迭的必然产物;

本书习题含有各种标记:0~50的分数、M/HM标记以及箭头

Wednesday, November 02, 2011

《Introduction to Algorithms 3rd Edition》结构初探

从前言来看,作者的雄心很大:
  1. 自诩为“自助餐”和“大杂烩”,可成为大学任意学习阶段的教材(从本科的算法入门到研究生的算法设计)
  2. 算法手册
对读者的要求:
  • 初具编程经验
  • 具备一定数学知识(本书第1和第8部分的数学知识+初等代数知识)
特点:
  • 内容丰富
  • 注重数学证明和算法分析
  • 采用伪代码,但强调:易于以其他计算机语言实现
  • 内容的编排上,将问题域和算法设计技术混排
  • 有专门的网站,同时公布了部分习题的答案
  • 网上还有教学录像(2nd ed)和高手的学习笔记网站  

Tuesday, November 01, 2011

《Algorithms 4th Edition》 和《Algorithms in C++ 3rd Edition》结构初探

以下内容根据两书的前言和目录进行总结
首先谈谈二者的共同点:
1、都声称罗列了计算机科学中最为重要的算法
2、数学内容有限(自含推导或标记为不在本书范围之内进行论述)
3、使用实际代码,而非伪代码
4、均有相关网站
再说说二者间的差异
1、按作者自己的表述,《algorithms》更适合作为入门教程;而《algorithms in C++》则更高级一些,可以适应多种教学(数据结构和算法导论、算法设计、甚至编程)和学习要求(作为参考大全);
2、从目录上看,前者更聚焦,后者内容更多,范围更广
3、前者以java实现,后者以C++实现

后者前言中过于完美的自诩让我有点怀疑,还是深入以后再说吧。

结论:前者为阅读主线之一,后者作为参考;

《The Algorithm Design Manual》结构初探

本书是“算法设计”方面的手册,分为两部分:
1、如何分析算法,如何设计算法
2、参考大全:针对现有算法问题按类别给出具体解法,附带的网址链接指向以各种计算机语言对算法的具体实现
作者强调:设计算法最为关键的环节在于建模
描述算法时采用:贴近解题者的思维方式,试错、调整,验证。。。,比之一般教材似乎更易于理解
对数学证明和推导只是非正式的讨论,尽可能多的采用真实代码(这两点似乎与Nutshell相似),另外强化了作业和练习
总结:似乎需要对算法和数学知识有一点了解,并非算法的入门书籍,可作为参考书籍,但不能作为阅读主线。

《algorithms in a nutshell》结构初探

缘起:为了一偿学习算法的夙愿,把手头以算法为主题的书籍搜罗了一下,准备逐一研读一下各书的序言和目录,再着手制订具体的学习计划——初步的想法还是以各书为主线、相互穿插着进行主题阅读,同时结合读书笔记、习题和实际代码,以期达到好的效果;
具体书单如下:
Introduction to Algorithms 3rd Edition (CLRS)
Algorithms In A Nutshell
Algorithms in C++
Algorithms
The Art of Computer Programming
The Algorithm Design Manual
正文:
昨天阅读了Algorithms in A Nutshell的前言,浏览了其目录,试总结如下:
读者对象应为有经验的程序员,阅读目的有二:
1、发现解决问题的算法,或
2、改善现有算法性能
本书遵循原则有四:
1、本书试图针对程序员每天所面临的实际问题而提供以真实代码实现的真实算法
2、将算法与实际问题分离
3、对数学点到为止,不做深究
4、提供性能测试方法,为算法性能的数学分析提供感性支持
本书分为4部分:
1、了解算法所需的数学知识导论
2、算法介绍(即本书主体部分)
3、进阶阅读:其它方法失效时的应对策略、方法论
4、性能测试方法

Wednesday, November 07, 2007

i386体系下Linux系统C语言与汇编的对应关系

1、intel的i386堆栈在入栈时的栈顶寄存器sp是由高地址向低地址增长
2、c语言函数的局部变量,经过查阅汇编代码,实际是通过sp-x来分配,由基指针寄存器bp-n(n为偏移量)来定位存取的
3、main入口的堆栈排列(从高地址到低地址直至SP分别为:char **env, char **argv和int argc以及main的offset)
4、在c语言调用函数时,参数按从右至左的顺序入栈,即最左边的参数在栈顶(SP)

另外,这里是一篇好文章,gazette了不起!对c语言的main函数怎么在linux下面跑起来说得很透彻。