Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Apr 2009 22:39:40 +0200
From:      Polytropon <freebsd@edvax.de>
To:        freebsd-chat@freebsd.org, Polytropon <freebsd@edvax.de>, William Gordon Rutherdale <will.rutherdale@utoronto.ca>
Cc:        William Gordon Rutherdale <will.rutherdale@utoronto.ca>, Oliver Fromme <olli@lurza.secnetix.de>, freebsd-chat@freebsd.org
Subject:   Re: Why??  (prog question)
Message-ID:  <20090401223940.949ab0ee.freebsd@edvax.de>
In-Reply-To: <200904011335.n31DZT6D062212@lurza.secnetix.de>
References:  <20090401123512.ec165676.freebsd@edvax.de> <200904011335.n31DZT6D062212@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
First of all, thanks for redirection.

On Wed, 1 Apr 2009 15:35:29 +0200 (CEST), Oliver Fromme <olli@lurza.secnetix.de> wrote:
> There's no problem with hitting the Tab key.  Your editor
> takes care of the actual behaviour.  For example, I have
> configured my editor to use literal tabs for Makefiles
> and shell scripts, and display them with 8 positions apart,
> but for Python programs display them only with 4 positions
> apart.  For C source code, the behaviour depends on the
> project (directory).  For the FreeBSD project, tabs with
> size 8 are used (according to style(9)), but for some other
> projects, spaces are inserted (4 or 8).  For most other
> types of files, the <Tab> key inserts various amounts
> of space characters.

It's good to have this configuration on a per-project base,
instead of needing to set this manually (and change it
according to the project you're working on at a given moment).

And as I agreed, as long as there's a guideline one can
follow, it's not that bad.

What's bad is when several styles are mixed, e. g.

	int foo(int x, int y)
	{
	    int z; /* intended by 4 spaces */
	    struct moo {
		int pups; /* a tab here, shown at width 8 */
		int furz;
	    } /* and 4 spaces again */

You'll be surprised how ugly the code looks when ^TD != 8. :-)



> In all of those cases, I simply press the <Tab> key to
> indent, and the <Backspace> key to dedent.  There is no
> need to change habits.  The editor takes care of it.



> I assume that every modern editor can be configured that
> way.

Even "old fashioned" ones can, take the mcedit (Midnight Commander
Editor) and joe (Joe's own editor) into mind. I think even the
simple vi can.



> No, that won't work.  In practice you will either have to
> adopt the original indentation style, or reformat the
> code.  Just changing the tab size in your editor will
> break many things.

Maybe I expressed in an unelegant way: When tabs are used,
you can set the tab width to your individual preferences.
If spaces are used, you cannot do this anymore, you have to
live with the spaces ("corporate guideline").

The only chance you have is to set tab width = number of
spaces per indent level, and finally convert them back into
spaces. But that's ugly.



> Here's an example.  I'll use /usr/include/stdio.h for this
> example because it's installed almost everywhere, even if
> your don't have /usr/src.
> 
> $ less +100 /usr/include/stdio.h
> 
> That command should show you the typedef declaration of
> struct __sFILE, which is about 30 lines.  Note how the
> types, names and comment columns line up neatly.
> Now view the same with tab size 4:
> 
> $ less -x4 +100 /usr/include/stdio.h
> 
> See the difference?  It's a complete mess.

Yes, it is. The only chance here would be to completely use
spaces - use spaces ONLY, no tabs. But that doesn't conform
to the style of FreeBSD.



>  > But maybe if I pass ^TD8 code to you, you would want to
>  > work with it in ^TD4.
> 
> No, I wouldn't.  If I did only minor changes, I would
> simply stick to the existing style of the file.  And if
> I did substantial changes, I would probably reformat the
> whole file -- note that this does *not* only change the
> indentation style, but much more.  Indentation is only
> a part of the style, and probably not even the most
> important part.

I would need to add that I use ^TD8 so the "tabular example"
you gave above would work, so only if you rely on a tab
with = 8, everything looks fine, e. g. comments in structs.
With ^TD4, it would get messy, as you illustrated. So there
would be no practical use in using ^TD4 if this special case
would apply. Only for "plain code" (one statement per line,
comments on separate lines) it would be okay.



>  > > >  + you need more keypressing to get through the indentation with
>  > > >    the spaces, one keypress per space, while you only need one
>  > > >    keypress per tab (which equals one indentation level),
>  > > 
>  > > Not true.  You set up your editor settings to automatically do this for
>  > > you.  Most editors have this capability. 
>  > 
>  > Not all editors have this ability.
> 
> Tell me a common editor that doesn't have that ability.
> And no, ee(1) doesn't count.  I'm not aware of a FreeBSD
> developer who uses ee(1) for serious work.

My two examples above, joe and mcedit: Going forth and back
in indentation would require one keypress per space character,
in opposite to one keypress per tab (which equals one indentation
level).

But again, they don't count as serious editors, do they? :-)



>  > Not every programmer uses vim, emacs or Eclipse. Some really
>  > like the "old fashioned" ways like joe.
> 
> Oh, good thing you mention joe.  I'm typing this reply
> in joe right now.  I use joe for almost 20 years, and
> it *does* support all of the features mentioned above.

Well, joe was my first Linux and then FreeBSD editor, and it
got a lot of new features (such as code highlighting). If
you are familiar with TP / WS key codes (^KB ^KK ^KM ^KE
^KX ^TZ and so forth), it's a real powerful editor.


Finally, I'd like to add that I've not always been such
a "tabbing nazi". In KC-BASIC, my first programming language,
I didn't use indentation (allthough it was completely
possible) and later, when I learned TurboPascal for school,
I used one (!) space for indentation, no spaces to make the
code look tidy, and as many instructions per line as it was
possible. With my introduction to UNIX (i. e. WEGA) I found
that the standard tabbing with a width of 8 is the best to
read and to handle - that's my very individual opinion.

function st(x,y as integer):integer; begin x=sk(aa[q].x+rs(r,10,12); if(y=0)then begin x=sk1(ww[e],x+x0+rs(x,100*y,5); y=y+x; end; return x-y; end;

Terrible! :-)




-- 
Polytropon
>From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090401223940.949ab0ee.freebsd>