eclipse-wakaama / wakaama

Eclipse Wakaama is a C implementation of the Open Mobile Alliance's LightWeight M2M protocol (LWM2M).
BSD 3-Clause "New" or "Revised" License
497 stars 374 forks source link

Define code styling rules #513

Open sbernard31 opened 3 years ago

sbernard31 commented 3 years ago

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 commented 3 years ago

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 ?

rettichschnidi commented 3 years ago

I'd split this into two parts:

sbertin-telular commented 3 years ago

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.

sbernard31 commented 3 years ago

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

sbernard31 commented 3 years ago

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:

qleisan commented 3 years ago

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...

sbernard31 commented 3 years ago

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