
Programming Styles in the Node Community - tbassetto
http://dailyjs.com/2012/01/12/style/
======
mathrawka
I was hoping for a more in depth article, not something that squabbles over
commas, semi-colons and indent space counts.

I wanted to see more about how programs/modules are organized Yes, they
mention how TJ puts an index.js so he can require everything in one line, but
that was just a footnote it felt like.

------
lalc
Was hoping for something less bikeshed-y. What about, say, adherence to all-
streaming APIs? What granularity of stream fragment? At what complexity do
they switch from callbacks to EventEmitters? Keeping view partials ordered?

------
insraq
When I program in PHP, I always use four spaces (converted by a tab), which is
suggested by PEAR coding standard. Python mandates indentation. Four spaces is
highly recommended. One tab is accepted but discouraged.

------
Plog
You can find here (<http://nodeguide.com/style.html>) another style guide
written by Felix Geisendörfer, an early node.js core contributor.

Personally, I think that the more important is that your all team has the same
coding style and to be capable to adapt to another coding style when necessary
and when you change of language.

Generally it's better when your coding style looks like the one of the
language creator.

------
nestlequ1k
Easy solution. Just use coffeescript. Nice and clean, and you'll never have to
see anyone, anywhere put comma's before lines.

Win win :)

~~~
gcp
The canonical indentation for CoffeeScript is 2 spaces. In a language that
relies on indentation to define blocks...that's... _insane_.

I can attest firsthand this causes bugs. 2 spaces just isn't enough to
reliably visually identify the horizontal separation.

Python got this right with PEP 8. CoffeeScript did not and is worse for it.

~~~
nene
I've been switching between 2 and 4 spaces through my whole programming
career. Even now I'm switching daily between different languages and projects
with different amount of indentation. And I for one have noticed no
correlation between bugs and amount of indentation. But I might be wrong - I
have done no actual measurements.

What I can say though, is that there is a correlation between a lousily
indented code and bugs. Consistency is the key in indentation. Reading non-
consistently indented code, that's what drives you insane... but two instead
of four spaces... hardly.

~~~
gcp
This isn't about 2 spaces vs 4 spaces. It's about 2 spaces in a language where
blocks are defined only by indentation. That's a HUGE difference.

I have no problem with 2 spaces in C/C++. I have no problems with Pythons use
of white-space to define blocks. But the combination is deadly.

------
richthegeek
Drupal insists on 2 spaces.. but that really doesn't give enough indication of
depth to me so I use either 4 spaces or a tab character.

------
dionidium
I am torn between following the coding conventions that prevail in a
particular community (a generally reasonable thing to do) and (as a long-time
JavaScript user) disliking nearly every new JS convention the node developers
have settled on.

~~~
tomjen3
No offense but that isn't their fault -- it is simply because Javascript is a
bad language.

No convention can solve things like var hoisting, this changing meaning in
callbacks, etc, etc. So people come up with some really strange coding styles
to try to route around them -- which good programmers will hate, even if they
are not entirely sure why.

------
mise
Indenting by two spaces is new to me. As a PHP programmer, an inserted tab
(not converted to spaces) is the length of four spaces.

Is the two-space indentation relatively new? Or has it always been seen around
in the JS community?

~~~
dspillett
I've always been a four-spaces man, even in Javascript, and that seems quite
common.

Javascript uses in an event driven environment (like a browser of node.js) can
encourage some pretty deep nesting so perhaps people use smaller indentation
granularity for that reason.

------
jroseattle
I noticed all the comments around the code are setup for YUIDoc. Is YUIDoc the
standard in JS nowadays? I'm not familiar with alternatives otherwise.

