20090324

半部九阴真经 下卷

半部九阴真经

下卷。

----
JAVA的复杂度检查工具 和 code coverage工具。
甚至能检查疑似的copy&paste代码。

对比C++。群众基础是多么重要啊。

-----

YAGNI STANDS FOR "YOU AIN'T GONNA NEED IT." ItT

不要为将来而担心.
过度工程.
-----

Powerful languages + domain-specific meta-layers offer the best
approach currently available. The productivity comes from working
close to the problem domain in the DSL; the power comes from the
abstraction layer simmering just below the surface. Expressive DSLs on
top of powerful languages will become the new standard. Frameworks
will be written using DSLs, not on top of statically typed languages
with restrictive syntax and unnecessary ceremony.

------

The Law of Demeter

不要跟陌生人说话.

never use more than one dot for any method call.

Job job = new Job("Safety Engineer", 50000.00);
Person homer = new Person("Homer", job);
homer.getJob().setPosition("Janitor");

按 Law of Demeter,改为

public PersonDemo() {
Job job = new Job("Safety Engineer", 50000.00);
Person homer = new Person("Homer", job);
homer.changeJobPositionTo("Janitor");
}
public void changeJobPositionTo(String newPosition) {
job.changePositionTo(newPosition);
}

Person屏蔽了job的细节.

杨常使用上面的那个不符合law of Demeter的方法,并困惑client怎么能不对job产生信赖.

---------------------
以下是引用的。

For projects on which I'm the tech lead, our rule of thumb is to
allow no method to exceed 15 lines of code in Java or C#. For dynamic
languages such as Groovy or Ruby, the rule is five lines of code.f
------------------
SLAP,没注意过这个。
这样,写public函数就有有点类似于写大纲了。

SLAP STANDS FOR THE SINGLE LEVEL OF ABSTRACTION PRINCIPLE.

SLAP insists that all your code within a
method live at the same level of abstraction.

Encapsulate all implementation details away from public methods.
----------------------
完美编辑器需要的功能之一

Additive cut and copy commands
Don't make round trips when you can batch.
------------------------
对于XML持否定态度
可以使用XML,但是只生成,不书写。
Keep behavior in (testable) code.
举例,用Groovy生成XML。
--------------------------

No comments: