Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't consider myself a huge code style pusher but when I see two space indentation I have to really ask... seriously... why???!!!

Its funny to me because the languages where you get massive nesting you almost want greater indentation as it gets extremely confusing as to what scope you are in.

While I prefer either 4 spaces or tabs (obviously not mixed) I'm not completely revolted with 2 spaces in Algo languages like Java, C or Go (although I suppose Go you have no choice) because you just don't have much nesting.

But Scala and Javascript.... wholly crap is there a lot of nesting. Please for god sakes if you absolutely need that much indenting either refactor or give into the glorious evil that is TAB.

In all serious there is an accessibility thing with 2 spaces. You are hindering people with bad eye sight. I just don't have the visual acuity anymore to discern two spaces easily and I imagine there are many more. It is sort of like building a building and making the stairs extremely steep because you don't like taking lots of steps with your long legs.



It's because when you use 4 spaces, the lines just become too long. I use 4 spaces in C and 2 in javascript and that makes sense visually for me.


If your lines are too long with 4 spaces, then you either have a tiny screen, or aren't line-breaking when you should be. Or you're in callback hell...


yeah tiny screen, does that make me a bad programmer?


Well, better programmers can afford larger screens :-)


Let me guess... It is hard for you to read long lines or your monitor isn't big enough? You might call that an accessibility thing right? You get what I'm getting at. You traded one accessibility that is fairly easy to fix (at worse case you have line wrapping) for one that is almost impossible to fix (zooming and large font don't really help).


Reading long lines is also difficult.

To me some parts of FE development kind of require deep nesting, e.g. css, but in javascript if you are 4/5 levels deep in the nest (with the "long lines symptom"), then you should do as proposed in the article: split into modules and functions.

And sometimes (often?) long lines comes from the bad habit to do 3/4 things in one statement. To me good code does exactly one thing per statement, and except for config or urls, is should not be long.


Yes but like I said before long lines is an extremely easy thing to fix in most PLs (ignoring config of course). You can refactor code so that the line is not as long but you can't refactor indention spacing.


It's hard for me to read long lines.

I don't think 4 spaces makes it easier to know in what scope I'm in when there are a lot of scopes. The amount of white space is a bit overwhelming to me.

But you know, it's no big deal, just a matter of taste. Maybe 3 spaces is a better answer, which I guess we'll never know...


How long of a line are we talking here? Most coding standards are 80-120 with maybe some at 140.

If you are say 4 levels deep the additional characters used over 2 spaces is 8 characters. You got whopping 8 additional characters to make an even longer line of code (code to be interpreted or read) and screwed over the people who need the indenting.

If long lines are a problem than just refactor. I agree long lines are hard to read but there is a simple fix. Either refactor or just put in a line feed (or however the PL deal with long lines aka \ for bash or python).


  > Maybe 3 spaces is a better answer
No, tabs is the answer.


Does your code look like the code in the example? With the useless else clauses? And without sensible extraction of standalone functions?


I'm a tab heretic for this reason -- every user can adjust their editor to show tabs with whatever width they like.


I used to feel the same way. Any confusion goes away after you get used to it. Used 4 spaces for ~14 years, used 2 spaces now for 3 years. Now feel the same way about 4 as I once felt about 2 spaces.


I started using two spaces because it was the default with C on emacs. I took a liking to it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: