const or immutable?
Adam D Ruppe
destructionator at gmail.com
Wed Sep 22 20:17:22 UTC 2021
On Wednesday, 22 September 2021 at 20:06:59 UTC, Ali Çehreli
wrote:
> tl;dr Do you use 'const' or 'immutable' by-default for
> parameters and for local data?
well i often ignore it but `const` (or often better yet, `inout`
if there's any relation to a member of yours or if you return it)
is better on function arguments, and `immutable` is better on
internal members.
The exception is when you are storing something from someone
else, where immutable params might be more important. But if you
are looking and not touching, const or `in` is good.
> Aside: If 'const' is welcoming, why do we type 'string' for
> string parameters when we don't actually *require* immutable:
Unfortunate naming here... the convenient name encourages its use
but it is indeed often suboptimal.
More information about the Digitalmars-d
mailing list