在main()函数之前调用Bootstrap函数

在所有可执行程序中,调用的第一个函数通常都是其入口main(),但可以使用一些技巧来修改这种行为。全局对象(即具有文件作用域的对象)能满足这种要求,因为全局对象将在程序的main()函数被调用之前创建。程序员可以创建一个类,其默认构造函数将调用所有的bootstrap函数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//bootstrap
#include <iostream>
using namespace std;
class Bootstrap{
public:
    Bootstrap(){
        cout<<"Bootstrap.\n";
    }
    ~Bootstrap(){
        cout<<"~destory.\n";
    }
};
Bootstrap req;
int main(){
    cout<<"hello world!\n";
    return 0;
}

Python 风格指南

一个典型模块的内部结构:

  1. 起始行
  2. 模块文档(文档字符串)
  3. 模块导入
  4. (全局)变量定义
  5. 类定义(若有)
  6. 函数定义(若有)
  7. 主程序

样例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
#coding:utf-8
 
"this is a test module"
 
import sys
import os
 
debug = True
 
class FooClass(object):
    "Foo class"
    pass
 
def test():
    "test function"
    foo = FooClass()
    if debug:
        print 'ram test()'
 
if __name__ == '__main__':
    test()

关闭了Dreamhost帐户

dreamhost-frontpage-20091201
Dreamhost是一家优惠的虚拟主机提供上,但是由于之前已经将博客迁移到了MT上面,这次DH空间到期我就关闭了DH的帐户,从2006年至今我使用了3年DH的空间,一直都很愉快,DH的响应速度已经后台功能都很强大,对于需要廉价空间的用户来说DH是个不错的选择。离开DH也是迫不得已,现在的经济状况不是很好,为了节省开支而关闭,等到未来经济条件好转,需要空间的时候,DH仍会是我主要的选择。
-EOF-

Hello world!

#!/usr/bin/env python
#coding:utf-8
 
def helloworld():
    "Hello World! \
    \nWelcome to my blog."
    print 'Nice to meet you!'
if __name__ == '__main__':
    helloworld()