Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)
published in(发表于) 2016/8/22 9:47:09
Define code: no need to explain, a glance,

English

中文

Define code: no need to explain, a see-programmers, the code-IT information

Good code, like a good joke – able to make themselves understood without explanation. If you are self-explanatory code can do, most of the time, you don't need to equip them with documentation.

Good code, just like a car equipped with excellent sound, and Cup holder car, this car to a top speed when you hear noise, don't have to worry about water spill. When it fails, any mechanic can use the most common tools in the shortest possible period of time, easy to fix it.

Bad code is like a promise you top speed can reach 200MPH, but audio can play old tapes, and Cup holders or instability of the car. When you're adjusting reflector angle, the car suddenly fails and general mechanics won't be able to fix the car, need to find experts, experts on the production line using specialized tools to repair it.

Good code is a book of writing skill person wrote

1. easy to understand

2. Chapter, and each chapter has a clear theme

Bad code is like people who are just learning to write books

1. complicated between chapters, each chapter has no specific purpose

2. a long repetition of a Word, and for no apparent reason

3. set some rules at the beginning, but in the back of the content but in their own continue to violate these rules

4. a vampire suddenly appeared in the book, back in the day and suck blood.

If you want to write good code, you must keep in mind the following

? Readability – you are not alone, and you to cooperate with you and other developers

? Maintainability – make your code when modifying a simple

? Simplicity--don't let your code seems unnecessarily complex

? Efficiency – make your code as much as possible for fastest speed

? Clarity – of self-explanatory code can do if you, in most cases, you don't need to equip them with documentation. Method and property names when possible and reasonable. Split long codes. Do not copy/paste the code block.

If your colleague is not easily read the code you write, then your code is good enough.

Code quality test

1. find a developer have never read your code and let him look at your code and let him try to speak of each module.

2. If you often need to explain to him, so that your code was not good enough. Explain more, lower the quality of the code.

3. If you sit quietly, without having to ask you any questions that you code is of high quality.

When you're writing code when some signals you can prove that you wrote the code quality:

? Write the code is clever, but not too clever

? In terms of speed, and readability, you use the best algorithm

? Classes, variables, and functions are correctly named, so that people can see at a glance understanding

? After a weekend of rest, you continue to write code, I found myself immediately before continuing work

? The need to reuse things is always available

? The methods used for a short period, under the most ideal circumstances to less than 50 lines, up to a maximum of 100 rows and can be perfect to perform a single task

? When the method is called, you have enough information, without code search

? Is this the first feature to add and modify code

? Volume of try/catch blocks as small as possible

? The effortless to write unit tests

Good code is modular

Assumes your project has three distinct layers-the inner, middle and outer. Your content should and outer layers to import anything from it. Middle managers should not import anything from an outer layer, the benefit of this is that you can layer for independent testing of the code.

"Good code itself is the best description of the document. " — Steve McConnell


定义好代码:无需解释,一看便知 - 程序员,代码 - IT资讯

好的代码,就像是好的笑话——无需解释就能让别人明白。如果你的代码能够做到不解自明,在大多数时候,你根本无需为其配备说明文档。

好的代码,就像是一辆配备了优秀音响和杯架的汽车,这辆车在行驶到最高速度的时候,你听不到噪音,也不用担心水会洒出来。在它出现故障的时候,任何一名修理工都可以使用最常见的工具,在最短的时间里轻松将其修好。

而坏的代码,就像是一辆向你承诺最高速度可以达到200MPH,但是音响只能播放老式的磁带,而且杯架还不稳的车。你在调整反光镜角度的时候,汽车都会突然出现故障,而且一般的修理工还修不了这辆车,必须要找专家,让专家在生产线上使用专业的工具来修理。

好代码像是一本写作技巧高超的人所写的书

1.容易理解

2.分章明确,每一章都有清晰的主旨

而坏的代码像是刚刚学会写字的人所写的书

1.各个章节之间纷乱复杂,每一章都没有明确的主旨

2.连篇累牍的重复一句话,而且毫无缘由

3.作者在一开始设定了一些规则,但是在后面的内容中却自己不断的违反这些规则

4.突然间书里出现了一个吸血鬼,而且还能在白天出来吸血。

要想写出好的代码,你一定要牢记以下内容

• 可读性——不只是你,还有你身边与你合作的其他开发者

• 可维护性——让你的代码在修改的时候很简单

• 简洁性——不要让你的代码看上去毫无必要的复杂

• 效率性——尽可能的让你的代码获得最快的运行速度

• 明确性——如果你的代码能够做到不解自明,在大多数时候,你根本无需为其配备说明文档。在为方法和属性命名的时候,做到尽可能的合理。把长的代码进行拆分。不要复制/粘贴代码块。

如果你的同事不能轻松的看懂你写的代码,那么你的代码就不够好。

代码质量测试

1.找一个从来没读过你的代码的开发者,让他看你的代码,并且让他试着说出每一个模块的作用。

2.如果你经常需要向他进行解释,那么说明你的代码不够好。解释的次数越多,代码的质量就越低。

3.如果你只是静静的坐在一边,他无需问你任何问题,那说明你的代码质量很高。

当你在写代码的时候,一些信号可以证明你写的代码质量不错:

• 代码写的很聪明,但是又不会过分的聪明

• 无论在速度上,还是可读性上,你都使用了最佳的算法

• 类、变量和函数都得到了正确的命名,让人看一眼就能理解

• 休息了一个周末之后,你继续写代码,发现自己可以立刻继续之前的工作

• 那些需要重复使用的东西总是可用

• 你所使用的方法都很短,最理想的情况下要少于50行,最多不超过100行而且能够完美的执行单个任务

• 在调用方法的时候,你有着足够的信息,无需在代码堆中苦苦寻找

• 能够很轻松的在此前的代码中进行功能添加和修改

• try/catch块的体量尽可能的小

• 毫不费力的就可以写出单元测试

好代码都是模块化的

假设你的项目中有三个不同的层——内层、中层和外层。你的内容不应该从中层和外层那里导入任何东西。中层不应该从外层导入任何东西,这样做的好处是,你可以对代码的内层进行独立测试。

“好的代码本身就是最好的说明文档。” — Steve McConnell






If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759