0

私は慣例で 4 つの空白タブを使用する PHP から来ています。多くの例 (およびプロジェクトのブートストラップ コード) で、2 つのスペースが使用されていることに気付きました。これらのプロジェクトのスペーシングについて言及している決定的なスタイル ガイドを見つけることができなかったので、これが実際に慣例であるかどうか疑問に思っています。

4

2 に答える 2

4

Let me start by saying - according to the requirements of the language (Javascript) the 2 spaces are NOT REQUIRED (infact most of the times you can get away without using a ; too at the end). However if you mean to ask whether people use it ? Then here is the answer :

For Node - it starts from here so the creator of Node (and also maintainer and BDFL) !! (Ryan-Dahl aka the "benevolent dictator") insisted on using the 2 spaces . Ofcourse he is the creator so everybody has a tendency to follow.

Tabs vs Spaces

Let's start with the religious problems first. Our benevolent dictator has chosen 2 space indention for the node core, so you would do well to follow his choice.

Then comes TJ Holowaychuk author of Express, Jade, Stylus, and Mocha quoted from here

has an extremely consistent style. TJ uses two spaces for indentation, semicolons to end lines, and formats commas at the start of a new line:

Then there is Isaac Z. Schlueter,author of npm !!

Even on the Jade reference page ... all the code more or less has 2 spaces.

So it is a better thing to adopt the practice and it is almost in all major projects of Node/Express/Jade.

But IMHO who cares as long as you are confident that your code is correct. Maybe one day you will write better and elegant code and become the "benevolent dictator" ;-).

Hope that answers the question :)

于 2013-08-11T06:13:31.550 に答える