Ask HN: Why do the majority of JS developers prefer spaces over tabs?
I know this is a hotly debated topic, but I have to ask. Why is it that specifically for Javascript, 4 in 5 developers prefer to use spaces instead of tabs[1]? I've decided to switch from using tabs to 2 spaces because I'd rather convenience other developers than burden them, but I still don't understand the reason. Tabs take up less space in terms of bytes, and are dynamic width allowing the user to set the width to their personal preference. Sounds like a perfect solution to developers agreeing on a specific number of times to hit the space key. So why are spaces so popular?
[1] http://sideeffect.kr/popularconvention/#javascript
24 comments
[ 3.1 ms ] story [ 60.8 ms ] threadI 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:
PHP:So yeah, I would prefer explicit (brackets) over just implicit (spaces), in python.
Perl and Ruby aren't Python.
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.
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.
Many people decided to standardize various things (like the use of spaces for indentation) to compensate for this.
These days not a huge deal.
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.
var abc = something,
the variable names are neatly aligned on the left side!