[Haskell-cafe] Layout rule (was Re: PrefixMap: code review request)

Jared Updike jupdike at gmail.com
Tue Feb 28 21:14:38 EST 2006


BH> > Why? Surely typing one tab is better than having to hit the
spacebar 4 (or 8)
BH> > times?
PC> Not when it prevents me from ever exhibiting the slightest shred of style
PC> in my code. I use that control for readability purposes in my code.
> [snip]

BH> I'm really puzled here. I've been using tabs to indent my C++ code for at
BH> least 10 years and don't see the problem.

At least two reasons:
1. C++ doesn't care about any whitespace (except to separate tokens).
Haskell cares about leading whitespace (which it is clear you are
thinking a lot about...) but
2. as Philippa mentioned, Haskell programmers care a ton about
inter-line, inter-word layout/alignment, for example, lining up =
signs and arguments to functions in pattern matches, etc. C++ does not
invite this style of declarative programming so it is not surprising
that it wasn't an issue: aside from the indentation, I rarely type
fancy whitespace inside a giving line of C++ code to align elements
with those on a preceding line. In Haskell, this unofficial layout
"style" doesn't affect the machine-parsing of the code, but rather the
human-parsing of the code. (In fact, it's one of my favorite things
about Haskell.)

If you want to see what can be accomplished with variable width fonts
and complex layouts (not just beginning of lines but rather
inter-line, inter-word alignment) you should checkout lhs2TeX. They
accomplish all their magic with spaces.

BH> The only problem would be if
BH> someone mixed tabs with spaces. Since it has to be either tabs only or
BH> spaces only I'd choose tabs only to save keystrokes.

BTW, tab doesn't type the tab character (at least in emacs and I think
vim) but instead moves the left edge of the current line by adding or
deleted spaces (or trying to ident the right amount). This usually
means you don't have to type 4 or 8 spaces. (And anyway, I would just
hold the key down if I had to type more than one spacebar, etc.)

> [snip]
> For example on Windows Trebuchet MS is a very nice font, also Verdana, both
> of which are not monospaced. But yes I agree it's not a major issue and I
> just see the option of being able to use them as a nice side-effect.

Very few programmers I know would go to variable width fonts just to
use some Microsoft font to edit code... (BTW I like Trebuchet and
Verdana too.)

To each his/her own!

Cheers,
  Jared.
--
http://www.updike.org/~jared/
reverse ")-:"


More information about the Haskell-Cafe mailing list