今日推薦開源項目:《免費學習社區 freeCodeCamp》
今日推薦英文原文:《Tabs vs. Spaces》
今日推薦開源項目:《免費學習社區 freeCodeCamp》傳送門:GitHub鏈接
推薦理由:freecodecamp.org是一個免費學習編程的社區網站,課程完全免費並且自主安排。網站有數以千計的互動式編碼練習,以幫助您擴展您的技能。
今日推薦英文原文:《Tabs vs. Spaces》作者:Kenneth Reilly
原文鏈接:https://medium.com/@kennethreilly/tabs-vs-spaces-3c24defa7c9e
推薦理由:關於是使用Tab鍵還是使用空格鍵縮進的爭論在編程界已經持續了多年,不過Tabs可能是更好的選擇,是因為空格需要多按幾下嗎?
Tabs vs. Spaces
A scientific approach to an endless debate
Introduction
The debate over whether to use atab
or a space
for indention has been long-running for many years in the programming community.I use tabs for indentation myself, originally because that was what our senior developers used at my first software job, and to this very day for various reasons, most of which are logical and mathematical in nature. In this article, I will outline these reasons and shed light on this topic.
Code Indentation
We indent source code to make it more readable for humans, and for no other reason. This is fundamentally no different than indenting a list on a page in an old-school textbook or other document, for which the tab key was developed and included in every major typewriter design in history.The
spacebar
key, on the other hand, was not developed for the purpose of indenting content on a page, but for separating words in a sentence. So, when we inspect the tab
versus the space
when it comes to typing content in a readable fashion, the tab
wins by virtue of having been designed for the specific purpose of indenting text in order to make it more readable.So now that we have examined the true purpose behind each character and reached the conclusion that the
tab
exists for the sole purpose of indenting content while the space
does not, let』s examine the efficiency of using each.Efficiency
There is an unspoken concept among many senior developers who grew up in the 80』s and 90』s with limited tech resources, that many programmers today have a bad habit of taking for granted the kind of power and bandwidth that are available to the modern software developer. While it』s a good thing that we have the kind of resources we have today on modern client, server, and networking machines, it』s still a bad habit to assume that raw power will make up for a lack of efficiency on the part of the developer.While the machine doesn』t actually care if you use tabs or spaces (unless you』re using Python or something similar in which whitespace is part of the syntax), the size of your source code will increase by the use of spaces over tabs, especially if you indent by four spaces. If you are five levels deep in a nested function and you』re indenting an expression like
String str = ''
with 20 spaces, that line of source code contains more indentation characters than it does code, which is truly absurd by any standard. Multiply that by hundreds (or thousands) of files, with hundreds of lines of code each, and you』re going to have MBs upon MBs of spaces everywhere.Conclusion
So, at the end of the day, tabs versus spaces is truly a matter of preference, however the tab is still the character specifically designed for indentation, and using one tab character per indentation level instead of 2 or 4 spaces will use less disk space / memory / compiler resources and the like. It』s also arguable that full tab indentation produces more readable code, and will encourage a developer to utilize proper abstraction, encapsulation, and other practices, since not doing so will result in highly nested logic with indentation going off the screen (something that isn』t as much of an issue when indenting with two spaces).How you see your code every day has a huge impact on the kind of success you will have long-term as a developer, and clean logic is much easier to read and requires fewer mental resources (meaning more can be put into the actual work you』re doing instead of in maintaining hard-to-read code).
下載開源日報APP:https://openingsource.org/2579/
加入我們:https://openingsource.org/about/join/
關注我們:https://openingsource.org/about/love/