Skip to content

Instantly share code, notes, and snippets.

@hzhou
Last active December 10, 2015 23:02
Show Gist options
  • Save hzhou/97cd364d7b993ebfb818 to your computer and use it in GitHub Desktop.
Save hzhou/97cd364d7b993ebfb818 to your computer and use it in GitHub Desktop.
A case for silly comment

I was reading this numpy script and got this line which makes a good case for how unnecessary comments arise:

sp = 0.5-np.mod(jj,2)# even number of band,1/2; odd band, -1/2 to distinguish upspin and downspin

The coder wrote a clever succinct expression, then he find the need to explain. The explaination essentially in code:

$if jj % 2 == 0
    sp = 1/2.
$else
    sp = -1/2.

We should write code to communicate, rather to demonstrate our experience/cleverness.

PS: I start to find integer division (for constants) more an annoyance than useful. For typed variables are less a problem because of the type restriction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment