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的过程是消耗时间的。

Wednesday, September 15, 2010

程序员具有的能力

一个程序员要具有哪些能力呢?
抽象问题的能力,把实际问题,抽象为计算机语言;
编写程序的能力,Java和C#确实很好用,却也阻碍了许多程序员;
设计能力,你写的接口应当用得很舒服,架构便于维护和重用;
想象能力,面对一个问题,你想到了哪些解?
学习能力,学习是一个程序员增长价值的核心能力;
数学运用能力,不得不说,计算机和数学真的很近;
不能怕麻烦,大师曾说,如果理解不了指针,那就更理解不了不动点理论。

不怕学了没用,就怕用了没学

请问,什么是技术能力?
技术不是数学,知道了结果的存在性之后就可以呼呼大睡了。
技术不是民工,干一天,领一天的工资回家。
技术是形神一致,知行合一。
不仅仅知其然,还要知其所以然;不仅仅会重复,还要会创新;不仅仅要学在脑子里,还要学到手上。
认为熟练度不重要,注定只是学校里的学生。

踏实地学些东西,不浮躁。

Saturday, September 4, 2010

A solution to problem 13.2-5 of 'introduction to algorithms' (clrs)

If a binary tree T1 can be right-rotated to another binary tree T2, then the count of rotations needed is O(n^2) where n is the count of nodes of the tree T1.
Solution:
It is obvious that if a node is in the right subtree, then it can never be in the left subtree by right-rotations.
There's a corresponding right-rotation for each left-edge. It can not be right-rotated if the left-edge is right-rotated once.
Therefore, if we fix the root of the tree, then there's O(n) left-edges, so there's O(n) possible right-rotations.
There're n possible roots. If the root is fixed, then the elements in the left and right subtrees are fixed.
Thus the total right-rotations between two possible trees T1 and T2 is n times O(n), which is O(n^2).