Oct 30, 2008

10.30

开学一个半月,看着时间花花地流过,而且越流越快,可面前还有很多问题没有解决,也许到了重新评估一下的时候了。

主要的问题还是课业太重,自己的基础比较差,而且又花了很多时间在非课程的东西上,导致一时跟不上进度。想想课前预习课后复习才是效率最高的办法,以后多多注意。光统计就已经是科目繁杂,再加上对应的经济金融知识,以及数据管理、分析工具的掌握,这些对我这一年多学习时间来说,根本没有完成的希望。

还是思想和工具的问题,没有思想,再多的工具也没有用;可决定思想的往往就是工具。就像思想和语言的关系,思想往往被语言所限制,如果一个思想不能表达,它就不能称之为一个思想。现在我也是面临着这样的困境,金融经济分析是商务决策的工具;数据挖掘是经济分析的工具;而SAS等基础软件则是统计的工具。但现在,这些不同层面上的思想和工具在我面前都是脱节的,这是我现在面临的最大的困惑。记得在GSMC实习的时候,Lin曾经和我说,要做数据挖掘至少要5年的从业经验,现在看来,五年的学习曲线并不是很夸张,如果把业务方面的东西也加上去的话。

专注与学业及SAS和IBM的相应解决方案。如果可以的话,再加强些英语吧~~

Oct 23, 2008

Code Complete PART2

PART2: 创建高质量的代码
chapter 5: Design in Construction 软件构建中的设计
1. Design Challenges
Design --> wicked: 只有通过解决或部分解决才能明确的问题 现实<-->理论
Sloppy process --> tide result
方法论;优劣的差异;good enough?
Tradeoffs & priorities
Restrictions
Nondeterministic
Heuristic process
Emergent 自然而然
2. Key Design Concepts
Primary Technical Imperative: Managing Complexity
Accidental and Essential difficulties
失控的复杂度 --> 失败 --尽量减少在任一时间需要考虑的程序量
Desirable characteristics of a design
Minimal complexity --避免“聪明”
Ease of maintenance --self-explanatory
loose coupling
extensibility
reusablity
high fan-in --good use of utility classes
low fan-out --7
portability
leanness --完成->不能删除任何东西:伏尔泰
stratification
standard techniques
Level of design
System --> subsystem 子系统:业务规则、GUI、DB、对象依赖性
--> classed --> routines --> internal routine
3. Design Buildng Blocks: Heuristics
find real-world objects
辨识对象及属性 --> 确定自身操作 --> 对其他对象的操作 --> 可见性 --> 公开接口
Form consistent abstractions
抽象是一种让你关注某一概念的时候可以同时放心地忽视其中一些细节的能力--在不同的层次处理不同的细节。
Encapsulate Implementation details
房屋建造
Inherit -- when inheritance simplifies the design
Hide secrets (Information Hiding)
封装,模块化 冰山
隐藏复杂度、隐藏变化源
障碍:信息分散 循环依赖 类内数据->全局数据 性能损耗
价值:修改 设计
Identify areas likely to change
寻找 分离 预防
易变化的区域:业务规则 输入输出 非标准语言特性 困难的设计和构建 状态变量
anticipating different degrees of change
让变化的影响范围和发生变化的可能性成反比
有用的最小子集 --> 扩充
keep coupling loose
criteria: 规模(连接数) 可见性 灵活性
kinds of coupling:
simple data parameter coupling
simple object coupling
object-parameter coupling
syntictic coupling: 控制标志 假设。。。
Look for common design patterns
现成抽象 --> 减少复杂度
细节制度化 --> 减少出错
多种方案 --> 启发
高层次 --> 简化交流
4. Design Practices
Iterate Divide and conquer Top-down and botton-up design approaches
top-down: 易上手,但易受底层复杂度影响
botton-up: 复杂,但可早期鉴别出系统的复杂度,设计出更好的高层类
experimental prototyping collaborative design How much design is enough
最大的设计失误在于自我认为做的很充分,事后却发现做得不够。
最大的悲哀莫过于大厦快要完工时地基出了问题。 ——罗素
Capturing your work
doc in source, wiki, mail, DC, picture, CRC(类、职责、合作者), UML
5. Comments on popular methodologies
Big design up front --> little design up front or enough design up front
Design in General
Couceptul Blockbusting: A Guide to Better Ideas
How to Solve it: A New Aspect of Mathematical Method
How to Solve it: Modern Heuristics


chapter 6: Working Classes 可以工作的类
1. Class Foundations: Abstract Data Types(ADTs)
Benefits: 隐藏实现细节 支持改动 接口提供更多信息 易提高性能 正确性验证 自说明性 数据传递 实体操作
ADT + 继承、多态 --> 类
2. Good Class Interfaces
Good Abstraction
抽象是一种以简化的形式看待复杂操作的能力 混杂-->一致
类接口应展现一致的抽象层次
理解类所实现的抽象 精确!
提供成对的服务
转移不相关信息 --> 模块内聚
让接口可编程,而不是表达定义
谨防破坏接口的抽象
抽象性 and 内聚性
Good Encapsulation
限制类和成员的可访问性(accessibility)
不公开暴露成员数据
避免把私有的实现细节放入类的接口
不要对类的使用者做出任何假设
避免使用友元类(friend class)
让阅读代码比编写代码更方便
警惕在语义上破坏封装性:针对接口编程 --> 透过接口针对内部实现编程×
3. Design and Implementation Issues
Containment("has a" relationships)
使用包含 万不得已使用private继承 警惕超过七个数据成员的类
Inheritance("is a" relationships)
更精简的代码
成员函数:对派生类可见?有默认实现?能被覆盖?
数据成员:对派生类可见?
要么对继承做详细的说明,要么不使用继承
Liskov替换原则:派生类必须能通过基类的接口被使用,且使用者无需了解两者之间的差异
确保只继承需要继承的部分
注意:继承接口 --> 继承实现 继承实现 --> 继承接口
只想要实现 继承?包含!
不要“覆盖”(语法角度)一个不可覆盖(语义角度)的成员函数!
把共用的接口反正继承树尽可能高的地方
只有一个实例:新的对象?新的类?
只有一个派生类:提前设计?
覆盖但没做任何操作:怀疑!
类型检查?多态!
让所有数据都是private
对继承持有歧视的态度!
Member functions and data
子程序的数量 类调用子程序的数量 对其它类的子程序的间接调用: 尽可能少!
尽量减少类与类间相互合作的范围。
Constructors
尽可能在构造函数中初始化所以数据成员
private constructors --> singleton property
deep copies >> shallow copies
4. Reasons to Create a Class
建模 降低复杂度 隔离复杂度 隐藏实现细节 限制变动的影响范围 隐藏全局数据 让参数传递更通畅 建立中心控制点 易于重用 为程序族做计划 包装相关操作 实现特定重构
Classes to avoid
god class; 无关紧要的类; 用动词命名的类

