Immutable better than const?

Discussion in 'C++' started by MikeP, May 14, 2011.

  1. MikeP

    MikeP Guest

    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?
     
    MikeP, May 14, 2011
    #1
    1. Advertising

  2. MikeP

    MikeP Guest

    Pete Becker wrote:
    > On 2011-05-14 12:52:12 -0400, 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?

    >
    > <shrug>


    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.
     
    MikeP, May 14, 2011
    #2
    1. Advertising

  3. On 5/14/2011 12:59 PM, MikeP wrote:
    > Pete Becker wrote:
    >> On 2011-05-14 12:52:12 -0400, 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?

    >>
    >> <shrug>

    >
    > 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
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, May 14, 2011
    #3
  4. MikeP

    Öö Tiib Guest

    On May 14, 7:59 pm, "MikeP" <> wrote:
    > Pete Becker wrote:
    > > On 2011-05-14 12:52:12 -0400, 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?


    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.

    > > <shrug>

    >
    > 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.
     
    Öö Tiib, May 15, 2011
    #4
  5. MikeP <> wrote:
    > 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.
     
    Juha Nieminen, May 15, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajax Chelsea
    Replies:
    3
    Views:
    16,905
    Ajax Chelsea
    Dec 5, 2003
  2. Peter Bencsik
    Replies:
    2
    Views:
    839
  3. Replies:
    11
    Views:
    1,109
  4. Javier
    Replies:
    2
    Views:
    568
    James Kanze
    Sep 4, 2007
  5. Replies:
    2
    Views:
    56
    Mark H Harris
    May 13, 2014
Loading...

Share This Page