-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
In my experience it's best to split code over several lines and use {
curly braces}
even in cases where they're technically not necessary. It's longer but really boosts the readability.
For example, consider this line:
PCC_Processing_Design/src/lib/PCC_Characterisation/functions/analytical_solutions.h
Line 25 in 23c8e07
if (j0s != 0) j0s = jj0* log2(jj0); if (j1s != 0) j1s = jj1* log2(jj1); if (j2s != 0) j2s = jj2* log2(jj2); if (j3s != 0) j3s = jj3* log2(jj3); //Gives 0 in entropy! |
It would be way better written as this:
if (j0s != 0) {
j0s = jj0* log2(jj0);
}
if (j1s != 0) {
j1s = jj1* log2(jj1);
}
if (j2s != 0) {
j2s = jj2* log2(jj2);
}
if (j3s != 0) {
j3s = jj3* log2(jj3);
}
//Gives 0 in entropy!
Yes, it takes more lines of code, but there isn't a global newline shortage.
Some libraries can do more mnemonic approaches, by providing higher level concepts like vectors and quaternions and so on. I don't know if any of those would be applicable to your code; adopting one of those would certainly be a lot of work.
Metadata
Metadata
Assignees
Labels
No labels