posts - 84, comments - 54, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Some good programming styles

Posted on 2007-04-25 10:57 马达+斯加 阅读(204) 评论(0)  编辑  收藏 所属分类: My life recorder
From <A Programming Style for Java> by Paul Haahr.
 

Choose a good name: The reason that you can't pick a good name is that you don't understand enough what you are trying to say, or what you are going to do.

Be consistent: Of course, which variations are purposeless and which consistencies are foolish is a subjective matter.

Comment appropriately: If no question would be asked by the reader, there is no purpose in answer it. A comment which doesn't answer any questions is probably superfluous.

Be a chameleon: When you are dropped into a piece of existing code, don't rewrite it all in your own style.

Use consistent naming conventions.

User names you can pronounce.

Don't use abbreviations: unless everyone knows that, e.g. URL, EJB

Don't subclass concrete classes.

Keep classes, fields, and methods private until they are needed elsewhere.

Use final for fields which shouldn't change.

Make all non-final fields private: Use setter and getter to control the fields.

Each method should do one thing.

Smaller methods are easier to understand.

Create new variables rather than reassigning old ones.

Don't modify parameter variables.

Don't use exceptions for normal control flow.

只有注册用户登录后才能发表评论。


网站导航: