Skip to content

ATK Code Style Guidelines

Michael McCrea edited this page Aug 4, 2019 · 18 revisions

An overview of rules adopted for the atk library in SC3

Table of Contents

Created by gh-md-toc

Overview

Generally speaking:

Whitespace

  • Tabs are used, not spaces. Tab length is set to 4 spaces.
  • A newline is place at the end of every file.

Operators

Spaces should surround operators, including caparison operators.

Exceptions include fractions and common quantities: 1/2, pi/2, (3/2).sqrt, 3.sqrt/2, etc.

Commas

Spaces always follow commas.

arg/var keyword

Use |pipes| instead of the arg keyword.
[UNDECIDED] var keyword always under first function line, followed by empty line?

Flow control - UNDECIDED

if statements

"Receiver Notation" is preferred over "Functional Notation":
(test > 4).if({ true }, { false });
Use only open curly brackets '{' when the if has no else case, or when there is no trailing method call:
(test > 4).if{ true };		// no else case

(test > 4).if({			// if/else case
	"yes".postln
}, { 
	"no".postln
});

(test > 4).if({			// trailing method call
	[1, 2, 3] 
}).flop;
If it's clearer not to use receiver notation...

put a space between if and its statement, and use curly braces to enclose the cases, not parentheses:

if (test > 4) { 
	"yes".postln
} {			// space between case braces
	"no".postln
};

switch statements

a = 5;
a.switch(
	4, { 
		"four" 
	},
	5, { 
		"five" 
	},
	{ 
		"default" 
	}
)

case statements

Place the case, with enclosing brackets, on its own line.
pn = case
{ pn.colonIndices.size == 0 } {
	Atk.getMatrixExtensionSubPath(this.set, this.type) +/+ pn;
}
{ pn.colonIndices.size > 0 } {
	Atk.getMatrixExtensionSubPath(this.set, this.type) +/+ pn;
}
{ 
	/* default case */ 
}

fork and defer

follow fork with curly braces only

... unless you need to specify the clock explicitly, in which case, use functional notation with a parenthesis.

// default clock
fork {
	/* do something */
	1.wait;
	/* do something else*/
};

// clock specified
fork({
	/* do something */
	1.wait;
	/* do something else*/
}, AppClock);

multi-test comparisons

Taken from SC's style recommendations.

Use the and: keyword (and related keywords) instead of &&, and enclose the second test in curly brackets.

This is more efficient.

(test > 4 and: { test2.isNil }).if({ 
	"yes".postln
}, { 
	"no".postln
});

// multi-line, multi-test
(
(test1 > 4) and: { 
	test2.isNil or: {
		test3.notNil 
	}
}
).if({ 
	"yes".postln
}, { 
	"no".postln
});
Clone this wiki locally