wakaama icon indicating copy to clipboard operation
wakaama copied to clipboard

Define code styling rules

Open sbernard31 opened this issue 4 years ago • 7 comments

Maybe it would be good to define some rules about code styling ? This could help to have a more consistent code base ?

The rules could be written in a wiki page (e.g. https://github.com/eclipse/leshan/wiki/Code-&-design-guidelines)

  1. value == var VS var == value (currently leaning towards : value == var?)
  2. if (ptr) VS if(ptr != NULL) (currently leaning towards : if(ptr != NULL)?)

sbernard31 avatar Dec 16 '20 14:12 sbernard31

E.g of question : Should we write value == var or var == value (see https://github.com/eclipse/wakaama/pull/512#discussion_r544283993 for more details) ?

About benefits of value == var, this is maybe not so true.

@sbertin-telular, @tuve, @qleisan, @rettichschnidi ?

sbernard31 avatar Dec 16 '20 14:12 sbernard31

I'd split this into two parts:

  • Code formatting: using e.g. clang-format (not part of this issue)
  • Everything else (including the example from above): Lets find something which is a) close to the predominantly used style in this code base (is there one?) and b) is already existing

rettichschnidi avatar Dec 17 '20 10:12 rettichschnidi

As far as value == var or var == value, I find var == value slightly easier to read and write as it aligns with the way I think. I have been working on a project recently with value == var as the standard, so I'm getting used to it, but it does still take a bit of extra time to write or read it that way.

sbertin-telular avatar Dec 17 '20 13:12 sbertin-telular

(I'm not sure be I think you have right to create wiki page if needed)

sbernard31 avatar Dec 17 '20 13:12 sbernard31

Add a new code style question : if (ptr) VS if(ptr != NULL) (from #512) I will add all this kind of question in the issue description :point_up:

sbernard31 avatar Dec 18 '20 13:12 sbernard31

Decide coding style for when to check pointers https://github.com/eclipse/wakaama/issues/514#issuecomment-761041820 https://github.com/eclipse/wakaama/issues/506#issue-752058734

"always check for runtime errors but not always for programming errors...". This needs to be refined but IMHO it doesn't make sense to ALWAYS check pointers everywhere. "Assert" in combination with testcoverage is another tool that we can use to keep the code lean and clean. Some (Donald Knuth et al. :) argue that crash early and crash big is far better than creating wrong data...

qleisan avatar Jan 20 '21 10:01 qleisan

Question about usage of assert : https://github.com/eclipse/wakaama/pull/531

sbernard31 avatar Feb 15 '21 10:02 sbernard31