Subject: Re: Bluetooth protocol code
To: Garrett D'Amore <>
From: Ignatios Souvatzis <>
List: tech-kern
Date: 12/13/2005 10:18:09
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 12, 2005 at 02:42:45PM -0800, Garrett D'Amore wrote:
> Iain Hibbert wrote:
> >>3) break long lines where possible.

> >Sure, there are some issues there but how long is too long in the modern
> >world?  I use 160 char width xterm on ~5 year old laptop - 80 column
> >terminals are surely a thing of the past?
> >
> No, for several reasons:
>     1) Lots of people don't want to start a GUI to work -- there are a
> lot of 80 column consoles displays out there.  (And some folks still
> work with actual terminals, though that is rare.)
>     2) I work with 80 column emacs windows, and tend to pull up a bunch
> of them side by side on my high res display.  This lets me maximize my
> screen content.
>     3) *Some* standard has to be defined, because 500 character lines
> are not acceptable.  80 is a reasonable standard with historical preceden=
>     4) If you need to make your lines that long, then it *might* be a
> sign that your code needs to be restructured.  Deep nesting is a
> frequent sign, and maybe pulling code out into functions or changing
> your loop constructs might make it easier to read.  (More than about 3
> levels of nesting is hard for others to follow, *especially* in big
> functions.)

What he said, and additional:

It encourages you to do all validity tests at the start of a function,
and have the main piece of code at the first indentation level afterwards,
instead of being deeply indented:

Other style:

sometype foo(parameters) {
	variable declarations;
	if (parameter1 is ok) {
		if (somevariable =3D allocationfunction(someparameter)) {
			if (somehandle =3D opennetworkconnection(somevariable) {
				return result;
			} else  {
				return some other error code;
		} else {
			return error code;
	} else {
		return error code


	variable declaraitons;

	if (parameter 1 is not ok) {
		return error code;
	somevariable =3D allocationprocedure(someparameter);
	if (!somevariable) {
		return some other error code;
	somehandle =3D open network connection(someparameter, somevariable);
	if (invalid(somehandle)) {
		some error handling;
		goto cleanup;

	do something with variable and netowrk connection;

	return result;

	if (valid(somevariable)) {
	return error code;

The cleanup section is only really necessary if you have multiple
allocation-style initializations to undo (else all cleanup can be
done right next to the allocation error detection near the start of
the function), and can be written in the same style so that all
allocations succeeded are undone in the right order. - And the main
code is always near the left border of the terminal. If you want to
know why this is a good think, read some examples from the Amiga ROM
kernel programming manual - they do it the other way. To match=20
error handling to allocation, you have to count braces, or hope they
formatted right and use a pencil, a set square and a ruler.

[We all go through this set of instructions when we're new to the
 project - guess it's my time to explain]


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: 2.6.i