chapter 7: High-quality Routines 高质量的子程序
small intimate viaible flexible
1. Valid reasons to create a routines
降低复杂度 引入中间、易懂的抽象 避免代码重复 支持子类化 隐藏顺序 隐藏指针操作 提高可移植性 简化逻辑判断 改善性能
创建类的理由也是创建子程序的理由。
2. Design at the Routine Level
functional cohesion: 只执行一项操作
sequential cohesion: 步骤 共享数据 完成完整功能
communicational cohesion: 同样的数据,无其它联系
temporal cohesion: 需要同时执行
procedural cohesion: 子程序的操作按特定顺序
logical cohesion: 控制或“逻辑”是子程序组织的原因
coincidental cohesion
3. Good Routine Names
描述子程序所做的所有事情
避免使用无意义、含糊、表意不明的动词
不使用数字形成不同的子程序名
函数命名时对返回值有所描述
过程命名时使用语气强烈的动宾形式
准确使用对账词
为常用操作确定命名规则
4. How long can a routine be
适中最好 一屏 打印1到2页
5. How to use routine parameters
按输入-修改-输出组织
一致的排列顺序
使用所有的参数
状态或出错变量放最后
不要把子程序的参数用于工作变量
在接口中对参数的假设做出说明:I or M or O? unit? scope?
个数限制在大约7个以内
IN Modify OUT的命名规则
子程序的接口要达到何种抽象?
6. Special considerations in the use of functions
函数 vs 过程
如果一个子程序的用途是返回由其名字所指明的返回值,那么就应该使用函数,否则使用过程
检查所有可能的返回路径
不要返回指向局部数据的指针
7. Macro routines and Inline routines
把宏表达式整个包含在括号内
把含有多条语句的宏用{}包围
节制使用inline: 暴露细节

chapter 8: Defensive Programming 防御式编程

1. Protecting your program from invalid inputs
garbage in, garbage out
in: 检查源于外部的数据 检查数据输入 决定如何处理错误的输入数据
2. Assertions
开发时使用的让程序在运行时进行自检的代码
assert a != 0 : "a is unexpectedly equal to 0"
IN and OUT, state, value of variable, pointer check, container
Guidelines for using assertions
错误处理代码:预期会发生 断言:绝对不应该发生
避免把需要执行的代码放在断言中
用断言来验证前条件(运行前确保为真)和后条件(运行后确保为真)
先使用断言后使用错误处理代码
3. Error-Handling Techniques
返回中立值 下一个正确的数据 与前次相同的数据 最接近的合法值 log error-code
Robustness vs. correctness
correctness: 永远不返回不准确的结果
robustness: 尝试采用。。继续运转
4. Exceptions
通知机制
只有在真正例外的情况下才抛出异常:由于调用子程序的代码需要了解被调用代码可能发生的异常,因而弱化的封装
不能用异常来推卸责任
避免在构造和析构函数中使用异常,除非在同一地方捕获
在恰当的层次抛出异常:抛出的异常也是程序接口的一部分
在异常消息中加入导致异常发生的全部信息
避免使用空的catch语句
集中的异常报告机制 异常使用标准化 考虑异常的替代方案
5. Barricade your program to cotain the damage coused by errors
让软件的一部分处理“不干净”的数据,另一部分处理“干净”的数据,大部分代码就无需承担错误检查的任务
outside error-handling | assertions inside
6. Debugging Aids
Use offensive programming
对待异常:开发时--显现,运行时--自我修复

chapter 9: the Pseudocode Programming Process (PPP) 伪代码编写过程
1. Summary of steps in building classes and routines
steps in creating a class
类的总体设计 类中的子程序 复审并测试整个类
steps in building a routine
设计 检查 编写 检查
2. Pseduocode for Pros
类似英语,精确描述
避免使用目标语言的语法元素
在意图的层次编写伪代码
在足够低的层次上写伪码
3. Constructing routines by Using the PPP
Design the Routine
检查先决条件
定义问题:要隐藏的信息,输入输出,前条件后条件
子程序命名
决定如何测试
在标准库中寻找可用的功能
考虑错误处理
考虑效率问题
研究算法和数据结构
编写伪代码:头部注释+目的
考虑数据
检查伪码
Code the routine
写出子程序的声明
将伪码转为高层次的注释
在注释下填充代码
检查代码:重构?递归应用routine编写方法
收尾
check the code
脑海中检查:
桌面检查(desk checking)
同行评审(peer review)
走查(walk-through)
详查(inspection)
编译子程序
hacking and compiling 拼凑加检查×
将编译器的警告级别调到最高
使用验证工具(validators),C: lint
消除错误消息和警告的所有根源
在调试器中逐行执行代码 测试代码: 测试用例 消除程序中的错误
clean up leftovers
检查接口 检查整体设计质量 检查变量 检查语句和逻辑 检查布局文档及注释
4. Alternatives to the PPP
Test-first development
refactoring
design by contract
hacking×

Oct 22, 2008

卑微地努力

人类的行为取决与自身的知识,因为你无法知道自己将来知道什么,所以无法知道自己将来会做什么。

人类所做的新的发现不过是自己刚刚塞进去的东西而已。

今天上金融博弈的时候老师又开始讲起了哲学,我蛮喜欢那个不修边幅的老头的,“老年版的哈利波特”,宁同学是这么称呼的。数学、哲学、宗教,其实都是人类思维构造的体系,本质上有着想通之处,其实软件有何尝不是如此,“纯脑力的构建活动”—— Code Complete中是这么说的。简洁和优美,可能是所有科学都追求的一样东西。不过在实践的角度看,quick & clear往往是要着很深功力的,刚开始的时候也许quick & dirty比clean & slow要更好些,在尝试的过程中再慢慢向着quick & clean进步。

下午上财务报表的时候上课的老师也给了我很多感触,他原来师范毕业后在大学教书,过了几年考了硕士,出来在银行做了几年,又去读了博,现在在上财教书。从他的经历看来并算不上一个牛人,但他走的路可以说是一个普通人的成功之路。比如天天记日记,年年做总结,整理简历……心怀希望,能够坚持的人相信都是能成功的。

上海博物院

第一次去上海博物院是初中,之后是高中毕业那会,接着就再没去过了。今天正好去火车站配眼镜,在等磨镜片的那会功夫就顺便去博物院转了圈。

据说全国能称上博物院的只有三家:故宫博物院,上海博物院和南京博物院。“馆”和“院”虽然只是一字之差,可也体现了些身价的不同吧。上博院的藏品还是蛮丰富的,只是展厅里展出的只是其中的一部分,而且有些展厅也是时开时关,所以要看一些一些精品还是要有一定缘分的。但据说现在书画馆的画都已不是真迹的了,而是现代科技的复制品。##ReadMore##



这次在书画馆多呆了一些时间,有好些书画是很有名的,以前只是在画册中见过,现在一睹真容还是很有些感动的。只是也有些遗憾,看到宋元明清画作之精美高雅逸趣。想到现在社会上所谓名家的一些画,一些字,真不知该说是创新还是倒退。在陶瓷馆也呆了很久,康乾盛世的一些作品做工之精美真可以说是绝伦,经历了数百年的岁月依然灿然如新。

本来还拍了一些照,只是发现J10不愧是很低端很傻瓜的相机,变形严重而且高ISO下噪点严重。不过用picasa调下暗部加简单的模糊后效果还可以接受。

Oct 16, 2008

武东校区

