Style Sheet - marceloabk/tecProgRunner GitHub Wiki
#Style Sheet
##1. Entity Naming
Variables shall begin with a lower case letter.
Functions shall begin with a lower case letter.
int thisWillBeThStyleOfVariabelsCreated;
int highScore;
NSMutableArray *vector;
-(void) timerDidRunOut;
-(void) gameDidEnd;
-(instancetype) initWithSize:(CGSize)size;
Use sensible, descriptive names.
Do not use short cryptic names or names based on internal jokes. It shall be easy to type a name without looking up how it is spelt. Exception: Loop variables may have short names.
Only use english names.
It is confusing when mixing languages for names. English is the preferred language because of its spread in the software market and because most libraries used already use english.
##2. Indentation and Spacing
Braces shall follow this variation "K&R Bracing Style":
-(instancetype) initWithSize:(CGSize)size{
if(size.height > size.width){
NSLog(@"height bigger than width");
}else{
NSLog(@"width bigger than height");
}
}
Braces shall be indented by tab to the right of the starting position of the enclosing statement or declaration.
Loop and conditional statements shall always have brace enclosed sub-statements.
The code looks more consistent if all conditional and loop statements have braces. Even if there is only a single statement after the condition or loop statement today, there might be a need for more code in the future.
Declare each variable in a separate declaration.
This makes it easier to see all variables. It also avoids the problem of knowing which variables are pointers.
For declaring pointers and reference the "*" and "&" shall be surrounded by space on the left side.
char *aPointerWillBeSpacedLikeThis;
##3. Comments
Comments shall be written in english and fallow the fallowing model
// The comments will be spaced according to his line
// Comments with multiple lines
// Will be done with multiple bars
// So we can use shortcuts provided by xcode
Comments with continuation shall be written this way
// Set the attributes...
// ... for the player
// ... for the enemy
Description of variables and methods shall be written this way to facilitate documentation
/**
Description of the method or variable
*/
Every function shall have a comment that describes its purpose. Except when the function already have a description compatible with the purpose.
##4. Code examples
Header style .h
//
// NameOfTheClass.h
// TecprogRunner
//
// Description
//
// Copyright (c) 2015 Group 8 - Tecprog 2/2015. All rights reserved.
Header style .m
//
// NameOfTheClass.m
// TecprogRunner
//
// Description
//
// Copyright (c) 2015 Group 8 - Tecprog 2/2015. All rights reserved.
Import line example
#import <Foundation/Foundation.h>
Interface line example
@interface Teste : NSObject
If a single property of a class is created:
@property (nonatomic) InitialLayer *initialLayer;
If a variable needs to be created in the .m use an underline:
int _score;
SKSpriteNode *_sprite;
Alloc and init examples
NSString *string = [[NSString alloc] init];
NSString *string = [[NSString alloc] initWithString:@"Score"];
NSString *string = [[NSString alloc] initWithFormat:@"%i", 18];
NSArray *strings = @[@"Henrique", @"Julio", @"Lucas", @"Marcelo"];
For statement
for(int i = 0; i < 0; i++){
}
for(UITouch *touch in touches){
}
While statement
while(check){
}
If statement
if(highScore > 30){
}else if(highScore > 20){
}else if(highScore > 10){
}else{
}
Math
double score = 55 / 2;
self.score++;
self.score--;
self.score /= 3;
self.score *= 3.2;
self.score -= 5;
self.score += points;
self.score = ((something + 3) / 10) + 2;
self.score = (5 % 2) * M_4_PI;
EnumerateWithChild
[self enumerateChildNodesWithName:@"layer" usingBlock:^(SKNode *node, BOOL *stop){
SKSpriteNode *layer = (SKSpriteNode *) node;
[layer removeFromParent];
}];