Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A stylistic question.

Reply
Thread Tools

A stylistic question.

 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-20-2006
James Dow Allen said:

> I *do* like being able to line up begins and ends easily, so if I was
> ever forced to work on code that used (gasp!) 2-space indentation
> I'd become an indent(1) fan *real* quick. (2-space indentation may
> look
> OK on little fragments, but am I the only one that ever puts more than
> 3 or 4 lines of code into the body of a for or if?)


I use two-space indent, and I have found that it works very well. History: I
used to use tabs (with 8-stops), but that got silly fast, and I converted
to 4-stops (but still tabs). But then I got into Usenet. Tabs being frowned
upon, I got into the 2-space indent habit for Usenet posts (because it was
so much quicker!), and found that I liked it so much I adopted it for
non-Usenet code too.

I have no problem matching braces (because I lay them out Allman-style, so
it's very obvious) - and anyway, vim can jump between { and } with a single
keystroke, so even if it weren't obvious it wouldn't matter that much.

But yes, you're right - indent(1) is our friend.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Chris Hills
Guest
Posts: n/a
 
      05-20-2006
In article <(E-Mail Removed) .com>, Bill
Pursell <(E-Mail Removed)> writes

>Is using tabs for indentation a decision I'll regret? Ask
>me in 12 months.


You will.

Why not set the editor to replace tabs with spaces?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ http://www.velocityreviews.com/forums/(E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      05-20-2006
Chris Hills wrote:
>
> In article <(E-Mail Removed) .com>,
> Bill
> Pursell <(E-Mail Removed)> writes
>
> >Is using tabs for indentation a decision I'll regret? Ask
> >me in 12 months.

>
> You will.
>
> Why not set the editor to replace tabs with spaces?


That's what *I* did.
It's more obviously the right way to go,
if you post a lot of code to Usenet.

--
pete
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-20-2006
"James Dow Allen" <(E-Mail Removed)> writes:
[...]
> My "normal indent" is one TAB character, and I'm amazed people
> mess around with spaces. It seems futile to try a TAB other than
> 8 spaces, though I admit 6 spaces would be slightly better.
> 4 spaces of indentation is almost too little for my taste.
> I *do* like being able to line up begins and ends easily, so if I was
> ever forced to work on code that used (gasp!) 2-space indentation
> I'd become an indent(1) fan *real* quick. (2-space indentation may
> look
> OK on little fragments, but am I the only one that ever puts more than
> 3 or 4 lines of code into the body of a for or if?)


It's important to distinguish between tabstops and indentation levels.
Too many people seem to think they have to be the same thing.

Tabstops, in my opinion, should be set at 8 columns, always. That's
the default setting on every system I've used. Setting it to
something other than 8 means that anything containing tabs will look
different in *some* context (printing, viewing with a different
editor, etc.).

My own preferred indentation level has changed over the years;
currently, I like 4 spaces. My preferred text editor, vi, has
separate settings for "tabstop" and "shiftwidth". I type ^T at the
beginning of a line to indent by one shiftwidth, and ^D to un-indent
by one shiftwidth. vi automatically converts indentation to a
sequence of tabs and spaces (for example, a 12-column indent becomes a
tab followed by four spaces); it's a feature I wish I could turn off,
but I live with it. (I think some versions of vi can turn this off;
nvi can't.) I've defined an editor macro that filters the buffer
through "expand", which expands all tabs to the right number of
spaces.

I have no doubt that emacs can do something similar.

For the most part, I don't "mess around with spaces"; I let my editor
take care of it for me. Computers are generally pretty good at that
kind of thing.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Bill Pursell
Guest
Posts: n/a
 
      05-20-2006

Chris Hills wrote:
> In article <(E-Mail Removed) .com>, Bill
> Pursell <(E-Mail Removed)> writes
>
> >Is using tabs for indentation a decision I'll regret? Ask
> >me in 12 months.

>
> You will.
>
> Why not set the editor to replace tabs with spaces?


Aesthetics. And being able to do a single backspace
to lower the indentation level. (It's easier than ^d).

About 2 years ago, I decided to not use tabs at all, except
in makefiles. A few weeks ago, I decided that 4 spaces for
indentation wasn't enough, and I wanted 8. Had I been
using tabs, I could now set my tabstop to 8, and all would
be well. Instead, every time I open a file, I have to filter
it to change the indentation. That's not a big deal, but
it's annoying. One of my thoughts is that since
I'm using a tabstop of 8, I'm far less likely to have any
problem with the tab/space issue. (Of course, that
may eliminate the point of using tabs, since I want the
flexibility of being able to change the tabstop.)

Everyone wants stable coding standards in a project,
but the reality is that it doesn't happen. I'm constantly
looking at code that is totally unreadable and that I have
to run through indent before I can even stand to look
at it. Maybe by imposing the rule that code be indented
with tabs and rejecting code that fails to conform will
help, maybe it won't. If I'm unable to enforce that rule,
I'm no worse off than I am now, and I'll have to filter
the code. But maybe I can catch those damn 2 space
indenters who use a tab for the 4th level of indentation...
those people are evil...

 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      05-20-2006
"Bill Pursell" <(E-Mail Removed)> writes:

> About 2 years ago, I decided to not use tabs at all, except
> in makefiles. A few weeks ago, I decided that 4 spaces for
> indentation wasn't enough, and I wanted 8. Had I been
> using tabs, I could now set my tabstop to 8, and all would
> be well.


Really? Do you not line up continuation lines after parentheses?
long_function_name (long_function_argument_1,
long_function_argument_2,
long_function_argument_3,
long_function_argument_4);

--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
 
Reply With Quote
 
Sjouke Burry
Guest
Posts: n/a
 
      05-20-2006
Ben Pfaff wrote:
> "Bill Pursell" <(E-Mail Removed)> writes:
>
>
>>About 2 years ago, I decided to not use tabs at all, except
>>in makefiles. A few weeks ago, I decided that 4 spaces for
>>indentation wasn't enough, and I wanted 8. Had I been
>>using tabs, I could now set my tabstop to 8, and all would
>>be well.

>
>
> Really? Do you not line up continuation lines after parentheses?
> long_function_name (long_function_argument_1,
> long_function_argument_2,
> long_function_argument_3,
> long_function_argument_4);
>

I do, and get something like thisi hope the tabs show)
long_function_name ( long_function_argument_1,
long_function_argument_2,
long_function_argument_3,
long_function_argument_4);
I like tabs, and i hate it when people(or editors)
start to change it to spaces,especially when they
return the code to me
 
Reply With Quote
 
Tomás
Guest
Posts: n/a
 
      05-21-2006
James Dow Allen posted:

> My "normal indent" is one TAB character, and I'm amazed people
> mess around with spaces.



Two things I do:

1) Write my programs in a fixed-width font (Courier New), and in plain
black text.

2) Hit the space bar four times when I want to indent.


Why?

Because if I become accustomed to fancy colours, and fancy automatic
indentation features, then I'll be lost if I'm ever found without them.
This happened to me in the past. When I first started reading code on
newsgroups, I simply couldn't read it because I was lost without syntax
highlighting and different colours for keywords, etc. So I decided to wean
myself off fancy features so that I could program with the bare
necessities.

Give me notepad with Courier New and I'm good to go.


-Tomás
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2006
Tomás wrote:
> James Dow Allen posted:
>
>
>>My "normal indent" is one TAB character, and I'm amazed people
>>mess around with spaces.

>
>
>
> Two things I do:
>
> 1) Write my programs in a fixed-width font (Courier New), and in plain
> black text.
>
> 2) Hit the space bar four times when I want to indent.
>
>
> Why?
>
> Because if I become accustomed to fancy colours, and fancy automatic
> indentation features, then I'll be lost if I'm ever found without them.
> This happened to me in the past. When I first started reading code on
> newsgroups, I simply couldn't read it because I was lost without syntax
> highlighting and different colours for keywords, etc. So I decided to wean
> myself off fancy features so that I could program with the bare
> necessities.
>
> Give me notepad with Courier New and I'm good to go.
>

What do you do when you refactor a bit of code and extract some indented
code into a function?

I don't know how this could be done easily without some form of auto indent.

--
Ian Collins.
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      05-21-2006
Sjouke Burry <(E-Mail Removed)> writes:

> Ben Pfaff wrote:
>> "Bill Pursell" <(E-Mail Removed)> writes:
>>
>>>About 2 years ago, I decided to not use tabs at all, except
>>>in makefiles. A few weeks ago, I decided that 4 spaces for
>>>indentation wasn't enough, and I wanted 8. Had I been
>>>using tabs, I could now set my tabstop to 8, and all would
>>>be well.

>> Really? Do you not line up continuation lines after parentheses?
>> long_function_name (long_function_argument_1,
>> long_function_argument_2,
>> long_function_argument_3,
>> long_function_argument_4);
>>

> I do, and get something like thisi hope the tabs show)
> long_function_name ( long_function_argument_1,
> long_function_argument_2,
> long_function_argument_3,
> long_function_argument_4);


Changing the tab width will still break the alignment of the
function arguments.
--
"...what folly I commit, I dedicate to you."
--William Shakespeare, _Troilus and Cressida_
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fujitsu Siemens Stylistic ST5022D Tablet PC. Gerhard Nerge Computer Support 1 09-25-2006 03:06 AM
Stylistic question about inheritance Andrew Koenig Python 17 04-01-2005 12:49 PM
Stylistic question -- initialization lists and vectors Denis Remezov C++ 4 04-30-2004 05:10 PM
stylistic use ofexplicit this. P.Hill Java 13 04-23-2004 04:21 AM
stylistic prototype question Mantorok Redgormor C Programming 5 10-30-2003 01:51 PM



Advertisments