What does this code do?
johndcook.com
johndcook.com
The author says, "Meaningful variable and function names would have helped, but..." and I don't really see why he needed the "but." The first function can be renamed "get_exponent(base, exponent)" and the second, "get_random_integer()", and that's the end of it. What more comments would really be appropriate?
Specifically, naming the algorithm would be good, but the comment should also say why. //This is called by the frobbinator module where preconditions A and B are met, which makes this more efficient.
if n < 0:
n = -n
x = 1.0 / x
Dead giveaway.If your peers don't know this, you're in trouble.
At the time, I hated it because I thought it cramped my style.
Since then, I have worked in many shops with no standards at all and most of the crap I've had to maintain looked just like OP's examples. Probably written by someone who didn't like his style cramped.
Funny how it sometimes takes years to understand that which once made no sense.
“When I was a boy of 14, my father was so ignorant I could hardly stand to have the old man around. But when I got to be 21, I was astonished at how much the old man had learned in seven years.” - Mark Twain
Method names are good, but some clue about the approach is helpful too, which the method name would probably not include.