程序员编程培训_每个程序员都必须知道的5条编程原则( 二 )


3.现在而不是将来的代码 (3. Code for the Now not the Future)
One of the smart principles of programming is to make provisions for future changes in the code. It should be easy for a third party who was not involved in the project, to follow the logic and add or remove functionality as needed.
编程的明智原则之一是为将来的代码更改做好准备 。对于不参与项目的第三方来说,遵循逻辑并根据需要添加或删除功能应该很容易 。
Nevertheless, making provisions for future maintenance isn’t the same as coding in functionality that you might need in future. The latter only increases the volume of code while creating a new avenue for bugs. In any case, such functionality is often not needed at all in future.
但是,为将来的维护做准备与将来可能需要的功能编码不同 。后者只会增加代码量,同时 为错误 创建新的 途径。无论如何,将来通常根本不需要这种功能 。
Coding for the now prevents scope creep. Unless the end user specifically requests for this functionality to be included from the onset, stay away from it.
现在进行编码可防止范围蔓延 。除非最终用户明确要求从一开始就包含此功能,否则请远离它 。
4.不要过早优化 (4. Don’t Optimize Prematurely)
When you enroll for a basic programming course, one of the areas of emphasis is the need to create fast efficient algorithms. The mistake some coders make is to run with this one lesson. They get immersed in trying to speed up and optimize the code from the start while losing sight of the primary objective which is a creating a functioning program.
当您注册基础编程课程时,重点领域之一就是需要创建快速高效的算法 。一些编码人员犯的错误是在学习这一课时 。他们全神贯注于从一开始就试图加快代码的速度并优化代码,同时又忽略了创建功能正常的程序的主要目标 。
Work on meeting the system requirements first then move on to optimize the code. Optimizing too early is akin to groping in the dark. Before the program is up and running, you cannot really be certain where the bottlenecks will be. You could waste precious time optimizing a function whose speed doesn’t contribute much to overall program performance.
首先要满足系统要求,然后继续进行代码优化 。太早进行优化类似于在黑暗中摸索 。在程序启动并运行之前,您无法真正确定瓶颈将在何处 。您可能会浪费宝贵的时间来优化功能,而该功能的速度对整体程序性能的影响并不大 。
Ergo, first satisfy the program requirements then work on resolving the bottlenecks.
因此,首先要满足程序要求,然后再解决瓶颈 。
5.聪明的代码之上的可读代码 (5. Readable Code Over Clever Code)
Clever code is programming that is less about creating easily understandable code and more about showing everyone how smart you are. A typical example of clever code is packing an excessive amount of program logic into a single line of code.
聪明的代码是编程,而不是创建易于理解的代码,而更多的是向所有人展示您的聪明程度 。聪明代码的典型示例是将过多的 程序逻辑 打包 到一行代码中 。
Minimal code was at one time heralded as a sign of good programming but over time, the industry has recognized that brief code is meaningless if it’s hard for someone else to follow the logic. Any line of code that would take another programmer dozens of minutes to understand should probably be done away with.
极少的代码曾一度被认为是良好编程的标志,但随着时间的流逝,业界已经认识到,如果其他人很难遵循逻辑,那么简短的代码就毫无意义 。可能需要其他程序员花费数十分钟才能理解的任何代码行,都应该删除 。
Good programming is not only about building applications that meet the end user’s expectation but also creating code that is easy to understand. Following these programming principles will ensure you achieve both.


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: