top | item 19658099

(no title)

OtterCoder | 6 years ago

I've translated several mathematical papers into code, and I must strongly disagree. The very first thing I do is translate glyphs into names relevant to the domain I'm applying the math to. It makes the rest of the process immensely easier.

discuss

order

shstalwart|6 years ago

I guess we'll have to agree to disagree then. I too have coded up a lot algorithms from academic papers. In my mind,

yk = C * xk + D * uk

is a lot clearer than

position_at_time_k = output_matrix * state_at_time_k + feedthrough_matrix * input_at_time_k.

The first is an idiom. The second is not.

FakeComments|6 years ago

That may make sense internal to a library, where you’ve established idioms.

But as a counterpoint, I only know what you meant by the first expression because I read the second expression.

I actually agree with you in large part, that short variable names can have more meaning within an established set of idioms because they allow you to parse whole statements at once. But there’s a trade-off involved, because mathematics can take symbology further than that’s useful.

For example:

    E[i=0;5](i**2)

    sum([i**2 for i in range(0,5)])
So it often comes down to a matter of taste.

jononor|6 years ago

Why not something like this?

    position = C * state + D * input
Reasoning: k is the only subscript, so it can be dropped. Meaning of C and D are implicitly defined through their function wrt to state and input, so its OK not to name them. It also keeps the structure visible similar to that of the math.