MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Roy Lyseng Date:April 28 2009 9:17am
Subject:Coding style change proposal
View as plain text  
Hi,

the coding standard for MySQL says the following about struct typedefing:

"Structure types are typedef'ed to an all-upper-case identifier"

However, I cannot find a single logical reason for this practice. Rather 
I think it is a source for confusion, because typedefs are used rather 
inconsistently within the code.

Examples:

typedef st_select_lex_node SELECT_LEX_NODE;

(st_ prefix is not carried on to the typedef).

struct TABLE_share;

(Mixed upper/lower case)

struct TABLE_SHARE;

(Uppercase - should be typedef according to coding style doc)

typedef struct st_field_info {...} ST_FIELD_INFO;

(typedef name is uppercased version of struct name).

typedef class Item COND;

(COND is an alias to Item - I guess this is allowed according to code 
style).

struct TABLE_LIST;

(All uppercase letters)

typedef struct keyuse_t {...} KEYUSE;

(suffix _t on struct name)

typedef struct st_join_table {...} JOIN_TAB;

(st_join_table -> JOIN_TAB?)

class JOIN;

(typedef names are allowed to be uppercase - class names are not)

It also seems to me that C++ does not require typedef for shorthand 
references to type names.

E.g the following compiles in gcc:

typedef class xxx_class {
   int dummy;
};
struct XXX {
   xxx_class *xxx;
   yyy_class *yyy;
   struct xxx_class *zzz;
   class xxx_class *www;
};

The C++ book by Stroustrup says the following about typedefs:
"Use a typedef to define a meaningful name for a built-in type in cases 
in which the built-in type used to represent a value might change", and
"Use typedefs to define synonyms for types" (implying the synonyms to be 
a shorthand).

I propose that the guideline for typedef should be:

typedef can be used in the following cases:
- to define a meaningful name for a built-in type in cases in which
   the built-in type used to represent a value might change
- to define a shorthand synonym for a complex type name
   (e.g. typedef List<Table> Table_list)
- to define a synonym for another class when both names are meaningful:
   (e.g. typedef class Item Condition)
   This case should be used with great care to avoid confusion, however.

The coding standard should also include a note about legacy typedef 
definitions:

Typedef definitions that do not follow this style should be removed when 
natural cleanup of the code base occurs.

Thanks,
Roy
Thread
Coding style change proposalRoy Lyseng28 Apr
  • Re: Coding style change proposalGuilhem Bichot28 Apr
  • Re: Coding style change proposalMats Kindahl29 Apr