Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

86 Clear Syntax

How a human reads code and how the computer reads it are two very different things. The note array loop example looks a lot like this to the computer:

var targetPitch=60;var rootNote;for(var thisNote=0;thisNotes<chord.length;thisNote++){var note=chord[thisNote];if(note.pitch==targetPitch){rootNote=note;}}

While the code still works, it is not really readable by anyone other than the computer. While this is an extreme example, it does highlight the importance of writing code in such a way that clearly shows the logic and structure of what is being accomplished and to write for clarity. Fixing a bug in the above example would be unnecessarily challenging.