Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tabs should always be used for indentation. Spaces should never be used for indentation. We live in a world where IDEs can be configured to display tabs at variable lengths, so configure your tab width to what you feel comfortable with. This author prefers tabs to be represented as 4 spaces.

Line Length

Lines should be designed such that a reader can avoid horizontal scrolling, except in cases where scrolling offers improved readability over word-wrapping. As the resolution and width of monitors has increased the standard width of 80 characters (previously the width of a punch card) no longer holds any relevance. Use your best judgement to determine where lines should wrap.

...

Tip
titleCorrect
Code Block
languagephp
define("MY_CONSTANT", "some value");

 

Conditionals

...

Statements

Blesta uses Compact Control Readability style. Each statement should begin on its own line.

Tip
titleCorrect
Code Block
languagephp
if ($foo > $bar) {
    echo "foo is greater";
}
else {
    echo "bar is greater";
}

 

Classes

Methods

Comments

Doc Comments

...

There are three types of comments that may be used in PHP. They are block comments (/* */), inline comments (//), and shell comments (#).

Block Comments

Inline Comments

Inline comments should be used to clarify code. You are discouraged from using inline comments at the end of a line as this creates run-on lines and your comment is unlikely to be read.

Note
titleCorrect, but discouraged
Code Block
languagephp

$c = 2*pi()*$r; // Calculate the circumference
Tip
titleCorrect
Code Block
languagephp
// Calculate the circumference
$c = 2*pi()*$r;

 

Shell Comments

These comments should only be used to identify TODO comments.

Code Block
languagephp
titleA TODO Comment
firstline1
linenumberstrue
<?php
class MyClass {
    #
    # TODO: Finish this class.
    #
}
?>