程序員編程培訓(每個程序員都必須知道的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.由于免費在線教程的大量增加,幾乎任何人都可以學習編碼 。 一旦成為開發(fā)人員已有一段時間,您就會很快開始意識到并非所有代碼都是平等的 。編程論壇上充斥著恐怖的故事,詳細描述了巨大的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.盡管這些看上去像菜鳥般的錯誤,只是讓那些剛起步的人迷上了,但許多程序員卻將這些不良習慣帶入了他們的職業(yè)生涯,并帶來了災難性的后果 。

文章插圖
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.復雜的代碼不僅需要花費更多的時間來設計和編寫代碼,而且更容易出錯和出現(xiàn)錯誤 。迷宮般的代碼會使 Web應用程序監(jiān)視 變得 乏味 。當心功能蔓延,在這里您開始向客戶不需要的程序添加新功能,因為這只會不必要地糾纏軟件 。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.重復最少是質(zhì)量代碼的標志 。避免重復邏輯和數(shù)據(jù) 。要知道您的程序是否重復過多,請考慮如果您想改變應用程序行為的一個方面,需要修改多少代碼 。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.為了最大程度地減少重復,請確定執(zhí)行相同操作的所有代碼段 。在需要執(zhí)行上述任務時,將這些通用代碼塊抽象為一個函數(shù) 。這樣,如果您需要更改任務的執(zhí)行方式,則只需要修改一個函數(shù),而不是在整個程序中修改多行代碼即可 。3.現(xiàn)在而不是將來的代碼 (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.編程的明智原則之一是為將來的代碼更改做好準備 。對于不參與項目的第三方來說,遵循邏輯并根據(jù)需要添加或刪除功能應該很容易 。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.但是,為將來的維護做準備與將來可能需要的功能編碼不同 。后者只會增加代碼量,同時 為錯誤 創(chuàng)建新的 途徑 。無論如何,將來通常根本不需要這種功能 。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.現(xiàn)在進行編碼可防止范圍蔓延 。除非最終用戶明確要求從一開始就包含此功能,否則請遠離它 。4.不要過早優(yōu)化 (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.當您注冊基礎編程課程時,重點領域之一就是需要創(chuàng)建快速高效的算法 。一些編碼人員犯的錯誤是在學習這一課時 。他們?nèi)褙炞⒂趶囊婚_始就試圖加快代碼的速度并優(yōu)化代碼,同時又忽略了創(chuàng)建功能正常的程序的主要目標 。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.首先要滿足系統(tǒng)要求,然后繼續(xù)進行代碼優(yōu)化 。太早進行優(yōu)化類似于在黑暗中摸索 。在程序啟動并運行之前,您無法真正確定瓶頸將在何處 。您可能會浪費寶貴的時間來優(yōu)化功能,而該功能的速度對整體程序性能的影響并不大 。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.聰明的代碼是編程,而不是創(chuàng)建易于理解的代碼,而更多的是向所有人展示您的聰明程度 。聰明代碼的典型示例是將過多的 程序邏輯 打包 到一行代碼中 。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.極少的代碼曾一度被認為是良好編程的標志,但隨著時間的流逝,業(yè)界已經(jīng)認識到,如果其他人很難遵循邏輯,那么簡短的代碼就毫無意義 ??赡苄枰渌绦騿T花費數(shù)十分鐘才能理解的任何代碼行,都應該刪除 。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.好的程序設計不僅與構建滿足最終用戶期望的應用程序有關,而且與創(chuàng)建易于理解的代碼有關 。遵循這些編程原則將確保您同時實現(xiàn)兩者 。程序員編程培訓(每個程序員都必須知道的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.由于免費在線教程的大量增加,幾乎任何人都可以學習編碼 。 一旦成為開發(fā)人員已有一段時間,您就會很快開始意識到并非所有代碼都是平等的 。編程論壇上充斥著恐怖的故事,詳細描述了巨大的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.盡管這些看上去像菜鳥般的錯誤,只是讓那些剛起步的人迷上了,但許多程序員卻將這些不良習慣帶入了他們的職業(yè)生涯,并帶來了災難性的后果 。
以上關于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關的問題,請您及時就醫(yī)或請專業(yè)人士給予相關指導!
「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對您有所幫助:- 如何成為更好的程序員 程序員編程培訓
- 各種長跑的小技巧
- 你還不知道如何辨別舒俱來真假嗎 舒俱來的功效與作用
- 終于知道為什么那么多人喜歡買舒俱來 舒俱來多少錢一克
- 舒俱來的收藏價值你知道嗎 舒俱來的價格是多少錢一克
- 《誰都知道我愛你》原著小說是什么 《誰都知道我愛你》講的是什么故事
- 聽完才知道我不懂淘寶石 紫龍晶與舒俱來有什么區(qū)別
- 兒童票必須使用兒童身份證嗎 兒童票火車票怎么買票
- 你知道什么是有氧運動嗎
- 俯臥撐架在運動時有用嗎?
