Re: Using ref
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 08 Jul 2008 09:40:00 -0700
On Tue, 08 Jul 2008 07:42:10 -0700, Ben Voigt [C++ MVP] <rbv@xxxxxxxxxxxxx> wrote:
It doesn't prevent something from being modified in C++ either.
It does, unless the callee goes out of its way to break its contract (i.e.
uses the const_cast keyword to remove the const).
What does it matter _what_ the exception is? The fact is, the exception exists. As long as the exception exists, it's trivial for someone to modify something declared as "const" in this context.
More importantly, a much better way to ensure that a data structure
isn't modified is simply to make that data structure immutable. For
example, the String class is essentially "const" all the time. Works
great.
Not in C++ it isn't. No matter how immutable you make your object, C++ can
still overwrite the innards if you explicitly work to do so.
This isn't a C++ newsgroup. And presumably the OP would just use "const" if they were using C++. So forgive me for not going out of my way to qualify my statements explicitly so that everyone reading them knew they applied to C#, not C++. It never occurred to me that someone would be confused.
The lack of "const" for methods or their parameters doesn't make C#
any more flawed than any of the other languages people use on a daily
basis. It just makes it different from one of them.
If having "const" methods and parameters was such an important
feature, everyone would use C++ and no one would use C#, Java, VB,
etc. Odd, then, that so many people find languages other than C++
preferable, or at the very least, just as useful.
Or maybe it is something they really want, but they want garbage collection
and reflection more.
Like I said, "==>IF<== having 'const' methods and parameters ==>WAS SUCH AN IMPORTANT FEATURE<==...".
The question isn't whether people find it useful at all. It's whether it's important enough for someone to described a language without the feature as "deeply flawed".
It's just stupid to state or imply that "const" is a critical language feature. It obviously isn't, however useful it might be to some people.
Pete
.
- References:
- Using ref
- From: Arjen
- Re: Using ref
- From: Steve Harclerode
- Re: Using ref
- From: Jon Skeet [C# MVP]
- Re: Using ref
- From: Steve Harclerode
- Re: Using ref
- From: Peter Duniho
- Re: Using ref
- From: Steve Harclerode
- Re: Using ref
- From: raylopez99
- Re: Using ref
- From: Peter Duniho
- Re: Using ref
- From: raylopez99
- Re: Using ref
- From: Peter Duniho
- Re: Using ref
- From: raylopez99
- Re: Using ref
- From: Peter Duniho
- Re: Using ref
- From: Ben Voigt [C++ MVP]
- Using ref
- Prev by Date: Re: repeat character
- Next by Date: Re: Control.BeginInvoke is NOT fire-and-forget
- Previous by thread: Re: Using ref
- Next by thread: Re: Using ref
- Index(es):
Relevant Pages
|