Skip to content

Instantly share code, notes, and snippets.

@daljeet-singh
Created December 22, 2015 07:18
Show Gist options
  • Save daljeet-singh/c038103683873a51fc86 to your computer and use it in GitHub Desktop.
Save daljeet-singh/c038103683873a51fc86 to your computer and use it in GitHub Desktop.
Please follow the guidelines provided below for developing code and committing to GitHub.
### Indentation
Its important to have your code properly indented for other to read ( I mean for me to read and audit! ). The standard indentation is of 4 SPACES. No TABS to be used for indentation as they are interpreted differently on other editors ( I do a lot of VI and a TAB is 8 SPACES there)
### Braces
Braces are important containers and are used widely in PHP. We all need to adhere to the BRACING practices.
While defining methods, braces start on the same line as the declaration of the method and terminate on a new line after the last of the method.
```php
public function doSomething( $arg1, $arg2 ) {
// Some code here
}
```
Conditional statements, Loops, of course, will use the same pattern. Simple.
```php
$commitAuthor = $this->getCommitAuthor();
if( !$codeIsProperlyIndented ) {
if( !$this->isDead( $commitAuthor ) {
$this->kill( $commitAuthor );
$this->notifyTeam( 'Sh*t happens when you do not indent your code!' );
$this->notifyManagement( 'We need a new engineer. We lost one today in the battleground.' );
} else {
$this->notifyTeam( 'Remember why ' . $commitAuthor . ' died?' );
}
} else {
$this->reward( $commitAuthor ); // basically go drinking with $commitAuthor
$this->sendNotificationToTeam( 'Congratulate ' . $commitAuthor . ' !!' ); // Let them sulk!
}
```
### Naming Conventions
If something can be called with a simple name, use that. Thats the convention. If you are adding a new record to the database, name the method `add`; if you are assigning a role to a user, name the method `assign`; if you are applying a rule to a data set, name the method `applyRule`. Notice when camelCasing should happen.
```php
function addUser() // WRONG! Should be function add()
$postData // WRONG! Should be $data.
```
While naming in the database, use all lowercase and underscores as separators.
```sql
MakeGood_Single_Advertiser // Should be makegood_single_advertiser
FundingSource // Should be funding_source
isDeleted // Should be is_deleted
```
### Committing to GitHub
Use sensible commit messages when committing to GitHub. Messages such as _Updated Users Model_, _Changed css_, etc. will attract the attention of a Draconian Engineer. You don't want that. Rather use clear actions that are going in the code that you are committing. The Draconian Engineer loves to read commits (Its like a story script!) so commit messages like _Added a new method to extract blood from humans_ or _Fixed a bug where the human was alerted prior to attack_ are appreciated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment