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


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

文章插图
程序员编程培训
Thanks to a proliferation of free online tutorials, virtually anyone can learn how to code. Once you’ve been a developer for a while though, you quickly start to realize that all code is not created equal. Programming forums are awash with horror stories detailing ginormous if-else blocks, massive spaghetti-like algorithms and redundant code that serve no purpose.
由于免费在线教程的大量增加,几乎任何人都可以学习编码 。一旦成为开发人员已有一段时间,您就会很快开始意识到并非所有代码都是平等的 。编程论坛上充斥着恐怖的故事,详细描述了巨大的if-else块,大量类似于意大利面条的算法以及毫无用处的冗余代码 。
While these may seem like rookie errors that only bedevil persons just starting out, many programmers carry on these bad habits well into their career with disastrous results.
尽管这些看上去像菜鸟般的错误,只是让那些刚起步的人迷上了,但许多程序员却将这些不良习惯带入了他们的职业生涯,并带来了灾难性的后果 。
程序员编程培训_每个程序员都必须知道的5条编程原则

文章插图
Image Source
图片来源
Below are some of the useful principles of programming that you must keep in mind while writing code.
以下是编写代码时必须记住的一些有用的编程原理 。
1.简单性 (1. Simplicity)
Simplicity is the ultimate sophistication and perhaps nowhere more than in programming. It all begins with how you document and dissect program requirements. Each requirement should be well articulated to the extent that once you start to code, you can satisfy these requirements using the simplest of techniques.
简单性是最终的复杂性,也许在编程中无处不在 。这一切都始于您如何记录和分析程序需求 。每个要求都应明确阐明,以便您开始编码后就可以使用最简单的技术来满足这些要求 。
Complex code not only takes more time to design and write but is also more vulnerable to errors and bugs. A labyrinth of code can make web app monitoring tedious. Beware of feature creep where you start to add new features to the program that the customer didn’t ask for as this only needlessly entangles the software.
复杂的代码不仅需要花费更多的时间来设计和编写代码,而且更容易出错和出现错误 。迷宫般的代码会使 Web应用程序监视 变得 乏味 。当心功能蔓延,在这里您开始向客户不需要的程序添加新功能,因为这只会不必要地纠缠软件 。
2.不要重复自己 (2. Do Not Repeat Yourself)
Minimal repetition is a sign of quality code. Avoid duplicating logic and data. To know whether your program has excessive repetition, think about how much code you’d need to modify if you wanted to alter one aspect of the application’s behavior.
重复最少是质量代码的标志 。避免重复逻辑和数据 。要知道您的程序是否重复过多,请考虑如果您想改变应用程序行为的一个方面,需要修改多少代码 。
To minimize duplication, identify all sections of code that do the same thing. Abstract this common blocks of code into a single function that you call whenever you need to perform the said task. That way, if you ever need to change how the task is performed, you’ll need only modify the one function as opposed to amending multiple lines of code throughout program.
为了最大程度地减少重复,请确定执行相同操作的所有代码段 。在需要执行上述任务时,将这些通用代码块抽象为一个函数 。这样,如果您需要更改任务的执行方式,则只需要修改一个函数,而不是在整个程序中修改多行代码即可 。


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

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