规范3

目录文档 所有的目录下都需要具有readme文档,其中包括: 该目录的功能及其包含内容 一个对每一文件的在线说明(带有link),每一个说明通常还应该提取文件标头的一些属性名字。 包括设置、使用说明 指导人民如何连接相关资源: 源文件索引 在线文档 纸文档 设计文档 其他对读者有帮助的东西 考虑一下,当每个原有的工程人员走了,在6个月之内来的一个新人,那个孤独受惊吓的探险者通过整个 工程的源代码目录树,阅读说明文件,源文件的标头说明等等做为地图,他应该有能力穿越整个工程。 ——————————————————————————– use a design notation and process programmers need to have a common language for talking about coding, designs, and the software process in general. this is critical to project success. any project brings together people of widely varying skills, knowledge, and experience. even if everyone on a project is a genius you will still fail because people will endlessly talk past each other because there is no common language and processes binding the project together. all youll get is massive fights, burnout, and little progress. if you send your group to training they may not come back seasoned experts but at least your group will all be on the same page; a team. there are many popular methodologies out there. the point is to do some research, pick a method, train your people on it, and use it. take a look at the top of this page for links to various methodologies. you may find the crc (class responsibility cards) approach to teasing out a design useful. many others have. it is an informal approach encouraging team cooperation and focusing on objects doing things rather than objects having attributes. theres even a whole book on it: using crc cards by nancy m. wilkinson. ——————————————————————————– using use cases a use case is a generic description of an entire transaction involving several objects. a use case can also describe the behaviour of a set of objects, such as an organization. a use case model thus presents a collection of use cases and is typically used to specify the behavior of a whole application system together with one or more external actors that interact with the system. an inpidual use case may have a name (although it is typically not a simple name). its meaning is often written as an informal text description of the external actors and the sequences of events between objects that make up the transaction. use cases can include other use cases as part of their behaviour. requirements capture use cases attempt to capture the requirements for a system in an understandable form. the idea is by running through a set of use case we can verify that the system is doing what it should be doing. have as many use cases as needed to describe what a system needs to accomplish. the process start by understanding the system you are trying to build. create a set of use cases describing how the system is to be used by all its different audiences. create a class and object model for the system. run through all the use cases to make sure your model can handle all the cases. update your model and create new use cases as necessary. ——————————————————————————– open/closed principle the open/closed principle states a class must be open and closed where: open means a class has the ability to be extended. closed means a class is closed for modifications other than extension. the idea is once a class has been approved for use having gone through code reviews, unit tests, and other qualifying procedures, you dont want to change the class very much, just extend it. the open/closed principle is a pitch for stability. a system is extended by adding new code not by changing already working code. programmers often dont feel comfortable changing old code because it works! this principle just gives you an academic sounding justification for your fears 🙂 in practice the open/closed principle simply means making good use of our old friends abstraction and polymorphism. abstraction to factor out common processes and ideas. inheritance to create an interface that must be adhered to by derived classes. ——————————————————————————– design by contract the idea of design by contract is strongly related to lsp . a contract is a formal statement of what to expect from another party. in this case the contract is between pieces of code. an object and/or method states that it does x and you are supposed to believe it. for example, when you ask an object for its volume thats what you should get. and because volume is a verifiable attribute of a thing you could run a series of checks to verify volume is correct, that is, it satisfies its contract. the contract is enforced in languages like eiffel by pre and post condition statements that are actually part of the language. in other languages a bit of faith is needed. design by contract when coupled with language based verification mechanisms is a very powerful idea. it makes programming more like assembling specd parts. ——————————————————————————– 其他杂项 这一部分包含着各种各样的该做的和不该做的。 在需要用到离散的数值使,不要使用浮点数变量。采用浮点数来做循环计数器无异于向自己的脚 开枪。测试浮点数时总要使用 ,永远不要用 = 或 => 。 不要使用程序自动美化器,得益于好的程序样式的主要的人就是程序员自己,特别是刚开着手代 码、算法设计的程序员,使用程序自动美化器仅仅能根据语法来更正程序,因此当对空白和缩进 的注意有很大需要时,它是不可能做到的。正常的细心注意细节的程序员们能很好的用清晰直观 的样式来完成一个函数或文件(换句话来说,一些直观的样式是意向的规定而不是程序自动美化 器能读懂的智慧)。马虎的程序员应该学习细致的程序员,不要依赖程序自动美化器来增加程序 的可读性。最初的美化器是必须分析源代码的程序,复杂的美化器不值得通过这样获得好处,美 化器最好用于生成总的机器建立(machine-generated)格式代码。 对逻辑表达式第二个 = 不小心的忽略是一个问题,以下显得混乱而且更像是错误: if ($abool= $bbool) { … } 程序员在这里真的是要赋值么?一般常常是,但通常又不是这样。这样避免引起这样的混乱呢?解 决方案就是不要这样做,利用显式和隐式的判断测试,推荐的方法是在做测试前先做赋值: $abool= $bbool; if ($abool) { … } ——————————————————————————– 使用if (0)来注释外部代码块 有时需要注释大段的测试代码,最简单的方法就是使用if (0)块: function example() { great looking code if (0) { lots of code } more code } 你不能使用/**/,因为注释内部不能包含注释,而大段的程序中可以包含注释,不是么? ——————————————————————————– different accessor styles why accessors? access methods provide access to the physical or logical attributes of an object. we disallow direct access to attributes to break dependencies, the reason we do most things. directly accessing an attribute exposes implementation details about the object. to see why ask yourself: what if the object decided to provide the attribute in a way other than physical containment? what if it had to do a database lookup for the attribute? what if a different object now contained the attribute? if any of the above changed code would break. an object makes a contract with the user to provide access to a particular attribute; it should not promise how it gets those attributes. accessing a physical attribute makes such a promise. implementing accessors there are three major idioms for creating accessors. get/set class x { function getage() { return $this->mage; } function setage($age) { $mage= $age; } var $mage; } one method name class x { function age() { return $mage; } function age($age) { $mage= $age; } var $mage; } similar to get/set but cleaner. use this approach when not using the attributes as objects approach. attributes as objects class x { function age() { return $mage; } function rage() { return &$mage; } function name() { return mname; } function rn

http://www.bkjia.com/phpjc/532253.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/532253.htmltecharticle目录文档 所有的目录下都需要具有readme文档,其中包括: 该目录的功能及其包含内容 一个对每一文件的在线说明(带有link),每一个说明…

Posted in 未分类