上财的所谓武东路校区原来是,现在还是同济的校园。住着不多的学生,有一些陈旧荒芜的气息。
##ReadMore##

Oct 15, 2008

敬畏耶和华是智慧的开端

一天无事。
上午看Code Complete,有感时间的匮乏,用Google Calender排了下这学期的日程。现在又是一个人了,该慢慢习惯泡图书馆的日子吧,可能这就是我的Style,刻意追求着简单,简单得什么都不要。
研究生就这两年,在明年找工那会仅仅一年时间,要是从明年五月报暑期实习的时间来算,时间更少。Less is more。尽量集中精力吧。
下午上财务报表分析,书上看到了财务预警分析的简介。多元逻辑分析、神经网络和概率预测在财务预警分析上都有可用的模型,但却都存在着这样那样的问题。我进一步坚信统计、计算机相结合在商务智能上必将有开阔的应用前景。
晚上上的是金融博弈,也是选修的第一节,老师一看就是理科出身。学工学理学文对一个人的气质真的影响很大,如果潜心学过的话。
课程的引言就是“敬畏耶和华是智慧的开端”。
我并不是宗教的信徒,但也不是无神论者。冥冥之中自有定数。我一直相信,如果有上帝的话,他创造的该不是物的世界,而是公理和规律;而且,他可能是程序员。
前几天在Code Complete上看到了下面的一些话,发觉虽在不同的领域,真正优秀的思想其实是相通的:
你思考的能力取决于你是否知道能够表达该思想的能力
《The Humble Programmer》:大部分编程工作都是在弥补我们有限的智力。承认自己智力有限并通过学习来弥补
谦卑的人那,努力吧。

Learning python 读书笔记 PART 6

PART 6: Classes and OOP
Chapter 19. OOP: The Big Picture
classes: instance factories, data + function
Instances: represent the concrete items in a program's domain
attributes searching at runtime, lower level to higher level
Coding Class Trees
Class C1(C2, C3): multiple inheritance
Attributes --> class  :  assignments made within class statements
Attributes --> instances  :  assignments to self inside class statements
>>> class C1:
    def setname(self, who):
        self.name = who       
>>> I1 = C1()
>>> I1.setname('xyz')
>>> print I1.name
xyz
initialization: def __init()

Chapter 20. Class Coding Basic
Class: namespace, generating multiple objects, namespace inheritance, operator overloading
Module: namespace
Classes VS. Instances
Class objects probide default behavior:
attributes functions --> class <-- a class name
Instance Objects are concrete items:
call a class object like a function makes a new instance object
each instance object inherits class attributes and gets its own namespace
a new attribute can be generated on the instance
Classes are customized by Inheritance
classes and modules:
from module1 import Class1
class Class2(Class1): ...
Classes can intercept Python Operators
def __init__(self, value): ...
def __add__(self, other):
    return ...
def __mul__(self. other):
    self.data = ...

Chapter 21. Class Coding Details
The Class Statement
class <name>(superclass,...):
    data = value
    def method(self, ...):
        ....
Methods
instance.method(args...) == class.method(instance, args ...)
Calling superclass constructors:
class Sub(Super):
    def __init__(self, x):
        Super.__init__(self, x)
        ......
Inheritance
Abstract superclasses:
class Super:
    def method(self): ...
    def delegate(self):
        self.action()
    def action(self):
        assert 0, 'action must be defined!'
Operator Overloading
__init__: Constructor
__del__: destructor
__add__, __radd__, __iadd__: +, right-side + , +=
__or__:  |
__repr__,__str__ : printing
__call__ : X()
__getattr__ : X.a
__setattr__ : X.a = value
__getitem__ : X[key], for loops, in tests
__setitem__ : X[key] = vlaue
__len__
__cmp__, __lt__, __eq__
__iter__
user-defined iterators
def __init__(self, start, stop):
def __iter__(self)
    return self
def next(self)
    ....
__getattr__ and __setattr__ catch attribute references
__getattr__: is not called if Python can find the attribute, used to deal with undefined attributes
__setattr__: if defined, self.attr = value --> self.__setattr__('attr', value)
    self.__dict__['name'] = x
__repr__ VS. __str__
>>>x  :  run __repr__
>>>print x  :  run __str__
add:
>>>x + 1 #__add__
>>>1 + y #__radd__
__call__:  x(attr)
__del__: run automatically when an instance's space is being reclaimed
Namespaces: The Whole Story
instance -- __class__ --> class
class -- __base__ --> higher superclasses

Chapter 22. Designing with Classed
Python and OOP
inheritance polymorphism encapsulation
Overloading by Call Signatures
*class C:
     def meth(self, x): ...    #a
     def meth(self, x, y):...  #b
 a will overwrited
*class C:
     def meth(self, *args):
          if len(args) == 1: ...
*class C:
     def meth(self, x):
          x.operation()
Classed as Records
OOP and Inheritance: "is-a" relationship
OOP and Composition: "has-a" relationship
OOP and Delegation
Multiple Inheritance
search process depth-first all the way to the top
Classes are objects: Generic Object Factories
apply function:
def factory(aClass, *args)
    return apply(aClass, args)
Methods are objects: Bound or Unbound
Unbound: class, no self
object1 = Spam()
t = Spam.doit
t(object1, 'lalal')
bound: instance, self + function pairs
object1 = Spam()
x = object1.doit
x('lalal')
Documentation String Revisited
import docstr
a.__doc__, a.b.__doc__
Class Versus Modules
they are both namespacefiles
Modules:
Are data/logic packages
Are created by writing Python or C extensions
Are used by imported
Classes:
Implement new objects
Are created by class statements
Are used by being called
Always live within a module

Oct 12, 2008

从9月16号开学,到现在已经差不多一个月了,终于逮着机会,浩浩荡荡50人聚一起吃烧烤啦~~
记下帐先:
费用:
烤炉:40元/次 小凳子:2元/把 铁网:5元/块 夹子:5元一把 木材:5元/打  门票:15元×八折  结论:黑,相当地黑。
原料:(摘自。。。。忘了。。)
餐具及辅助用品:一次性桌布(厚)、一次性筷子和碟子、纸杯、餐巾纸、竹签、毛刷、废报纸h、小刀及叉子
烧烤主食类:鸡翅 骨肉相连 肉串 馒头 蘑菇 年糕 玉米肠 贡丸 土豆 菜椒
其他:蜂蜜、香辣粉、辣椒面、番茄酱、盐
饮料:可乐、果汁、纯水
食物是昨天晚上去十人去沃尔玛买的,花了一千多,然后再加门票五百多,再加上烧烤用具的租金,七七八八倒也勉强够用。
然后。。。很郁闷,在搬木头的时候我踩到了钉子,而且扎得很深,回来的时候又在公园迷了路。折腾着五点总算到了学校,医务室又没破伤风针打,537路坐到了长海医院,大个破伤风针三块五,七七八八硬是整到了70多,然后又打车回了学校,霉。
http://picasaweb.google.com/shufe08/081012#

Oct 11, 2008

J10


今天在京东的库存品展销会上买了富士的J10,入门得不能再入门的相机,早日换单反,努力!!!##ReadMore##

Posted by Picasa

