[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using TABs vs. spaces II. (the Philosophy flamewar reloaded ;-

MiG

7/12/2007 2:35:00 PM

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:

1. Should there be the only one coding style in Ruby? I would prefer this,
but...

2. 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.

3. Would all people accept one of those two styles? I don't think so.

4. So should Ruby interpreter allow only those two styles? I don't think so.

5. Is there any solution for TABs vs. spaces? No, I don't think so ;-)

6. 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


10 Answers

Warren Brown

7/12/2007 2:49:00 PM

0

Jan,

> 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.

This is the fatal flaw of using TABs. There will inevitably be
cases where they get mixed, and as soon as that happens, the TABs are
*required* to be the length that that person chose, or the code does not
indent properly.

> 5. Is there any solution for TABs vs. spaces?

Yes. "unexpand -2" is your friend. Just remember to "expand -2"
when you're done.

I hope this helps.

- Warren Brown


Stefan Rusterholz

7/12/2007 2:53:00 PM

0

Hi Jan Molič

I don't think there's really a solution to that problem as it is about
personal preferences. However, there are plenty of tools like
expand/unexpand to or even built into your editor to change code to your
liking.
That said, my preference is to use tabs for indention and space for
alignement. That way everybody can set the width of a tab as he likes it
and the code still looks fine.

Regards
Stefan

--
Posted via http://www.ruby-....

SonOfLilit

7/12/2007 2:55:00 PM

0

Hello, Jan,

Since you can't see the difference, reinforcing use of only tabs when
using tabs is really hard - you sometimes miss a space.

That's why I prefer spaces, and I think it's the ruby community
attitude for the same reason. (My other reason is that I like ASCII to
be 100% content with no "markup" or "metadata", and tabs are
metadata).

For those who must change the setting, their editors probably support
creating a macro that converts the files to tab on load and back to
spaces (with a 2sp setting) on save. It's pretty easy in emacs.

For your commandlne problem, why don't you create a script that
translates a tab into X spaces, call it some short name (like 'tb')
and pipe your code through it? So `grep sort * | tb` and you see what
you want.

Aur

Chad Perrin

7/12/2007 9:10:00 PM

0

On Thu, Jul 12, 2007 at 11:34:55PM +0900, Jan Moli?? wrote:
>
> 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.

That's the argument for using two spaces all the time rather than
sometimes using three or four spaces, and for choosing to stick with just
spaces or just tabs rather than switching between the two. It's not
specifically an argument for spaces over tabs.

There are arguments for spaces instead of tabs, but that's not really one
of them.


>
> 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.

You can alter tab length in your editor (for at least most editors,
including vi/Vim and Emacs).


>
> 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."

Using two spaces per indent also warns when functions are nested too
deeply. It requires twice as many keystrokes per indent as using tabs,
which means you'll get tired of keystrokes for indentation twice as
quickly. It works as a reminder for me, anyway.


>
> 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.

As mentioned in another response or two to your email, you can use the
expand and unexpand utilities to switch between spaces and tabs in your
source code files. I would recommend coding in tabs if you must, and
using the expand and unexpand utilities to change code formatting as
needed so that whenever you share code (such as on this list) you present
it in two-space indentation style.


>
> (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.
> (...))

Parse error: mismatched parentheses.


>
> 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:
>
> 1. Should there be the only one coding style in Ruby? I would prefer this,
> but...
>
> 2. 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.
>
> 3. Would all people accept one of those two styles? I don't think so.
>
> 4. So should Ruby interpreter allow only those two styles? I don't think so.

Last I checked, leading whitespace is not syntactically significant, and
I'd like to keep it that way. If I wanted significant whitespace, I'd
use Python.


>
> 5. Is there any solution for TABs vs. spaces? No, I don't think so ;-)

See above, re expand/unexpand.


>
> 6. Is this "war" 50:50? Or is it finished? Or... Any ideas?

By far, the majority of programmers these days seem to prefer spaces over
tabs. There are certain communities that run strongly the other way,
still, but I think they will continue to be increasingly outnumbered at
least until there's a substantial shift in where things are headed in
that regard.


>
>
> 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.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
John Kenneth Galbraith: "If all else fails, immortality can always be
assured through spectacular error."

Philip Hallstrom

7/12/2007 9:31:00 PM

0

Gregory Brown

7/12/2007 9:53:00 PM

0

On 7/12/07, Chad Perrin <perrin@apotheon.com> wrote:

> Using two spaces per indent also warns when functions are nested too
> deeply. It requires twice as many keystrokes per indent as using tabs,
> which means you'll get tired of keystrokes for indentation twice as
> quickly. It works as a reminder for me, anyway.

I actually turn on expandtab, so that I can use the tab key still and
keep my spacebar from falling off. :)

John Joyce

7/12/2007 10:53:00 PM

0


On Jul 12, 2007, at 4:52 PM, Gregory Brown wrote:

> On 7/12/07, Chad Perrin <perrin@apotheon.com> wrote:
>
>> Using two spaces per indent also warns when functions are nested too
>> deeply. It requires twice as many keystrokes per indent as using
>> tabs,
>> which means you'll get tired of keystrokes for indentation twice as
>> quickly. It works as a reminder for me, anyway.
>
> I actually turn on expandtab, so that I can use the tab key still and
> keep my spacebar from falling off. :)
>
Tabs/Spaces? is an age old debate as unimportant as where to put
opening/closing braces/brackets/parentheses in other languages.
This is less interesting than the god debate the other day.

