Coding for mathematical algorithms - should variables in the book or more descriptive be used?

I support the code for the mathematical algorithm that came from the book, with links in the comments. Is it better to have variable names that describe what the variables represent, or do the variables correspond to what is in the book?

For a simple example, I can see this code that reflects a variable in a book.

A_c = v*v/r

I could rewrite it as

centripetal_acceleration = velocity*velocity/radius

The advantage of the latter is that anyone looking at the code can understand this. However, the advantage of the first is that it is easier to compare the code with what is in the book. I can do this to double check the implementation of the algorithms, or I can add additional calculations.

Maybe I'm thinking too much about it and should just use comments to describe variables. However, I prefer self-documenting code (use the names of descriptive variables instead of adding comments to describe what they are), but perhaps this is the case when the comments are very useful.

I know this question may be subjective, but I was wondering if anyone has guidelines for making a decision or have links to guidelines for a mathematical coding algorithm.

+5
source share
7 answers

. , , , "". , .. -, .

, , .

+8

. () -, , , a = v * v/r, .

, . , , (- Knuth " ", ? , ). LAT ascii art, . Jave.de - Java Ascii Vmumble.

, , , , REFACTOR, , , , .

+3

, , , . , , " ", / , , v r, , , , . (, , ), , . / , , , , .

+3

, . .

// A_c = Centripetal Acceleration
// v = Velocity
// r = Radius

A_c = (v^2)/r
+3

"". 'v' 'r' .. .

+1

?

(:-)) Δ, (, #):

int Δv;
int Δx;

, , . , . , ( ), , , .

, , , ?

0

The trade-off may be to code and debug, as contained in the book, and then perform a global search and replace all of your variables until the end of your development, to make them easier to read. If you do this, I would change the names of the variables a bit so that it is easier to change them later.

e.g. A_c @ = v @ * v @ / r @

0
source

All Articles