Comment

Comment by jpcfl

Parameters and functions

No const.

Please don't. `const` is incredibly valuable, not only to the reader, but to the compiler.

Take for example:

  int Foo_bar(Foo const* self);
Just looking at this signature, I know that calling `bar()` will not modify the state of the object. This is incredibly valuable information to the reader.

Furthermore, if I want to create a `Foo` constant, I can only call this function if it is `const`.

  static Foo const a_foo = FOO_INIT(&some_params);
  return Foo_bar(&a_foo); // Will not compile without 'const' in function
`const` is valuable to the compiler, since `a_foo` can be placed into ROM on some platforms like MCUs, saving precious RAM.
parent jpcfl 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton