mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephen Satchell <satch@fluent-access.com>
To: Anton Altaparmakov <aia21@cam.ac.uk>,
	Mark I Manning IV <mark4@purplecoder.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [OT?] Coding Style
Date: Mon, 22 Jan 2001 22:37:48 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20010122222130.00b1b780@mail.fluent-access.com> (raw)
In-Reply-To: <5.0.2.1.2.20010122233742.00ae5e40@pop.cus.cam.ac.uk>
In-Reply-To: <3A6C630E.C2CB784C@purplecoder.com> <4.3.2.7.2.20010122130852.00b92a80@mail.fluent-access.com>

At 11:56 PM 1/22/01 +0000, Anton Altaparmakov wrote:
>At 16:42 22/01/2001, Mark I Manning IV wrote:
>>Stephen Satchell wrote:
>> >                                              I got in the habit of using
>> >  structures to minimize the number of symbols I exposed. It also
>> > disambiguates local variables and parameters from file- and program-global
>> > variables.
>>
>>explain this one to me, i think it might be usefull...
>
>What might be meant is that instead of declaring variables my_module_var1, 
>my_module_var2, my_module_var3, etc. you declare a struct my_module { 
>var1; var2; var3; etc. }. Obviously in glorious technicolour formatting... (-;
>That's my interpretation anyway...

The first sentence is right on the money.  In addition to module variables, 
I define a global structure as:

      extern struct G {
          /* the real globals */
          } g;

and then in the main program I define the instance as "struct G g;"  This 
is more for apps than operating systems.

Further to the avoidance of pollution of the external global namespace, I 
define local functions as static.  Indeed, in one parser I had over 1400 
very small functions, none of them with external scope.  Instead, I defined 
a structure of function pointers and exposed one name to the rest of the 
world.  Sound stupid?  Well, that stupidity had its place:  the "opcode" in 
the pseudo-instruction stream was the offset into this structure of 
pointers to the pointer of interest, which made the main loop for the 
parser about five lines long, and not a switch statement to be seen.  Three 
of those lines were to handle unknown-opcodes...

I also am partial to arrays of function pointers when appropriate.  Ever 
think how easy it would be to implement a TCP stack that would handle the 
"lamp-test packet" as a single special case?  Granted, it results in a 
small amount of code bloat over the traditional in-line test method, but it 
does make you think about EVERY SINGLE ONE OF THE 64 COMBINATIONS of 
Urg/Ack/Psh/Rst/Syn/Fin (to use the labels from the 1985 version of RFC 
793) and what they really mean.  Especially the combination with all bits set.

Satch

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

  parent reply	other threads:[~2001-01-23  6:38 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-22 21:09 Stephen Satchell
2001-01-22 16:42 ` Mark I Manning IV
2001-01-22 23:56 ` Anton Altaparmakov
2001-01-23  0:01   ` Larry McVoy
2001-01-23  6:37 ` Stephen Satchell [this message]
2001-01-23  8:37 ` Helge Hafting
2001-01-23 18:58   ` Alan Olsen
  -- strict thread matches above, loose matches on Subject: below --
2001-01-23 22:22 Jonathan Earle
2001-01-23 16:47 Jesse Pollard
2001-01-24  0:07 ` Stephen Satchell
2001-01-23 15:41 Jonathan Earle
2001-01-23 15:58 ` Larry McVoy
2001-01-23 16:00 ` Mike Harrold
2001-01-23 16:32   ` Joe deBlaquiere
2001-01-24  1:14     ` Steve Underwood
2001-01-25 13:33       ` Kai Henningsen
2001-01-24  5:42     ` Brent Rowland
2001-01-24  5:50       ` Andre Hedrick
2001-01-26  0:20   ` James Stevenson
2001-01-23 16:14 ` Georg Nikodym
2001-01-23 18:05   ` Christopher Friesen
2001-01-23 18:41     ` Mathieu Chouquet-Stringer
2001-01-23 18:44   ` Georg Nikodym
2001-01-23 18:53   ` James Kelly
2001-01-23 17:42 ` John Kodis
2001-01-25 13:38   ` Kai Henningsen
2001-01-25 13:25 ` Kai Henningsen
2001-01-25 19:30   ` Harald Arnesen
2001-01-22 17:53 Jonathan Earle
2001-01-22 16:04 Jonathan Earle
2001-01-22 16:19 ` Mike Harrold
2001-01-22 16:22 ` Larry McVoy
2001-01-22 18:29   ` Richard B. Johnson
2001-01-22 23:20   ` Admin Mailing Lists
2001-01-23  0:54     ` Werner Almesberger
2001-01-23 12:28   ` Steve Underwood
2001-01-23 16:17     ` Nicolas Noble
2001-01-23 21:16       ` David Benfell
2001-01-23 12:52   ` Andrew Morton
2001-01-23 18:10   ` Stephen Satchell
2001-01-22 17:43 ` Gregory Maxwell
2001-01-20 15:32 Anton Altaparmakov
2001-01-20 16:19 ` [OT?] " profmakx.fmp
2001-01-21  5:10   ` Ragnar Hojland Espinosa
2001-01-21  5:50     ` Admin Mailing Lists
2001-01-21  5:58       ` Mike A. Harris
2001-01-21  7:07         ` Josh Myer
2001-01-21  7:20       ` Alan Olsen
2001-01-21 22:40       ` Mo McKinlay
2001-01-22  0:23         ` Admin Mailing Lists

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4.3.2.7.2.20010122222130.00b1b780@mail.fluent-access.com \
    --to=satch@fluent-access.com \
    --cc=aia21@cam.ac.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark4@purplecoder.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®