MySQL Internals Manual
The purpose of this chapter is to establish a set of guidelines that will help you, the developer, to follow the established MySQL coding styles and standards when writing code. Consistent style is important as it makes it easier to maintain our code and allows you to find specific routines much more quickly. The standards contained within this chapter apply to the mysql server, and do not necessarily apply to other projects such as JDBC, ODBC, Administrator, etc.
Indentation and Spacing
The following rules apply to indentation and spacing of code within a source file:
• Do not use tab characters (\t), use spaces. All indentation should be two spaces. You should be able to configure your editor to use spaces instead of tabs. (See the editor configuration tips at the end of this chapter for instruction for vim and emacs).
• Line breaks should occur on column 80, with two line breaks between each function in a file.
• Do not use carriage return (\r\n) characters in a source document; this can cause problems for other users and for builds.
• Matching ‘{}’ (left and right braces) should be in the same column. With the exception of a switch statement, all braces should appear on their own line. The only exception to having braces on separate lines is if there is nothing between the braces.
Examples:
if (is_valid(x))
{
x= 2;
}
switch (my_arg) {
for (…)
{}
• Put a space after evaluation keywords if, for and while.
• When a function has multiple arguments, place a space after each comma (‘,’) in the argument set.
return_value= my_function(arg1, arg2, arg3);
• When performing assignments, place a space after the equals sign but make sure there is no space between the variable and the equals sign. This allows for easier searching through the code for variable assignments; It is easier to search for an assignment to ‘x’ when you can search for x= .
When you make multiple assignments indent the right-hand values to make them easier to
read:
int x= 27;
int new_var= 18;
• Operators should have spaces on both sides, including the ‘==’ operator.

Leave a Reply
You must be logged in to post a comment.