Gregory Brown

7/12/2007 10:59:00 PM

0

On 7/12/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
>
> On Jul 12, 2007, at 4:52 PM, Gregory Brown wrote:
>
> > On 7/12/07, Chad Perrin <perrin@apotheon.com> wrote:
> >
> >> Using two spaces per indent also warns when functions are nested too
> >> deeply. It requires twice as many keystrokes per indent as using
> >> tabs,
> >> which means you'll get tired of keystrokes for indentation twice as
> >> quickly. It works as a reminder for me, anyway.
> >
> > I actually turn on expandtab, so that I can use the tab key still and
> > keep my spacebar from falling off. :)
> >
> Tabs/Spaces? is an age old debate as unimportant as where to put
> opening/closing braces/brackets/parentheses in other languages.
> This is less interesting than the god debate the other day.

Of course, it's only important if you want to work on (almost) any
open source Ruby project.

Mike Kasick

7/13/2007 6:14:00 PM

0

On Thu, Jul 12, 2007 at 11:34:55PM +0900, Jan Moli?? wrote:

> 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.

I have similar vision issues. It takes me a while to parse two space
indentation in passages where the indentation isn't obvious from context.
Four spaces isn't so bad, and I can fly through eight spaces.

> 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.

Sometimes I prefer for code not to look the same. If I'm on a terminal
with larger text area but a smaller font, I need larger indentation but
have the column space to sacrifice. If I'm on an 80 column terminal, eight
space indentation results in line wraps, and since the font is bigger I
have less trouble parsing 2-4 space tabs.

> FINAL QUESTIONS:
>
> 1. Should there be the only one coding style in Ruby? I would prefer this,
> but...

It's best to have a consistent coding style across a single project. With
free software, it also helps to have a consistent coding style across a
language since folks inevitably cherry pick code from multiple projects.

That said, I don't think you're going to see excessive complaints over
hard tabbed code as compared to other coding style deviations.

> 2. 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.

The real problem isn't whether folks would accept it, but rather would
folks acknowledge it.

Don't get me wrong, I'm with you here. In my own code I prefer to use hard
tabs. However, I rarely advocate their use outside of my own code these
days.

The problem, as others have mentioned, is that using hard tabs properly
requires a certain dedication to consistency. Most people don't have that
discipline and will add spaces willy-nilly to make things look right on
their screen. The end result is a tab/space combination that's broken for
everyone. That's worse than the alternative of spaces only.

> 5. Is there any solution for TABs vs. spaces? No, I don't think so ;-)

Yes, sadly it's spaces. Although I'd love for the world to accept tabs and
use them properly, the only way to avoid the problems that will inevitably
result is to go space only.

Daniel Berger

7/14/2007 12:18:00 PM

0



On Jul 12, 8:48 am, "Warren Brown" <warr...@aquire.com> wrote:
> Jan,
>
> > 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.
>
> This is the fatal flaw of using TABs. There will inevitably be
> cases where they get mixed...

<snip>

As anyone who's ever read the Ruby source code can attest. :/

Death to tabs!

Regards,

Dan, who will always use 3-space, er, tabs.