Immutable better than const?

M

MikeP

Is immutable better than const? I mean "immutable" like in C#. At least
one book author opines that it is superior to C++ "const" because
const-ness can be cast away. What is your opinion on the matter?
 
M

MikeP

Pete said:

I forgot to ask what y'all would prefer ideally (either/or/both) and if
there is any talk about an "immutable" keyword as a possibility in a
future standard or if the committee feels that const fits the bill
adequately and entirely.
 
V

Victor Bazarov

I forgot to ask what y'all would prefer ideally (either/or/both) and if
there is any talk about an "immutable" keyword as a possibility in a
future standard or if the committee feels that const fits the bill
adequately and entirely.

Just a thought: since you're talking of a non-existing feature of the
language, which you think might be considered for discussion for future
versions of the language, comp.std.c++ is a better venue. Just a though...

V
 
Ö

Öö Tiib

No. constexpr is great upcoming keyword that means something. What
does immutable help? There will be always book authors who think that
software developer is stupid moron and language engine should know
better how to write software.

People reading your code look also at casts. If you don't know what
you are doing then you will be badly beaten by review and sent back to
your Actionscript or PHP team.
I forgot to ask what y'all would prefer ideally (either/or/both) and if
there is any talk about an "immutable" keyword as a possibility in a
future standard or if the committee feels that const fits the bill
adequately and entirely.

It is unneeded. If i need only immutable objects then i make classes
that do not have any methods to mutate the instances. Plain and
simple.

In C++ one will always be able to cast anything to anything if he
knows what he does. He can still reinterpret my immutable object into
pile of chars and hack there but then it is his fault if something
fails.
 
J

Juha Nieminen

MikeP said:
Is immutable better than const? I mean "immutable" like in C#. At least
one book author opines that it is superior to C++ "const" because
const-ness can be cast away. What is your opinion on the matter?

Can casting constness away be misused? Yes.

Is casting constness away being misused by incompetent programmers in
situations where significantly better solutions exist? Yes.

Should the language patronize competent programmers who know perfectly
well what they are doing and only cast away constness when it's absolutely
necessary or somehow useful, by absolutely forbidding it? That's where
opinions will differ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top