Hacker News new | past | comments | ask | show | jobs | submit login

You mean something like this don't you?

  [tab]void some nice method(int param a,
  [tab]                      int param b
So long as you only use tabs for indentation, not alignment, tabs look correct on _everyone's_ machine. The real problem with tabs is that (some) people are lazy and do stuff like this:

  [tab]void some nice method(int param a,
  [tab][tab][tab][space][space]int param b
Personally, I think if you work like that you need to learn to be professional and write code that follows whatever coding standard your organization uses. If they use tabs, the second example is _not_ following the coding standard.

So whether to prefer tabs or spaces, to me, depends entirely on how much you can/want to trust your coworkers to follow the coding standards.

Edit:

Or as pointed out below, change your coding style to this:

  [tab]void some nice method(
  [tab][tab]int param a,
  [tab][tab]int param b



No I think grand parent comment means that some developers sometimes add spaces instead of tabs, even if it is by mistake. That will mix everything up.

"Could" happen the other way too, but I think: If you use spaces you typically dont repeatedly hit space to produce a single indent. You use tab which gets translated to spaces. Once the editor is set up for this, you don't accidently insert tabs for indentation.


Wait ... you're saying that you should do a tab, and then a whole bunch of spaces?

What actual benefit does tabbing even get you at that point?


Respecting indent preferences of others while not breaking the formatting of that line-split function call.


This whole post would be so much more productive if "Tabs for indentation, spaces for alignment." was defined upfront for everyone to debate.


Formatting


The Linux codebase uses tabs, and presumably they have this rule about using spaces for alignment. I've seen tons of committed code that doesn't follow this rule, though, and hence Linux source looks like shit on anything besides 8 tab-width.


While this is true they will look correct on everyone's machine, they'll be annoyingly wide in tools that display tabs as 8 spaces (such as less, most online diff displays, etc). But spaces will look the same regardless of tool, editor, anything.


I don't know what online diff do you use, but less let you configure the tab stop with the -x option, which is the point of using tabs: being able to chose what's more readable for you.


The point of using spaces is to not worry about any of this. You need a specific fix for less, another specific fix for other diff tools, etc etc. With spaces, everything just works.


I don't see it as a "fix" but as a configuration. And tabs also just works, if you accept the defaults that are given to you :) but if you don't, then you can change your settings (which is trivial). With spaces you have no option but accept whatever is given to you.


Something tells me we'll just go back and forth on this. Should we discuss something else? Perhaps vim versus emacs? Windows versus Linux? :)


The only reason 2, 4 or 8 is less "readable" to anyone is because they have a mental breakdown when they see a style they don't prefer and can't get past it. Tab is a variable width character, it has no place in text laid out with fixed-width fonts.


Is having a style preference bad? One can freely configure color scheme and font, so why should indentation be restricted?


Those options are unambiguous and never require changes to a plain text file to work. I'm pretty sure it was Ayn Rand who said "A is A, but God only knows what Tab is." It's not always used for indentation, it might be for alignment, even if it's at the beginning of a line. There's no way to make any sane programmatic decisions base on it's presence. It does not belong in the digital world!


Some typefaces have spaces as narrow as 1/5em. Many are around 1/4em.

Spaces in a fixed width typeface will be up to about 5 times as wide as in some proportional width ones.


This is like an "eternal September" - when tabs vs spaces comes up each year, most commenters have never seen one of the rather simple ways of using tabs correctly.




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

Search: