One of the several indent styles for C/C++/Java programming. For some reason, almost all Java code is written using the K&R indent, but (according to the Jargon File), Whitesmith is actually more common than K&R among C/C++ programmers. You can compare several different indent styles at the autonoded indent style writeup, and I'll provide a few more examples of the Whitesmith style later on.

Whitesmith, again according the the Jargon file, originally came from examples included with an early C compiler. According to various old mailing list archives, Whitesmith (the company) was still alive as of at least 1988 and possibly as late as 1993, selling compilers for a number of now completely obsolete CPUs, like the 68000, the 8051, and the VAX. It turns out, in fact, that Whitesmith was primarly the work of P.J. Plauger, who is today very well known in the C/C++ world (for one, he wrote most of the STL implementation used by Visual C++).

Here's a litttle bit of C code to give you a feel for how Whitesmith works:

#include <stdio.h>

int main()
   {
   int j, k = 0;
   for(j = 0; j != 5; j++)
      {
      printf("Hello World %d\n", j);
      k += j;
      }
   printf("Hi %d\n", k);
   return 0;
   }

The claimed advantage of Whitesmith over Allman or K&R is that is very obvious where blocks begin and end, even in deeply nested structures - you can just look up and down and line up the braces, and they are less likely to get lost than in Allman or (especially) K&R. People point out that each brace wastes a whole line of your screen, implying that K&R is the superior style. I would contend that this means you should look into buying a nicer monitor - it's not like any of us are stuck on 30 line terminals anymore.

Now, is this indent style called Whitesmith's or Whitesmith? I (and GNU Emacs) call it Whitesmith, but because the actual company name was Whitesmith's, the Jargon file calls it Whitesmiths. How's that for confusing? Anyway, since I call it Whitesmith, that is what it is noded under. If you can come up with an convincing argument/reason why it should be called Whitesmith's exclusively, I'll request a writeup move.


Emacs, the one true editor, has a very nice system that will automatically format source code for you. However, for some reason, it's 'Whitesmith' setting seems to be more like Allman style (at least to me). So, if you like, you can put the following code in your .emacs file and get it working quite nicely. It's not perfect (there are some times when you'll have to manually correct the indentation), but it gets most of the cases right.

(setq realwhitesmith '(
      (c-basic-offset . 3)
      (c-comment-only-line-offset . 0)
      (c-offsets-alist

      (c . 0)
      (comment-intro . 0)

      (statement-block-intro . 0)
      (statement-cont . +)

      (substatement . +)
      (substatement-open . +)

      (block-open . +)
      (block-close . 0)

      (defun-open . +)
      (defun-close . 0)
      (defun-block-intro . 0)
      (func-decl-cont . +)

      (class-open . +)
      (class-close . +)
      (inclass . +)
      (access-label . -)
      (inline-open . +)
      (inline-close . 0)

      (extern-lang-open . 0)
      (extern-lang-close . 0)
      (inextern-lang . 0)

      (statement-case-open +)

      (namespace-open . 0)
      (namespace-close . 0)
      (innamespace . 0)

      (label . 0)
      )
))

; and similiarly for c++-mode-common-hook and 
; the java hook if you like.
(add-hook 'c-mode-common-hook
  (function (lambda()
    (c-add-style "realwhitesmith" realwhitesmith t))))

I think there are some extra things in here that don't have anything to do with Whitesmith, but I'll be honest - I'm way to lazy to go back through all the Emacs documentation to find out what each one does and figure out if it is actually for Whitesmith support or not. Lisp scares me, and I only know just enough to configure Emacs.


References:

  • http://www.znode51.de/articles/bdscint4.tx_
  • http://compilers.iecc.com/comparch/article/88-03-005
  • http://www.esacademy.com/automation/faq/8051/4.htm

Oh, I almost forgot to mention - Whitesmith is the one true brace style. So there.

White"smith` (?), n.

1.

One who works in tinned or galvanized iron, or white iron; a tinsmith.

2.

A worker in iron who finishes or polishes the work, in distinction from one who forges it.

 

© Webster 1913.

Log in or registerto write something here or to contact authors.