Oct 9, 2008

Learning python 读书笔记 PART 5

PART 5: MODULES
Chapter 15. Modules: The Big Picture
a.code reuse b.System namespace partitioning c.Implementing shared services or data
Python Program Architecture
import and from statements execute and load another file at runtime
How Imports Work
Find it --> Compile it(Maybe) --> Run it
Find it
The module search path:

a. home directory of the top-level file
b. PYTHONPATH directories (if set)
c. Standard library directories
d. The contents of any .pth files (if present)
current working directory
sys.path: the actual search path, is configured by Python at program startup
Compile it
.py & .pyc
Run it
import operation executes the byte code of the module
def: run at import time to create functions

Chapter 16. Module Coding Basics
Module Creation
module --import--> variables (name)
they should follow the normal variable name rules
<directory>m.<extension>
import a --> a.b
from a import b --> b
from a import * --> b
imports happen only once
Later imoort operations simply fetch an already loaded module object.
def, import, from are executable statements
import and from are assignments!
from small import x,y
x = 42 #change my x only
import small
small.x = 42 #change x in other module
equivalence from module import name
is euqal to
import module
name = module.name
del module
Module Namespace
attributes --namespace--> module ojbect
Module statements run on the first imoort: create an empty module object and execute the statements inside the module
Top-level assignments create module attributes
Module namespace: attribute__dict__, or dir(M) --> a directory object
Attribute Name Qualification
Import Versus Scope: function <--> module
Namespace Nesting
Reloading Modules
reload currently only works on modules written in Python; C extension modules cannot.
Reload Basics:
Reloads impact all clients that use import to fetch modules
Reloads impact future from clients only

Chapter 17. Module Package
Package import Basics
import dir1.dir2.mod --> dir0/dir1/dir2/mod
__init__.py
package initialization: run automatically
module namespace initialization
from* statement behavior
from Versus import with packages
import dir1.dir2.mod as mod #short name
from dir1.dir2 import mod

Chapter 18. Advanced Module Topics
_X: prevent being copied out in from* statement, but still not import statement
__all__: from* will only copy out those names listed in the __all__ list
can be used in __init__.py
__all__ = ["b","c"]
from __future__ import featurename
__name__ and __main__
run at top level: __name__ <-- "__main__"
if __name__ == '__main__'
tester()
from module import longname as name
Module Design Concept
you're always in a module in python
Minimize module coupling: global variables
Maximize module cohesion: unified purpose
Module should raraly change other module's variables

Code Complete PART 1: Laying the Foundation

Chapter 1. Welcome to Software Construction
What is Software Construction Activity:
problem definition
requirements development
construction planning
software architecture (high-level design)
detail design
coding and debugging
unit test
integration testing
integration
system testing
corrective maintenance
chapter 2. Metaphors for a Richer Understanding of Software Development
Metaphors: analogy --> modeling
Metaphors: heurstic, subject to chance Algorithm: predictable, deterministic, not subject to chance
common software Metaphors
Writing code: trial and error
Growing a System: incremental, iterative, adaptive, evolutionary
Building Software:
problem definition --> architectural design --> construction --> optimization (review and inspections)

