-
Notifications
You must be signed in to change notification settings - Fork 12
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
Created by gh-md-toc
Generally speaking:
- The SuperCollider Style Guidelines are followed.
- "Receiver Notation" is preferred over "Functional Notation"
- Tabs are used, not spaces. Tab length is set to 4 spaces.
- A newline is place at the end of every file.
Exceptions include fractions and common quantities: 1/2, pi/2, (3/2).sqrt, 3.sqrt/2, etc.
(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;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
};a = 5;
a.switch(
4, {
"four"
},
5, {
"five"
},
{
"default"
}
)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 */
}... 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);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
});