From: Ben Finney on
Tim Streater <timstreater(a)waitrose.com> writes:

> Trouble with tabs is, what is a tab?

<URL:http://www.jwz.org/doc/tabs-vs-spaces.html>
<URL:http://c2.com/cgi/wiki?TabsVersusSpaces>
<URL:http://www.codinghorror.com/blog/archives/001254.html>

--
\ “The greater the artist, the greater the doubt; perfect |
`\ confidence is granted to the less talented as a consolation |
_o__) prize.” —Robert Hughes |
Ben Finney
From: James Harris on
On 27 Feb, 05:36, Kelsey Bjarnason <kbjarna...(a)gmail.com> wrote:
> On Fri, 26 Feb 2010 11:28:19 -0800, Keith Thompson wrote:
> > Richard Heathfield <r...(a)see.sig.invalid> writes:
> >> Tim Streater wrote:
> >> <snip>
>
> >>> Trouble with tabs is, what is a tab?
>
> >> A quick way of inserting exactly two spaces into the source.
>
> > The One True Tabstop Width is 8.
>
> Three, actually.  Okay, 8, if you're stuck using output devices from the
> 1960's which didn't allow user-defined tab spaces, but for how many
> people is this true anymore?

Windows Notepad users are stuck with 8. Windows Wordpad users seem to
be stuck with 6. These are not earlier than the 1980s.

Come to think of it, apart from those two programs what do Windows
users use to enter and edit source code?

I don't think I ever use tabs when typing a high level language. I
always use spaces - just two per indent. Then there are no portability
problems, except for the line ends, of course, and they can be ignored
or dealt with.

IMHO embedded tabs in source code should be consigned to the wastebin
of history as just one of those non-printable characters we used to
hate. Why? Well, they generate a different result depending on where
they are placed and *look like* something else - i.e. one or more
spaces. They are, to an extent, hidden.

Older ones among us may remember dealing with invisible control
characters. For example, moving the cursor across a line one character
at a time looking for where it didn't move. That showed where the
invisible character was embedded. Not fun.

James
From: James Harris on
On 27 Feb, 05:19, William Ahern <will...(a)wilbur.25thandClement.com>
wrote:
> In comp.lang.c Ike Naar <i...(a)localhost.claranet.nl> wrote:
> <snip>
>
> > Consider the case where a condition does not fit on a single line:
>
> >     if (sscanf(input_buffer, "%d %d %d", &length, &width, &height) == 3 &&
> >         sscanf(other_buffer, "%d %d %d", &color, &price, &weight) == 3 &&
> >         needs_processing(color)) {
> >         compute_volume(length, width, height);
> >         compute_something_else(price, weight);
> >     }
>
> I agree that that's a sore spot. But in complex conditions I often like to
> align the logical operators w/ the if statement.
>
>     if (sscanf(input_buffer, "%d %d %d", &length, &width, &height) == 3
>     &&  sscanf(other_buffer, "%d %d %d", &color, &price, &weight) == 3
>     &&  needs_processing(color)) {
>         compute_volume(length, width, height);
>         compute_something_else(price, weight);
>     }
>
> Along with 8 space aligned indentation, it's not that bad.

Or, because the condition should be made clear how about setting it
off as follows.

if (
sscanf(input_buffer, "%d %d %d", &length, &width, &height) == 3 &&
sscanf(other_buffer, "%d %d %d", &color, &price, &weight) == 3 &&
needs_processing(color)
) {
compute_volume(length, width, height);
compute_something_else(price, weight);
}

I generally indent continuation lines half as much as the indent for a
block of code. In this case there are four spaces prior to the guarded
block of code and hence two spaces prior to each of the continuation
lines.

I can't recall seeing a recommendation for continuation lines
anywhere. I've just used this from my early programming days. It's
clear and consistent but I expect there are better schemes I've never
come across.

James
From: James Harris on
On 25 Feb, 17:03, Poster Matt <postermatt(a)no_spam_for_me.org> wrote:
> Eric Sosman wrote:
>
> >     Contradict each other, of course!  Why did you ask?
>
> Given the amount of contradictory advise I'm getting in this
> thread I am beginning to wonder why myself. :)

I know you wrote this with a smiley and you are right there's been a
lot of differing advice but just as general observations:

1. the differences of opinion have been informative in their own right
and also served to highlight what preferences there are, and
2. some areas of consensus have come up.

All-in-all a useful discussion. Someone even managed to insert a word
none of us had ever heard of, bedizenry. (I think it was this thread.)
When I checked even Google only showed nine web hits and that's
including duplicates. Nice one, whoever that was. :-)


James
From: Keith Thompson on
Stephen Sprunk <stephen(a)sprunk.org> writes:
> On 26 Feb 2010 09:12, Tim Streater wrote:
>> On 26/02/2010 14:51, Richard Heathfield wrote:
>>> Tim Streater wrote:
>>>> Trouble with tabs is, what is a tab?
>>>
>>> A quick way of inserting exactly two spaces into the source.
>>
>> Since I don't know what tab setting you had when you handed me the code,
>> I think s/exactly two/a random number of/ applies here.
>
> That's a problem with _mixing tabs and spaces_, which is Evil(tm).
>
> If you use a tab character (inserted by pressing the tab key) for each
> level of indentation, each programmer can set the tab stops in his
> editor however he wants and it will look correct for everyone.

Only if everyone who ever modifies the code consistently uses tabs,
and only tabs, for indentation.

I really don't want to have to set the tabstops in my editor (and
in every other piece of software and/or hardware I might use to
look at the code, either on my own screen or on someone else's)
to the appropriate value for the particular file I'm looking at to
make it legible.

I might commonly examine a source file using any of vim, emacs, less,
cat (if it's very short), or one or more Windows-specific editors, or
I might print it, probably after using enscript to generate Postscript
output. I'm also likely to use diff, among other things, to process
the source file as input. I know how to set the tabstop width for
some of those, but certainly not all of them.

> (That introduces a new problem if you want to limit to 80 columns, but
> that can be remedied by saying "80 columns with X-character tabs".)

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
First  |  Prev  |  Next  |  Last
Pages: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Prev: integer
Next: shared memory question