Wednesday, March 23, 2011

深入学习UNIX的原因

今天开始,又在学习UNIX操作系统设计。主要的目的是:

  1. 了解UNIX接口定义,帮助以后写出elegant的程序;
  2. 了解UNIX底层设计与实现,开拓视野;
  3. 自己的一个夙愿。
希望能完整的坚持下来。

Wednesday, January 19, 2011

The UNIX Philosophy

From Doug Macllroy,

  1. Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.
  2. Expect the output of every program to become the input to another, as yet unknow, program. Don't clutter output with extraneous information. Avoid stringently colummnar or binary input formats. Don't insist on interactive input.
  3. Design and build software, even operating systems, to be tried early, ideally with weeks. Don't hesitate to throw away the clumsy parts and rebuild them.
  4. Use tools in preference to unskilled help to lighten a programming task, even if you have to detour to build the tools and expect to throw some of them out after you've finished using them.
A summary:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

Wednesday, November 17, 2010

使用Python的一点感受

使用Python有半个月了,对这个语言有了一些切身的感受:
  1. 语言本身比较简单,python是一种脚本语言,不用像C++那样去记忆规则。
  2. 一切都是对象,包括函数,内建类型。
  3. 对象本身都是不可改写的,重新赋值时改变的是变量名拥有的实际对象。因此,变量名可以重新赋值为任何对象。
  4. 对象类型都是动态的。不需要在运行前决定对象的类型。完全动态绑定也带来了Python的低效率。
  5. Python可以很好的和C语言结合。如果程序中有消耗计算的部分,可以用C语言实现相应的功能,通过python来调用。
  6. 没有固定的this名称,self不是关键字,可以用任意非关键字term来代替self。
  7. 规范需要遵守PEP-8
  8. 封装C++对象可以用swig库及工具
  9. 可以用的第三方资源比较多

Sunday, November 7, 2010

Coordinatisation

伽利略(Galileo)说,'Measure everything that is measurable, and make measurable everything that is not yet so.'

Tuesday, October 5, 2010

C Programmer的巧计可能称为C++ Programmer的陷阱!

不少有经验的C程序员,当然是已经对C的编程模型了解很深刻的,使用C语言的巧计,在C++代码里却有可能称为陷阱,这样的例子不少:

  1. struct中的不定长数组。
  2. C style字符串。
  3. 函数指针。
  4. memset/memcpy/memmove
  5. void*
当你想用以上机制时,要好好想想是否在C++里有更好的办法?

Inside The C++ Object Model是本好书

深度探索C++对象模型,是Lippman十年前的巨作,深度介绍C++背后的事情。C++这门语言和其它语言不同的是,你要想用好它,就得充分的了解它,了解C++编译器在背后做了哪些事情。这本书会让有一些经验的C++ Programmer拍案叫绝!

Sunday, October 3, 2010

Python程序的运行

Python是一种脚本语言,但和普通的脚本语言,如Bash不同。Python在运行时解释器会将其编译成Bytecode,而Bytecode在运行时Python虚拟机会将其实时地转换为机器码运行,而这种机器码会被优化,只有被运行地那一部分机器码会被实际转换出来,其余地不受影响,而且这种机器码会一直被保留着。这种过程叫做JIT=Just In Time。
每一个import的Python模块会被保留一直到程序运行结束,后面即使模块改变也不会重新编译。而import的过程是消耗时间的。