While talking with a non-coder friend , I mentioned that my muse is a night owl and usually visits late at night. He was surprised, and said "you mean there's a programming muse?"
Oh yes, there is a programming muse! Some people call it "being in the zone". When my muse visits, it's as if the code is writing itself... and doing it well...with meaningful comments!
My friend was skeptical, and said poets have muses. My instant response was that code can be a lot like poetry, albeit a strict form of poetry. It can certainly be elegant, to a reader who understands it's form and meaning.
He remained skeptical, but the conversation planted a seed in the back of my brain. Since then, I've noticed a pattern in my coding preferences. I crave poetic symmetry and pattern. When I have to break pattern to avoid some compiler errors, I'm uncomfortable.
The following code snippet, will not generate compiler errors (in context), but it has an ugliness to it.
Now I know this is just a matter of personal taste, but it would look more symmetrical if I could use "var" in each clause as if the clause was a function and declare that variable in each clause. That way, I could keep "var" in front of each variable. To me, dropping "var" for repeats (like p1 and p2), disrupts the rhythm of the code for me.
if(gen == 1){
// two peaks
var p1 = A.x - T.hz1;
var p2 = A.x + T.hz1;
peaks.push(p1, p2);
} else if(gen == 2){
// 4 peaks
p1 = A.x - T.hz2;
p2 = A.x + T.hz2;
var p3 = A.x + 2*T.hz1 - T.hz2;
var p4 = p3 + 2*T.hz2;
peaks.push(p1, p2, p3, p4);
} else if(gen == 3){
//8 peaks
p1 = A.x - T.hz3;
p2 = A.x + T.hz3;
p3 = A.x + 2*T.hz2 - T.hz3;
p4 = p3 + 2*T.hz3;
var p5 = A.x + 2*T.hz1 - T.hz3;
var p6 = p5 + 2*T.hz3;
var p7 = p5 + 2*T.hz2;
var p8 = p7 + 2*T.hz3;
peaks.push(p1, p2, p3, p4, p5, p6, p7, p8);
}
Update: In context, the code above is called in sequence, so that the first time it's run gen=1 and the next time gen=2.