Hacker News new | past | comments | ask | show | jobs | submit login

I once had a very stubborn intern who decided to add as much const as he could in our codebase. What followed was a heated discussion and I did a global replace of const by nothing.

The main problem with const is that it's ugly, it's viral and it does not add any value to the code.

And I know all the supposedly good things about this, but I never found any real usage in practice.




You should fire yourself. Seriously.

Understanding which object parameters to a function are inputs and which ones are modified is key information about the behavior of a function. It's omission requires devs to divine the intent from the name and hope that every previous dev was a good citizen w.r.t keeping function names accurate to intent.

Finding and replace const with empty is the moral equivalent of replacing all the types of parameters with void*. After all, types are viral and ugly too.

I really hope that intern found a better place to work than your company.


With "const" you still need to rely on devs being good citizens since const can be trivially casted away.

I've been programming in C for 25+ years. const is clutter.


Don't let consts get "trivially" casted away in code review. If something is no longer const than remove the keyword, or find another way to solve your problem


> const can be trivially casted away.

Yes, types can be trivially casted away too. That's not a reason to use void* everywhere.


I strongly disagree, obviously. Using const to document code might seems like a good idea in some organizations, with extremely large codebase, I don't know.

But first, when you're an intern, you have to follow the local codestyle, even if you think it's not ideal.

Second, I think there are much better rules than spamming const to attain the same objective, but you might need more experience to really appreciate that.


> Second, I think there are much better rules than spamming const to attain the same objective

Like?

> you might need more experience to really appreciate that.

Practically a picture perfect appeal to authority.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: