Skip to content

Split code over multiple lines #7

@dkfellows

Description

@dkfellows

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:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions