Ask HN: Why do the majority of JS developers prefer spaces over tabs?
[1] http://sideeffect.kr/popularconvention/#javascript
[1] http://sideeffect.kr/popularconvention/#javascript
im_a_long_method(argument_no_1,
set_indentation_true(...),
no_string_cutoff,
whatever)
Now suppose I used tabs to indent and my editors tab width is 4 spaces while your is 8 spaces, then the above would look like: im_a_long_method(argument_no_1,
set_indentation_true(...),
no_string_cutoff,
whatever)
Since not every editor agrees on how wide a tab character is, you get crappy alignments. Therefore use spaces.Then it'll look wrong in a proportional font; indenting and aligning with non-indented text are different things. Either spaces or tabs indent consistently when used consistently in a source file. Alignment cannot be acheived consistently (with spaces or tabs) unless you also assume a monospaced font, or (with tabs) have elastic tabstops.
Yes, the desire to use alignment without something like elastic tabstops being widespread is the limitation which prevents wide adoption of otherwise-superior proportional fonts in coding.
I remember using the tab key to enter tabs back in school to make something like an informal, 2-or3-column table (or whatever I was actually doing). This would have been in Word. Things would line up pretty until I wanted to change some text. If I made it longer I would need to add another tab because the tab had shrunk to nothing. If I made it shorter the tab would jump into the previous section and no longer line up with the other lines.
As far as I can see, the same will happen with this source example if it were using tabs and a proportional font.
Programmers don't use proportional fonts. Source code maintenance is hard enough without asking for trouble.
Many people decided to standardize various things (like the use of spaces for indentation) to compensate for this.
These days not a huge deal.
Optimizing for size in the primary format for editing isn't that important. For deployment, sure, but you're going to minify for that anyway, right? So spaces vs. tabs makes no difference for that.
var abc = something,
xyz = somethingElse,
stringOfAbc = abc.toString();
the variable names are neatly aligned on the left side!Because, with a fixed-pitch font such as is used in programming, the meaning of a space is unambiguous (unlike tabs). Also, having two indistinguishable whitespace characters is bad, and mixing them in a single file is worse. So one chooses the least problematic of the two.
I think making the implicit explicit is also a belief of most logical devs outside of the Python community.
Seems like a strong argument for sticking with strongly typed languages.
Dynamic typing and weak typing are not the same thing.
Python:
>>>1 + "1"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
PHP: >1 + "1"
2So yeah, I would prefer explicit (brackets) over just implicit (spaces), in python.
Perl and Ruby aren't Python.