Hi All,

I would like to propose something that I have found _incredible_ useful:

Here is an example from the standard C lib:

struct tm {
  int  tm_sec;          /* seconds after the minute [0-60] */
  int  tm_min;          /* minutes after the hour [0-59] */
  int  tm_hour;         /* hours since midnight [0-23] */
  ...
  int  tm_yday;         /* days since January 1 [0-365] */
  int  tm_isdst;        /* Daylight Savings Time flag */
  long tm_gmtoff;       /* offset from CUT in seconds */
  char *tm_zone;        /* timezone abbreviation */
};

The fields of the structure are prefixed.

If this is done so that field names are unique then finding all places in the code where a field is used is very easy.

Whether debugging or just trying to understand code, this is extremely useful.

Often you have a bug where a structure (or class) field has the wrong value, and you need to know where the field is assigned. Now if the field is called 'flags', you have a tough time finding all instances because of the flood of hits.

I have often wished for this while trying to code read my way through the MySQL optimizer to figure out why it is using the wrong query plan. And also for answering questions like how are memory buffers used in MySQL, as Ronald has asked.

I am not proposing that all current structures be changed. Although that would be ideal, and easy to do with the help of the compiler. But it is something to keep in mind for new code.

Obviously, if we do change existing structures it has to be done soon, because it causes a merge nightmare...

Brian Aker wrote:
Hi!

This needs to be a FAQ, not an email. Here goes:


Please use stdint.h for now. http://en.wikipedia.org/wiki/Stdint.h When writing new code always use the C99 types. GCC will give us lint like advice if we do.

Use bool, not my_bool. Use true and false, not TRUE and FALSE (those macro need to die).

ulong -> uint32_t
ulonglong uint64_t

long int -> int32_t


Why? Long is not portable and in MySQL there are a number of places where we use it that I question if the code is really 64 bit clean.

When assigning please use MySQL style:
x= 4;

It is easy to search for.

When you put something together like this:

a == b && c ==j || A

Do it like:

((a == b) && (c ==j)) || A


Be generous with your use of parens. If I see them, then I know you knew what you were doing and I do not have to worry if you really understood operator precedent.

Encapsulate structures and classes.


Use enum, not defines. Defines are for single shot "everything will be this". Enums create lists. If the values are going to go into a switch/ case... they should be enums.

Please do not use "i" as an iterator in for loops. I have old eyes... use x or spell out a variable.

Please fix indention in old code. It is a boring thing to do, but is incredibly valuable. When someone looks at code, they will send in patches based on what they see. Lets make it so the code looks identical.

Do this for () {}; not for (); when you have an empty body. It gives me a hint that you really did want just the for to loop. And while we are at it, (void)func() calls if you are ignoring the return type.

All new classes get their own .h and .cc files. We will need to pull apart the mess that exists today, but that is a long term goal.


Cheers,
        -Brian


--


_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to