develooper Front page | perl.perl6.internals | Postings from January 2002

Proposal: Naming conventions

Thread Next
From:
Steve Fink
Date:
January 10, 2002 11:25
Subject:
Proposal: Naming conventions
Message ID:
20020110192505.GA21708@foxglove.digital-integrity.com
The naming of things is getting a bit messy. I'd like to propose a
convention that I use in my work. It's compatible with the last draft
of PDD 7 that I could find:
http://www.mail-archive.com/perl6-internals%40perl.org/msg03422.html

By example:

struct somename_t { ... };
typedef struct somename_t { ... }* Somename;

The non-typedef'd name of a struct type ends in _t. (If you don't mind
typing the 'struct', then surely you won't mind typing the _t.)
Typedef'd names are always capitalized (as in PDD 7). If a particular
type is almost always used as a pointer (eg Parrot_Interp), then the
capitalized name refers to a pointer type. (Think of a Foo as a
reference to a struct foo_t). This is the case for nearly all struct
typedefs. Some things are *never* used without going through a
pointer, in which case the _t version is unnecessary.

I usually only use _t names for recursive data structures like linked
lists and trees. But maybe some compilers don't like
  Foo foo = (Foo) malloc(sizeof(*foo));
? Does ANSI allow using sizeof on a variable declared on the same line?

The current
  struct Parrot_Interp { ... };
would become
  typedef struct Parrot_interp_t { ... }* Parrot_Interp;
or if you like splitting things up
  struct Parrot_interp_t { ... };
  typedef struct Parrot_interp_t* Parrot_Interp;

and in the gazillion places where 'struct Parrot_Interp *' is used,
we'd use 'Parrot_Interp' instead. Imagine, we'll save 8 bytes * 1
gazillion occurrences! More function declarations will fit on a line!
World peace will ensue and the moon will become habitable again!

If people have visceral objections to typedef'ing pointers, I'm fine
with dropping that part of the proposal. I'd just like to see

struct Stack_Entry *push_generic_entry(struct Parrot_Interp *, struct
Stack_Entry **top, void *thing, INTVAL type,  void (*cleanup)(struct
Stack_Entry *));

become more like

Stack_Entry push_generic_entry(Parrot_Interp, Stack_Entry *top,
                               void *thing, INTVAL type,
                               void (*cleanup)(Stack_Entry));

Oops. Except PDD 7 says that it's

Stack_Entry
push_generic_entry(Parrot_Interp, Stack_Entry *top,
                   void *thing, INTVAL type,
                   void (*cleanup)(Stack_Entry));

(someday I'll figure out why our stacks are obsessed with passing back
their tops all the time.)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About