Task #2536

Additions to coding guidelines

Added by Robert Lemke almost 11 years ago. Updated about 9 years ago.

Status:
Resolved
Priority:
Must have
Assignee:
-
Category:
- Documentation -
Start date:
2009-01-30
Due date:
% Done:

100%

Sprint:
PHP Version:
Has patch:
Complexity:

Description

Add (and explain) the following rules to the CGLs:

1. Prefer strict comparisons whenever possible. Examples:

   if ($template)             // BAD
   if (isset($template))      // GOOD
   if ($template !== NULL))   // GOOD
   if ($template !== ''))     // GOOD
   if (strlen($template) > 0) // BAD! strlen("-1") is greater than 0
   if (is_string($template) && strlen($template) >0) // BETTER

   if ($foo == $bar)          // BAD, avoid truthy comparisons
   if ($foo != $bar)          // BAD, avoid falsy comparisons
   if ($foo === $bar))        // GOOD
   if ($foo !== $bar))        // GOOD

2. Order of methods:

1. constructor
2. injection methods
3. initialization methods (including initializeObject())
4. public methods
5. protected methods
6. private methods
7. shutdown method(s)
8. destructor

3. Avoid double-negation:

Instead of exportSystemView(..., $noRecurse) use exportSystemView(..., $recurse). It is more logical to pass TRUE if you want recursion instead of having to pass FALSE. In general, parameters negating things are a bad idea.

trueFalse.jpg View (29.7 KB) Robert Lemke, 2009-01-30 12:02

Associated revisions

Revision c75e8dd0 (diff)
Added by Karsten Dambekalns over 10 years ago

FLOW3:
  • some updates to the coding guidelines, fixes #2536

History

#1 Updated by Karsten Dambekalns over 10 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset r2030.

Also available in: Atom PDF