Coding Guidelines - hpi-swa-teaching/InteractivePongTutorial GitHub Wiki

In this repository, we employ the following coding guidelines and would encourage all contributors to follow them:

General

One statement per line, the statement may be multi-line.

Name parameters in squeak-style: aParameter, anInteger, etc.

One space before an opening bracket and after a closing bracket: ifTrue: [foo]

Space around @: (69 @ 420)

Space after return character ^

Temporary variable definitions are padded with space: | tempVar1 tempVar2 |

Blocks

General form: collection do: [ :i | | temp var |

...

].

Blocks containing only one statement may be truncated to a single line.

Cascades

One message per line:

foo new

withMessage: aMessage;

withColor: aColor;

yourself.

Messages

Messages are always ended with a period.

One message per line, if there are multiple arguments, the message may be expanded to multiple lines.

Conditions

ifTrue/ifFalse moves to next line and is indented:

(condition)

ifTrue: [foo]

ifFalse: [bar]

Getters/Setters

Always use getters and setters to access variables, even when accessing a variable within the class.

Tests may access their instance variables directly.

General method categories

Common method categories to be used across classes.

  • initialization: methods responsible for creating a new instance of a class
  • accessing: methods responsible for getting/setting instance variables