![]() |
|
|
EQdkp Core Developer Manual
EQdkp Coding Standards
This document describes the coding standards used in the core EQdkp code and is not necessarily applicable to plugins, but it would be preferrable.
Text Editors
Editor Settings
Tabs vs. Spaces: All spaces, no tabs. 4 spaces per indentation.
Naming Conventions
Variable Names: Variable names should be all lowercase, with words separated by an underscore. "$variable_name" is right, "$variablename" and "$variableName" are not. Loop Indices: The only situation where a one-character variable name is allowed is when it's the index for a looping construct. Function Names: Functions should be named descriptively while not being 50+ characters long. Function Arguments: Subject to the same guidelines as variable names. The basic idea here is to not sacrifice code clarity for the sake of laziness.
Code Layout
Standard CVS Header: This comment block is placed at the top of every file in EQdkp's core.
/******************************
Braces: Always include the braces. Typing two extra characters greatly improves code clarity.
// The following are all wrong:
Brace Position: This is another issue of personal preference, but in the case of EQdkp, please put each brace on its own line, it makes it much easier to tell where each block starts and stops when you can line up the start and end braces.
// Use:
Single/Double quotes: Unless you need to use double quotes, use single quotes.
// Wrong:
Use spaces and parenthesis to group conditions:
// Wrong: Notice that PHP keywords (if, for, foreach, while, else, elseif, etc.) have a space between the word and the parenthesis, whereas function calls do not.SQL code layout: SQL keywords should be in uppercase ("SELECT field1 AS something FROM table WHERE (this = that)") and should be on their own line for large queries.
$sql = 'SELECT r.member_name
Always include field names for INSERT statements. Plugins may want to add a field to an existing table instead of creating an entirely new table, and doing so would break SQL statements that don't specify the fields.
// Wrong:
Commenting: Use helpful comments wherever possible - even if the logic is obvious to you but might confuse someone else, include comments. Do not comment just for the sake of commenting, however.
// BAD COMMENTING: For examples of the desired level of commenting, see admin/addraid.php and includes/eqdkp_plugins.php.Ternary operator: The ternary operator is used extensively throughout EQdkp's core code. It should be formed in a similar way to an if-else block and should not go more than 2 levels deep:
// Wrong:
Server Settings/Requirements
EQdkp should be able to run with register_globals set to off and error reporting set to E_ALL (notices, warnings, and errors). This means that variables must be initialized before being used/checked. Use isset() and empty() where necessary. The minimum requirement for EQdkp is PHP 4.1.2 and should stay that way until more hosts are upgraded. Do not use a function that is only available in 4.2.x or 4.3.x - check the manual first. |