Chapter 3. Measure Twice, Cut Once: Upstream Prerequisites
根本目标:降低风险
流程 --> 质量
Importance of Prerequisites
Causes of Incomplete Preparation:
Non't konw How --> 如果不能做好,做再多也没用!
尽快开始编码:WIMP(why isn't Sam Coding?)
Determine the Kind of Software You're Working On
商业系统 使命攸关 性命攸关
Inerative Approbches --> 修正成本地,发现缺陷的时间更接近引入缺陷的时间
Choosing Between Interative and Sequential Approaches:
需求稳定性 设计是否透彻 熟悉性 项目风险 长期可预测性 后期改变需求、设计和编码的代价
Problem-Definition Prerequisite
product vision -- vision statement -- mission statement -- product difenition == problem definition
应用客户的语言书写
Requirements Prerequistite
scope --> 降低更变
The Myth of Stable Requirements
Handing Requirements Changes During Construction: 评估,通报,建立程序,开发方法
Architecture Prerequistite
system architecture -- high-level design -- top-level design --> architecture specification
Typical architecutral components
program organization: 维护设计的缘由 <--> 维护设计本身
major classes: rules and relationship
data design: files & database
business rules
user interface design: 模块化,便于更换
resource management: 数据库连接、线程、句柄、内存
security: threat model
performance: 资源的使用,速度、内存、成本的优先顺序
scalability: 增长以满足未来需求的能力
internationalization / Localization (I18N, L10N)
Input/output: reading scheme (look-ahead or look-behind or just-in-time)
Error processing: a coding-convention level problem
纠正 or 检测? 主动 or 被动? 错误传播 消息处理 异常处理 处理错误的层次 输入数据有效性
Fault tolerance: 检测 恢复 包容
容错策略:退回 try again;辅助代码,主代码错误时使用;表决算法,分别计算-比较;使用虚假值(phony value)
architectural feasibility
overengineering
buy-vs.-build decisions
resuse decisions
change strategy
general architectural quality: 维护概念完整性
Amount of Time to Spend on Upstream Prerequisites
工作量:10% ~ 20%
时间:20% ~ 30%

Chapter 4: Key Construction Decisions
Choice of programming language
C: 1
Fortran 95: 2
C++, Java: 2.5
VB: 4.5
Perl, Python, Smalltalk: 6
语言的表达能力--思考的能力:你思考的能力取决于你是否知道能够表达该思想的能力
Language descriptions
Cobol: COmmon Business-Oriented Language
Fortran: FORmula TRANslation
Perl: Practical Extraction and Report Language
PHP: PHP:Hypertext Processor
BASIC: Beginner's All-purpose Symbolic Instruction Code
Programming in a language (如果语言工具是初级的,那么程序员的思想也是初级的)
programming into a language (思想 --> 决定如何使用工具)

Oct 7, 2008

Code Complete 读书笔记 PART 7

Software Craftsmanship 软件工艺
Chapter 31. 布局与风格
Layout and Style
准确、一致、易读性、易维护性
Layout Fundamentals
好的布局凸显程序的逻辑结构。
人 != 计算机
经验和规矩是吻合的
Layout as Religion
Objectives of Good Layout
准确,始终如一地表现程序的逻辑结构;改善可读性;经得起修改
Layout Techniques
分组:空行,空格
空行:将不相关的语句隔开 8% ~ 16%
缩进:2 ~ 4 空格,显示逻辑
Layout Sytles
纯块结构:Basic
仿纯块结构:java
begin-end {}
行尾布局
Laying Out Control Structures
begin-end: 未缩进;两次缩进  ×
在程序中加入空行,有助于思考语句的从属
缩进策略应统一
goto:标号大写、上下空行;包含goto的语句单独为一行
Laying Out Individual Statements
空格:逻辑、数组引用、子程序参数
续行:续行需明显(“+ , && ||”);所有后续行按标准量缩进;
Using only one statement Per Line
易调试,易修改,能提供关于复杂度的正确印象,线性阅读
数据声明:一行一声明,靠近首次使用的位置,合理组织顺序
注释:缩进一致,注释前加空行
有约定比约定某个特定细节更重要
Laying Out Routines
用空格分隔程序各部分
参数按标准缩进
Laying Out Class
Class Interfaces: 头部注释(类及完整用法) 构造析构 public protected private
Class Implementations: 类文件内容 类数据 public protected private
子程序间:2~3行

Chapter 32. 自说明代码
Self-Documenting Code
好的注释才有价值
源码包含大部分关键信息,信息融入代码
好的代码本身是最好的说明
注释应用来说明代码无法说明的东西
注释应易维护
External Documentation
单元开发文件夹:UDF: uint-development folder  SDF: software-development folder
详细设计文档
Programming Styla as Documentation
良好结构、直率易懂的方法、有意义的名称、具名常量、清晰的布局、最低复杂度的控制流和数据结构
循环 -- 良好定义的子程序
尽可能采用问题领域的术语
To Comment or not to Comment
好注释 != (重复代码 or 解释代码)
注释困难 --> 代码差劲 or 没有彻底理解
代码复杂:改进代码 > 添加注释
Kinds of comments
repeat of code
×
explanation of code ×
marker in the code (fix before release?)
summary of code: good for other readers
description of the code's intent: 意图而非解决方法
information that cannot possibly be expressed by the code itself
Commenting Efficiently
采用不会被打断和易于修改的注释方法
用伪码编程法减少注释时间
1 comment per 10 lines
Commenting Techniques
行尾注释:代码块,数据声明
数据声明:数据单位、允许范围、编码含义、输入数据限制、位标志

Chapter 33. 个人性格
Personal Character
谦虚,求知欲,诚实,创造性,纪律,高明的偷懒
好性格 -->正确的习惯
软件开发:建造材料=个人才智;工具=自己,其实在研究人的智力、性格
20/80,10:1
Intelligence and Humility
理解一个程序,需要很强的吸取细节的能力并能同时消化
《The Humble Programmer》:大部分编程工作都是在弥补我们有限的智力。承认自己智力有限并通过学习来弥补
减轻脑力负担:
系统分解,复查、详查、测试,程序尽量短小,尽量高层,规范
Curiosity
在开发过程中建立自我意识
试验!学会制造错误-->收获;利用小程序
阅读解决问题的方法
在行动之前做分析和计划:分析<-->行动
学习成功项目的开发经验:Programming Pearls, The Mythical Man-Month
阅读文档,RTFM!^_^
向专业开发看齐
入门级:某语言的基本功能,运用语言特性
中级:多中语言基本功能,熟练使用一种语言
熟练级:对语言和环境有专业技能
技术带头人级:人
Intellectual Honesty
了解代码,了解进度,如实反馈
Communication and Cooperation
代码可读性,编程首先是和人交流,其次才是计算机
Creativity and Discipline
在非关键之处设立规范,从而在更重要的地方发挥创造性
Form is liberating.
Laziness
拖延:逃避思考,实在懒
迅速完成:用最少时间做完不喜欢的工作。开明懒
编写某个工作完成不喜欢的任务:一劳永逸的懒
Characteristics that don't matter as much as you might think
persistence: 固执己见 or 坚韧不拔 知道何时放弃
experience: 软件开发行业的经验比书本知识价值要小,工作10年,是得到10年的经验还是1年经验的10次重复
Habits
精神品德,编程品德
态度端正,积极思考 --> 习惯
不能用没有习惯来代替坏习惯
Additional Resources
《The Humble Programmer》
Dijkstra:编程的本质任务就是驾驭计算机科学的极端复杂性,编程是唯一一个需要掌握从最底层到最高层9个数量级细节差异的人类活动。

Chapter 34. 软件工艺的话题
Themes in software Craftsmanship
编程的目的之一是管理复杂性
过程对产品有深远影响
团队:广泛沟通;单人:自我交流
编程应基于问题域而非解决方案
注意警告信息
迭代:软件质量
丰富的工具箱

Conquer Complexity
降低复杂度几乎和衡量程序员成果的最重要依据
方法:划分子系统,类、接口,保持接口抽象性,避免深层次的继承,避免深层的循环、条件判断,不用goto,不滥用异常(需以系统的观点使用),不让类过度膨胀,子程序短小,使用不言自明的变量,子程序参数尽量少,规范和约定
Pick Your Process
团队成员 --> Process --> 质量。
避免不成熟的优化
坏的过程损耗脑力
Write Programs for People First, Computer Secon
目标:算法精准,结构紧凑,性能好,注释清晰得体
Program into your Language, Not in It
要什么 --> 怎样用工具实现。
Fous Your Attention with the Help of Conventions
规范是一套管理复杂度的质量工具
规范能精确地传达重要的信息
规范能免除各种风险:禁止,要求 --> 防范
规范能增加对低层工作的可预见性
规范能弥补语言的不足之处
Program in Terms of the Problem Domain
尽可能工作于最高的软件层次
顶层代码:说明解决的问题
Separating a Program into Levels of Abstraction
Level 0: Operating-System Operations and Machine Instructions
Level 1: Programming-Language Structures and Tools
Level 2: Low level of implementation Structures 粘结层
Level 3: Low level Problem-Domain Terms 提供框架
Level 4: High level Problem-Domain Terms 基于问题域的术语
Watch for Falling Rocks
艺术  工艺(craft) 科学
良好的个人判断
玄机代码 maybe 差劲代码
设计的度量 反映 设计的质量
警告信息
重复,“不自在,不惬意”
不容易写注释,不易命名变量,不易将问题分解
难以理解,不安,猜测
找不到错误的原因仅仅因为是忽视
Iterate, Repeatedly, Again and Again
反复评估 --> 精确
开发:逐步精化,实证而非证明
迭代的代码调整
Thou Shalt Rend Software and Religion Asunder
software Oracles & Eclecticism
Experimentation
基于实验结果改变思路
“试图没有错误”是最大的错误
设计是仔细规划小错误以避免更大的错误
试验可用在很多层次上


Chapter 35. 更多信息

Software Construction
Pragmatic Programmer
Programming Pearls
Extreme Programming Explained: Embrace Change
Writing Solid Code
The Practise of Programming
Topic Beyond Construction
Facts and Fallacies of Software Engineer
Professional Software Development
The Psychology of Computer Programming
Software Engineering Overviews
Software Engineering: A Practitioner's Approach
Software Engineering 6th
Periodicals
Software Development www.sdmagazine.com
Dr.Dobb's Journal www.ddj.com
IEEE Software www.computer.org/software
Communications of the ACM www.acm.org/cacm/
A Software Developer's Reading Plan
Introductory Level
Conceptual Blockbusting: A Guide to Better Ideas
Programming Pearls
Facts and Fallacies of Software Engineering
Software Project Survival Guide
Code Complete
Practitioner Level
Software Configuration Management Patterns: Effective Teamwork, Practical Integration
UML Distilled: A Brief Guide to the Standard Object Modeling Language
Software Creativity
Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process
Rapid Development
Software Requirements
Professional Level
Software Architecture in Practice
Refactoring: Improving the Design of Existing Code
Design Patterns
Principles of Software Engineering Management
Writing Solid Code
Object-Oriented Software Construction

Oct 6, 2008

blogger功能增强

昨天花了两个多小时给blogger加上了留言板、标签云和缩略显示。
blogger本身提供的功能较少,但提供了灵活的模板编辑功能,就好像blogger提供了一系列的数据接口,让用户选择所需要的数据进行显示,这比普通的Web开发来得更加省事,blogger的技巧很大程度上可以称为HACK,再加上blogger的广大用户群,所以一般的博客需求都可以方便地找到在blogbger上的解决方案。
留言板使用了cbox提供的服务,在网上找下就可以了。
标签云详见:Blogger V3.0 添加标签云
但是里面的javascript空行太多,影响阅读,使用正则表达式%[ ^t]++^p匹配多余的空行,删除就可以了。
缩略显示详见一下的文章:继续阅读懒人加强版

Oct 5, 2008

Learning python 读书笔记 PART 4

PART FOUR. FUNCTIONS
Chapter 12. Function Basics
calls:  myfunc(argv)
def, return, yield: def adder(a, b=1, *c): return a+b+c[0]
global:  def function(): global x; x = 'new'
lambda:  funcs = [lambda x: x**2, lambda x: x*3]
1. Coding Functions
def is a executable statement which create an object and assigns it to a name
arguments are passed by assignment
global declares module-level variables that are to be assigned
def <name> (arg1, arg2...):
    ...
    return <value>
def can executes at runtime
if test:
    def function():
else:
    def function():
2. Definitions and Calls
Polymorphism in Python: because python is a dynamically typed language, every operation is polymorphic in python
in python, code is not supposed to care about specific data types.

Chapter 13. Scopes and Arguments
1. Scope Rules
Name <--> Namespace
The enclosing module is a global scope
The global scope spans a single file only
Each call to a function is a new local scope
Assigned names are local, unless declared global
All other names are enclosing locals, globals, or built-ins
LEGB: local --> enclosing functions --> global --> built-in
the built-in scope
>>> import __builtin__
>>> dir(__builtin__)
zip <--> import __builtin__,  __builtin__.zip
2. The global Statements
3. Scope and Nested Functions
LEGB: statically nested scope
lambda: an expression that generates a new function to be called later, much like def statement
4. Passing Arguments
immutable arguments <--> C's "by value" mode
mutable arguments <--> C's "by pointer" mode
Avoiding mutable arguments change:
pass a copy or tuple
Simulating output parameters:
>>> def multiple(x,y):
    x = 2
    y = [3,4]  #change local names only
    return x,y #return new values in a tuple(not two values)
>>> x = 1
>>> y = [1,2]
>>> x,y = multiple(x,y)  #assign result to caller's names
>>> x,y
(2, [3, 4])
5. Special Argument Matching Modes
func(value)    : Normal argument: matched by position
func(name=value)    : Keyword argument: matched by name
self documention, more meaningful
def func(name)   
def func(name=value)    : default argument value, if not passed in the call
make some arguments optional
def func(*name)    : Matchs remaining positional args(in a tuple)
>>>def f(*args): print args
def func(**name)    : Matchs remaining keyword args(in a dict)
>>>def f(**args): print args
>>>f(a=1,b=2)
{'a':1, 'b':2}
Argument Matching
rules:
key arguments after non-keyargument
*name after normal argument
**name last
Matching steps:
non-key argus --> key word argus --> extra non-key argus --> extra key argus -->default values

Chapter 14. Advanced Function Topics
1. Anonymous Functions: lambda
lambda expression creates a function to be called later, but returns it instead of assigning it to a name
lambda argu1, argu2, argu3...arguN: expression using argus
lambda bodies are single expression, not a block of statements
example1:
L = [(lambda x: x**1),(lambda x: x**2), (lambda x: x**3)]
for f in L
    print f(2)
print L[0](2)
example2:
key = 'b'
{'a': (lambda f1),
  'b': (lambda f2),
}[b]()
is equivalent to
def f1():...
def f2():...
...
key = ...
{'a':f1, 'b':f2}[key]()
How(not) to obfuscate your python code
((a and b) or c) is roughly equivalent to:
if a: b else: c
(C's a?b:c)
2. Applying Functions to Arguments
The apply built-in
apply(func, argus) == func(argus)
argument list is passed by tuple
if <test>:
    action,args = func1, arguments_a
else
    action,args = func2, arguments_b
...
apply(action,args)
3. Functions Over Sequences
>>> counter = [1,2,3,4]
>>> def func(x): return x + 10
>>> map(func,counter)
[11, 12, 13, 14]
>>>map((lambda x: x + 3), counter)
[3,4,5,6]
map(func,[1,2,3],[4,5,6]) #[func(1,4),func(2,5),func(3,6)]
4. Functional Programing Tools
filter
>>>filter((lambda x: x>0), range(-5,5))
[1,2,3,4]
reduce
>>>reduce((lambda x, y: x+y), [1,2,3,4]) 
10
>>>import operator
>>>reduce(opetator.add, [1,2,3,4])
5. List Comperhensions
[x ** 2 for x in range(10)]
map((lambda x: x ** 2), range(10))
[x for x in range(5) if x%2 == 0]
filter((lambda x: x%2 == 0), range(5))
map((lambda x: x**2), filter((lambda x: x%2 == 0),range(10)))
the genaral structure of list comprehensions
[expression for target1 in sequence 1 [if condition]
                for target2 in sequence 2 [if condition]....
                for targetN in sequence N [if condition]]
list comperhension and map are faster than for loop.
6. Generators and Iterators
Generators yield a value rather than returning one. The yield statment suspends the function and sends a value back to the caller and allow the function to resume from where it left off.
>>> def gensqure(N):
    for i in range(N):
        yield i ** 2
>>>x=gensqure(10)
>>>x.next(), x.next()...
Iterators and built-in type: iter(L)
__iter__ method

Learning python 读书笔记 PART 3

PART THREE: Statements and Syntax
Chapter 8. Assignment, Expressions, and Print
program  are composed of  modules contains statements contain expressions create and process objects
1. Assignment Statements
a = 'a'
a, b = 'a', 'b'   #tuple assignment
[a,b] = ['a','b']    #List assignment
a = b = 'c'    #Mutiple-assignment
L = L + [3], L = L + [5,6]    #Concatenate(create a new object)
L.append(3), L.extend([4,5])    #Faster, but in-place(add at the and of memory)
L += [9,10]    #Mapped to L.extend([9,10]): the faster mothed
2. Expression Statements
3. Print Statements
print a,b,    #don't add newline at the end of text
print >>myfile a,b    #send data to myfile.write, not to sys.stdout.write
redirecting the Output Stream
import sys
sys.stdout = open('myfile', 'a')
print and stdout
class FileFaker:
    def write(self, string)  #do something with the string
import sys
    sys.stdout = FileFaker()

Chapter 9. if Tests
1. if stataments
if: elif: else:
if 1:
    print 'true'
else:
    print 'false'
switch & case:
*if choice = 'a':
    print 'aaa'
elif choice = 'b':
    print 'bbb'
else:
    print 'default'
choice = 'b'
*print {'a':'aaa','b':'bbb'}[choice]
*branch = {'a':'aaa','b':'bbb'}
  print branch.get('a', 'bad choice')
2. truth tests
2<3, 3<2   #Less-than: return 1 or 0
short circuit evaluation
2 or 3, 3 or 2   #(2,3) Return left operand if true. Else return right operand.
[] or 3   #3
[] or {}   #{}
2 and 3, 3 and 2   #(3,2) return left operand if false. Else return right operand.

Chapter 10. while and for Loops
1. while loops
while <test>:
     <statement1>
     if <test2>: break    #Exit loop now, skip now
     if <test2>: continue    #goto top of loop now   
else:
     <statement2>    #if we didn't hit break
breaks, continue, pass and the loop else
Emulating C while Loops

C assignments return the value assignment; Python assignments are just statements, not expressions
C: while ((x = next()) != NULL){process x...}
Python equivalent:
*while 1:
    x = next()
    if not x: break
    ...process...
x = 1
*while x:
    x = next()
    if x:
    ...process
2. for loops
for <target> in <object>:
    <statements>
else:
    <statements>  #if we didn't hit break
3. loop variations
range

Counter Loops
range(3)  #[0,1,2]
range(2,5) #[2,3,4]
range(0,10,2)  #[0,2,4,6,8]
*for item in X: print item
*i = 0
 while i < len(X)
     print x[i],; i += 1
*for i in range(len(x)): print X[i]
Nonexhaustive Traversals
S = 'abcdefghijk'
for i in range(0, len(s), 2) print S[i],  #manual for indexing
for i in S[::2]: print x
Changing Lists
for i in range(len(L)):
    L[i] += 1
zip and map
zip can enable us to visit multiple sequences in parallel
L1 = [1,2,3], L2 = [4,5,6]
zip(L1,L2)   #[(1,4),(2,5),[3,6]]
for (x,y) in zip(L1,L2):
    print x, y,
when argument lengths differ, zip choose the shortest length
map(None, L1, L2)
map choose the longest length and filled empty items with "None"
Dictionary Construction with zip
>>> keys = ['a','b','c']
>>> values = [1,2,3]
>>> zip(keys,values)
[('a', 1), ('b', 2), ('c', 3)]
>>> D = {}
>>> for(k,v)in zip(keys,values):
    D[k]= v   
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> D2 = dict(zip(keys,values))
>>> D2
{'a': 1, 'c': 3, 'b': 2}
File Scanners
file = open('test.txt', 'r')
while 1:
    line = file.readline()
    if not line: break
    print line
1. for line in open('test.txt').readlines(): print line
2. for line in open('test.txt').xreadlines(): print line
3. for line in open('test.txt'): print line
xreadlines loads lines on demand, "3" relies on iterators, is equivalent of xreadlines

Chapter 11. Documenting Python Code
1. the python document interlude

dir(): Lists of attributes  available on objects
__doc__: In-file documentation attached to objects
docstrings
User-defined docstrings: strings at the top of file, method and class
built-in docstring:
import sys
print sys.__doc__
print int.__doc__, print open.__doc__
pydoc
help(sys)
2. common coding gotthas
Don't forget the colons
Start in column 1
Blank lines matter at the interactive prompt:
mean the end of compound statement
Indent consistently
Don't coding C in Python:
don't embed assignment statements in while loop tests
Use simple for loop instead of while or range:
for loop is simple and fast
Don't expect results from functions that change objects in-place:
append(), sort(), append(), extend()
myList = myList.append(X)  #set myList to None
Always use parenthesis to call a function
Don't use extensions or paths in imports and reloads

Oct 4, 2008

Google docs + Google Gear + Blogger

这几天把其它地方的blog都挪到Blogger上了,和其它blog服务相比,blogger更加简洁,而且方便定制。但这两天在使用的过程中,也发现了一些问题,首先Blogger本身提供的文本格式化工具较弱,拍版普通的文字尚可,但如果文字有缩进之类的就相当麻烦,Tab是没用的,就算在“誊写”状态下使用空格,虽然在编辑视图中缩进正常,但是在发布后依然难以控制缩进的量。其次我习惯性将博客写在word中,然后粘帖到在线博客的编辑窗口,但doc中的样子在粘帖过程中很难不走样。

首先我想到的从word中导出Html,然后粘帖到blogger的html视图中,但即使将导出的html进行规整后,显示的效果依然极不理想。

接着我想到了像blogger这么大的用户群,应该有人会开发blogger for word的插件,结果还真让我给找着了,可实际结果是登录blogger帐号失败,分析下来的结果是用户名和密码的字符编码可能在中文win环境下有错,导致了不能登陆,在windows环境下,这类字符编码的问题很少发生,但发生了还真想不到解决的办法。

然后我又想到既然word和Google doc间的兼容性较好,而Google的产品间应该也有较好的兼容性,因此我想到了word-->Google doc-->Blogger这样的发布路线,但实际操作下来word-->Google doc这一步没有问题,但从Google doc 发布到blogger时仍然出现了问题,虽然现在Google doc支持将文档直接发布到Blogger,但是发布的效果和doc中的显示效果有较大的差别。其实原因很简单,Google doc默认使用的CSS和Blogger使用的CSS有些不同,但修改Blogger模板有点烦,一个个属性一个个值调下去太费时间。不过我觉得只要调整正文的P、ul、li、dvi这四个属性就能取得比较好的显示效果。

最后的结果是,现在我不用office了,直接使用Google docs,虽然功能少些,但是够用,也不要担心文章丢失之类的东西。想想Google docs推出这么些年,也该出个离线编辑功能了吧,找了下还果然发现了。

首先要在http://gears.google.com/下载Google Gear,Google的一个支持web apps离线操作的软件,下载后能自动套用到当前使用的浏览器。然后启动Google Docs,在“设置”中将语言设成English(现在还不支持中文版的Google Docs),然后重启下浏览器,Google docs的右上方就会出现:offline链接,搞定!

Learning python 读书笔记(6, 7章)

Chapter 6: Lists and Dictionaries
1. List
Methods: grow, sort, search, reverse, append, extend, append
del L[x:y], L[x:y]=[a,b,c]
range(x), xrange(x,y), L.pop()
2. List in Action
Slice assignment: delete + insert
L.append(x) < -- > L+[x]
3. Dictionaries
D.keys(), D.values(), D.items():
create a new list
D.copy(), D.get(k, default),
D2.update(D1): merges the keys and values of one directory into another, blindly overwriting values of the same key.
D.has_key(k), k in D
D = dict(zip(keyslist, valueslist))
4. Dictionaries in Action
sequence operation don’t work.
Assigning to new indexes adds entries.
keys need not always be strings.(can be other immutable object)
Using dictionaries to simulate flexible lists Using dictionaries for sparse data structures
Matrix = {}
Matrix[(2,3,4)] = 88: the number at position (2,3,4) is 88
Using dictionaries as “reconds”
Dictionary interfaces
import anydbm
file = anydbm.open(“filename”)
file [‘key’] = ‘data’ #store data by key
data = file[‘key’] #fetch data by key

Chapter 7: Tuples, Files, and Everything Else
1. Tuples

simple groups of objects, cannot change in place(immutable), don't support any method calls
>>> (1,2) + (3,4)
(1, 2, 3, 4)
>>> (1,2) * 3
(1, 2, 1, 2, 1, 2)
>>> T = ('1', '2', '3')
>>> tmp = list(T)
>>> tmp
['1', '2', '3']
>>> T2 = tuple(tmp)
>>> T2
('1', '2', '3')
>>> T = (1, [2,3], 4)
>>> T[1][0] = 5 #works
>>> T[0] = 0 #Fails
2. Files
input = open('path', 'r'), output = open ('path', 'w')  #mode: r, w, a
S = input.read(), S = input.read(N) # N bytes
S = input.readline(), S = input.readlines()
output.write(S), output.writelines(L), output.close()
seek: reset current position in file, flush: buffered output write into disk
3. Type Categories Revisited
Operator Overloading:

class MySquence:
    def __getitem__(self, index):
        #called on self[index]
    del __add__(self, other):
        #called on self + other
4. Object Generality
Lists, dictionaries, and tuples can: 1. hold any kind of object 2. arbitrarily nested
Lists and dictionaries can dynamically grow and shrink.
5. References Versus Copies
No reference to the same object:

A = L[:]    #instead of: A = L (or list(L))
B = D.copy()    #instead of: B = D
empty-limit slices and copy method only do a top-level copy!
nested copy:
import copy
X = copy.deepcopy(Y)
6. Comparisons, Equality, and Truth
L1 == L2, L1 is L2    #Equivalent? Same object?
But short string: S1 = 'spam', S2 = 'spam' # S1==S2: true, S1 is S2: true
Numbers are true if nonzero
Other objects are true if nonempty
None: much like NULL in C
L = [None] * 100
bool: True, False

Oct 3, 2008

Concept map 思维导图

接触思维导图是在《学习的革命》开始流行的那会,书中叫做“脑图”,兴许是名字太土,如今换成叫思维导图,听起来专业了些。也着实画了几张,后来新鲜劲过了也就没继续下去。昨天在抓虾上看到了《从优秀到卓越》的思维导图,发现看这图相比看书,比快餐还快餐,一下子就能知道个大概。接着试用了几款软件,MindMapper、Keystone和Inspriation。比较下来几款软件并无多少差异,可从作图的美观性和实例多少来看,MindMapper更为优秀。不过后来在Visio中找了下,发现也有类似的功能,即是所谓的灵感触发图。总的用下来Visio还是最好的,操作便捷且绘图标准大方。

在Visio中脑图一共有四种图形:主标题、标题、动态连接线和关联线。十分简单,而且够用。要花哨的话也提供了一些模板可以套用,使用上还是十分方便的。



http://picasaweb.google.com/xuyizun/LbltPF#
在网络相册中我放了一些搜集到的思维导图。

可我们真的需要脑图么?如果它真的有用,那么在工作中早就在应用了,而实际上直到现在,脑图依然处在个人的尝试中,我认为导致脑图并不流行的原因有以下几点:首先是脑图本身的局限性,它太简单而且太缺乏标准了,简单导致了灵活和杂乱,的确,脑图几乎可以表示任何结构的知识或思考;但由于没有标准的图例,一来导致了过于灵活,二来稍显杂乱。其次是中国的教育体制决定的,从小我们就被锻炼出了十分不错的记忆力,既然看完能较快地记住,脑图也就变得不那么重要了,因为脑图从本质上来讲就是为了帮助大家较好地建立一个思维体系。

下面用思维导图来表示思维导图的局限,算是练习咯!

Oct 2, 2008

Learning python 读书笔记(1--5章)

PART ONE: Getting Started
Chapter 1: A Python Q&A Session
Chapter 2: How python runs programs
1. Source(x.py) --> Byte Code(x.pyc) --> runtime(PVM)
2. CPython, Jython and Python.net
Psyco: Just-in-Time Compiler
3. Frozen Binaries: program + PVM = binary executable program.
Py2exe(for windows), Installer(Linux & Unix), freeze(original)
Chapter3: How you run programs
1. Unix executable scripts: start with #!/usr/local/bin/python
2. raw_input trick: pause the script
3. import and reload
imports are too expensive an operation to repeat, so when we use reload() instead.
4. Attributes: import xx & from xx import yy. yy are the attributes in the python file xx.
5. IDE: IDLE, Komodo, PythonWorks, PythonWin, Visual Python(plugin for VS).
6. text editor: see http://www.python.org/editors

PATR TWO: Types and Operations
Chapter4: Numbers
1. programs  modules  statements  expressions.
2. Numbers: Normal integers(C longs); Long integers(unlimited size); Floating-point(C doubles);Octal and hex literals; Complex number literals.
3. NumPy(Numeric Python).
4. When use a variable that has never been assigned, Pythons report an error rather than a default value.
5. Numeric representation:
>>>b/a #Auto echo output: more digits
>>>print b/a #print rounds off digits.
>>>repr(num) #Used by echos: as cod form
>>>str(num) #Used by print: user-friendly form
6. Division: Classic, Floor and True
x/y: Classic division
x//y: Floor devision
>>>from __future__import division
7. >>>import math
>>>math.pi, math.e
8. >>>int(‘0100’), int(‘0100’, 8), int(‘0x40’, 16) #100, 64, 64
>>>oct(64), hex(64) #’0100’, ‘0x40’
>>>eval(‘100’), eval(‘0100’), eval(‘0x40’) #100, 64, 64
9. >>>a=3 # a: Names (reference) 3: Object
10. >>>L1 = [2, 3, 4]
>>>L2 = L1
>>>L1 = 24 #L2 is not changed
>>>L1[0] = 24 #L2 = [24, 3, 4]
Chapter 5: Strings
1. >>> s = ‘a\nb\tc’
>>> s # output is the original sequence
>>> print s #output is translated sequence
>>>len(s) #5
2. If python doesn’t recognize the character after ‘\’, it simple keeps the backslash in the resulting string.
3. Raw stirng: r’xxxx’
4. u‘xxx’: Unicode string
5. >>> abc = 'abc'
>>> for i in abc:
print i
a
b
c
>>> for i in abc:
print i,
a b c
6. Index and slicing:
>>> num = '123456'
>>> num[1:3], num[5:], num[:-4]
('23', '6', '12')
>>> num[::2], num[::-1], num[0:-3:2]
('135', '654321', '13')
7. String conversion tools:
>>>int(“42”), str(42) #Convert from/to string
>>>string.atoi(“42”), ‘42’ #older techniques
8. You cannot change a string in place(by assigning an index).
9. String formatting
>>> "%s %d %s" %('I', 4, 'you')
'I 4 you'
%s: string
%r: s, but uses repr()
%c: character
%d: decimal (integer)
%i: integer
%u: unsigned integer
%o, %x, %X: Octal, Hex, Hex uppercase
%e, %E: floating-point exponent
%f: float point
%g, %G: floating-point e or f
%%: %
%[(names)][flag][width][.precision]code
>>> x = 1234
>>> res = "integers:...%d...%+d...%-6d...%06d" %(x, x, x, x)
>>> res
'integers:...1234...+1234...1234 ...001234'
10. String methods:
X.method(arguments) == string.method(X, arguments)
list(); join(); capitalize(); center(width)…