5 ms·
Programming languages are not mathematics, better to put your mathematics in the comments, than the reverse. force = (g_constant * mass[0] * mass[1])/(radius
by mjburgess 8y ago
Programming languages are not mathematics, better to put your mathematics in the comments, than the reverse.
force = (g_constant * mass[0] * mass[1])/(radius 2)
Communicates far more than the algebraic alternative.
Programming is about solving a particular problem, not providing a general formalism. The art of it, and mastery of it, is how to imbue the program with the problem domain. So that by speaking in its concepts you solve the problem.
> violate the principle of "don't repeat yourself"
That isnt the principle, that's a literal reading of each word conjoined into something totally different.
The principle is "solve the problem once", ie., if you encounter code re-solving a problem already solved before, abstract such that you solve it only once.
The principle only makes sense with respect to a problem which reoccurs, it is either incoherent or false when applied to literal fragments of code text.
One would then be moved to define replacement macros for anything more than two letters.
- enriquto 8y ago> better to put your mathematics in the comments, than the reverse I respectfully, and strongly, disagree. Try to implement the conjugate gradient algorithm (or a variation of it) https://en.wikipedia.org/wiki/Conjugate_gradient_method https://en.wikipedia.org/wiki/Conjugate_gradient_method Using your style, you will obtain an unreadable mess. Better make your code isomorphic to your math, and then explain the meaning of everything in the comments. > force = (g_constant * mass[0] * mass[1])/(radius 2) > Communicates far more than the algebraic alternative. I don't see how this is clearer than something like this // Newton's law of gravitation // // m : mass of first body // M : mass of second body // G : universal gravitational constant // r : distance between the two bodies // F : force between the two bodies F = G * m * M / (r^2)
- mjburgess 8y agoThe problem arises at the 1000-line program level and above.