Hello,
I read somewhere that good-style Ruby code is indented by 2 spaces. I’d
like
to tell you my problem: I’m not disabled, but I have problems with
reading
code if the indentation is only at 2 spaces. I must indent more. It’s
all
about my dysfunction of reading.
The main argument for using spaces is that the code looks everywhere
same.
But - who needs it? From my point of view, I don’t care if the code
looks
same on my and on my friend’s computer.
Of course, I expect the code to look same on my computer. There is a
problem:
Unfortunately GNU/TAB is set to 8 characters and if you display code on
terminal, for example using diff or grep, it’s not well readable and may
look
different than in your editor. So it breaks what I wrote above about
same-looking code within one computer. I don’t know if there is any
solution
for this case or if TAB length is hardcoded in Linux/BSD kernel.
from Linux coding style:
“In short, 8-char indents make things easier to read, and have the added
benefit of warning you when you’re nesting your functions too deep.
Heed that warning.”
On the other hand, terminal vs. editor difference is not fatal. I still
can
better read more-indented code than less-idented code. I use vim-diff
and
when I grep something, the grep output usually looks like a big mess and
I
really don’t care about indentation Moreover, I spend much more time
programming than grepping, and that’s why…
That’s why I prefer TABs. The main purpose of TABs is - to indent. I
don’t
think it is archaic. Almost all good editors are able to set indentation
today, so everyone can set indent him/herself at pleasure. The code will
still look consistent on other’s computer even if different indentation
is
used there. If you indent using spaces, you can’t set it alternatively
(if
you don’t want to do recoding, which is bad idea).
There always be people who will need more indents because of their worse
recognition capability and they can do it thanks to TABs.
(Another con of TABs is editing code in editors which aren’t able to set
indenation (notepad). But. Do you usually use notepad for programming?
(Hmm.
(…))
Of course, when I use TABs, I have to follow this rule: Don’t use TABs
elsewhere just before first non-space character on a line. It means
don’t mix
TABs with spaces. If I format code to “table”, use spaces.
FINAL QUESTIONS:
-
Should there be the only one coding style in Ruby? I would prefer
this,
but… -
Do you think everyone would accept it? No, one group would accept
TAB-style, another group would accept space-style. Maybe there could be
two
styles for each group. -
Would all people accept one of those two styles? I don’t think so.
-
So should Ruby interpreter allow only those two styles? I don’t think
so. -
Is there any solution for TABs vs. spaces? No, I don’t think so
-
Is this “war” 50:50? Or is it finished? Or… Any ideas?
Thank you for any answer on questions above and/or solution for the
terminal
TAB length problem, which is the only real con of TABs for me.
Jan