SU2 icon indicating copy to clipboard operation
SU2 copied to clipboard

C++ Core Guidelines

Open pcarruscag opened this issue 4 years ago • 2 comments

I would like to bring your attention to the existence of this gem: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#main

Of which I use maybe a subset in my often verbose and perhaps repetitive code reviews. The things I comment on are as much a matter of style as multiplication taking precedence over addition is. It is how "They" do it.

So do please browse the guidelines. Ingraining some good guidelines, goes a long way towards freeing one's mind to focus on important implementation aspects. Does this thing need to be const? Just make it, the compiler will tell you if it can't or if you were about to have a bug, the opposite does not happen. I need this piece of code from somewhere. -> Put it in a function. My function does not fit the screen. -> Too long. new su2double[nSomething] -> Some container type, which one? The simplest that will do the job. etc.

pcarruscag avatar Mar 03 '21 16:03 pcarruscag

Passing arrays by pointer -> don't https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-use-ptr Variables declared at the top of the function -> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-introduce Using member variables to "pass data" to other methods -> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-explicit

"What are important implementation aspects?" You ask -> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#per7-design-to-enable-optimization

pcarruscag avatar Mar 03 '21 17:03 pcarruscag

[WIP] SU2-specific best practices (carried over from #1487)

  • Get rid of magic numbers in the code: enums (ongoing work) #1457 (and many others)
  • Get rid of magic numbers for variable indices: nDim+1, nDim+2, etc. #1392

pcarruscag avatar Jan 14 '22 18:01 pcarruscag