constant references

  • Thread starter Thread starter Zytan
  • Start date Start date
Have you tried using ByRef? Look up passing variables ByRef for
VB .NET.

This would even be dangerous because it allows the method to change the
reference passed to the method in the parameter! 'ByVal' and 'ByRef' are
not really related to the OP's problem, although 'ByVal' is much more
appropriate here.
 
Stephany Young said:
Well, all I can really say is ...

If you need the features exposed by the C++ language and the C++ compiler
so badly then I don't understand why you are not using that instead of
bleating on about something that just "ain't gonna happen".

Hm... I think it's interesting that someone shows his/her interest in
functionality similar to 'const'. I believe that adding a similar concept
to .NET has been considered, but maybe it's worth to reconsider it.
 
You get no argument from me on that count Herfried.

I was responding to the OP's rant that basically was saying that VB.NET was
unusable because it didn't have this particular 'feature' and that it had to
be 'fixed' immediately.

I have no problem at all about a debate on whether or not such a concept
should or shouldn't be included in a future relase of the language.
 
Zytan,

Before I wrote this I have looked at the calendar, and it is really 2007.

I thought that I was back in 1967 while I was reading your response.

Although I agree with you in concept is it now much to late start again a
discussion.

As the Arabs had than won the Arab-Isrealy war, than a lot of things would
probably look different now, however you cannot change history (beside in
the schoolbooks of course).

Cor
 
I know I am a little late in joining this discussion, but I was just reading
something in the documentation that may be of some help - not sure since I
have not tried it yet. New to the .Net Framework version 2 is the
"Array.AsReadOnly" Generic Method that retrurns a read-only wrapper for the
specified array. So if you passed the original array (reference) byval, the
first line of code could be something like:
TheArray = Array.AsReadOnly(TheArray) ' assuming the param was "TheArray"
Then it seems to me that the compiler should find and flag any attempts to
modify the array. And of course, the byval keeps the original reference from
being modified.
I am fairly new to .net myself, so maybe I am on the wrong track here, but
it sounds like it should work.
 
Hm... I think it's interesting that someone shows his/her interest in
functionality similar to 'const'. I believe that adding a similar concept
to .NET has been considered, but maybe it's worth to reconsider it.

My point exactly, Herfried. My original post was how to replicate the
functionality, since VB does have "Const" in some parts of the
language. Since discovering it cannot be replicated in full, it is
certainly a legitimate point to raise concern that this feature should
be added for the numerous benefits I have mentioned. Unfortunately,
since most people have never made use of such features, even when they
are using languages that support them. So, they wouldn't really "get"
why it is so invaluable. I made effort to explain most of the major
reasons pretty clearly (there are more, such as how "const" protects
code from improper changes of OTHER programmers not-in-the-know, or
even yourself 6 months from now when you've forgotten how some
function works). But, it's hard for people to listen when they think
I am attacking their language. I am pointing out its weaknesses,
yes. This is how change begins. I do the same with all languages I
use. I guess, also, you don't miss anything you've never had. I
didn't care that all languages didn't have "const" functionality until
I used it. People here are acting like the old me. But, I listened
when someone said I should be using "const", and I started using it.
In this manner, I stumbled upon how useful it was -- I couldn't
possibly have known every benefit it brought without using it
personally (although most of them were found by listening to others).
I wish you all could share this experience. Maybe that's why
intelligent people have said programmers should learn a new language
every year... I should try that. There's probably tons of things I
am missing that I don't realize, yet.

Zytan
 
Stephany,
You get no argument from me on that count Herfried.

Herfried is agreeing with me that it is useful to considering new
language features.

I have no problem at all about a debate on whether or not such a concept
should or shouldn't be included in a future release of the language.

Now you are agreeing with me. We are currently HAVING such a debate.

I was responding to the OP's rant that basically was saying that VB.NET was
unusable because it didn't have this particular 'feature' and that it had to
be 'fixed' immediately.

I said VB .NET is unusable, and must be fixed immediately... because
it doesn't have "const"!?
Unbelievable.
My discussion with you ends now.

Zytan
 
Cor,
Before I wrote this I have looked at the calendar, and it is really 2007.

I thought that I was back in 1967 while I was reading your response.

Although I agree with you in concept is it now much to late start again a
discussion.

As the Arabs had than won the Arab-Isrealy war, than a lot of things would
probably look different now, however you cannot change history (beside in
the schoolbooks of course).

Thanks for the insults.

You're telling me that the... compiler... cannot do *compile time
checks* to ensure a variable is NOT changed inside of a function?

Exactly what history must be changed in order for someone to improve
the compiler?

Maybe if we all edit wikipedia, perceived history will change, and
someone will realize it is actually possible, and then someone will
improve the compiler.

Zytan
 
Terry,
I know I am a little late in joining this discussion, but I was just reading
something in the documentation that may be of some help - not sure since I
have not tried it yet. New to the .Net Framework version 2 is the
"Array.AsReadOnly" Generic Method that returns a read-only wrapper for the
specified array. So if you passed the original array (reference) byval, the
first line of code could be something like:
TheArray = Array.AsReadOnly(TheArray) ' assuming the param was "TheArray"
Then it seems to me that the compiler should find and flag any attempts to
modify the array. And of course, the byval keeps the original reference from
being modified.

Thanks for the reply. Branco mentioned this earlier, and he claimed
that it still would only be caught at run time. I am not sure, I'd
have to test and see. But, this is better than nothing. And it's
better than proxy objects because it is specifically designed for
this, needing much less code. I'll give it a shot.

Thanks,

Zytan
 
New to the .Net Framework version 2 is the
"Array.AsReadOnly" Generic Method that returns a read-only wrapper for the
specified array.

This works, but note that the result is a collection. It is not
something you can just drop into existing code.

Zytan
 
Terry,


Thanks for the reply. Branco mentioned this earlier, and he claimed
that it still would only be caught at run time. I am not sure, I'd
have to test and see. But, this is better than nothing. And it's
better than proxy objects because it is specifically designed for
this, needing much less code. I'll give it a shot.

Thanks,

Zytan

Zytan,

ReadOnlyCollection is a proxy object because it can masquerade as an
IList like the original collection. The read-only check is performed
at runtime.

Brian
 
Zytan said:
Before I wrote this I have looked at the calendar, and it is really 2007.

I thought that I was back in 1967 while I was reading your response.

Although I agree with you in concept is it now much to late start again a
discussion.

As the Arabs had than won the Arab-Isrealy war, than a lot of things
would
probably look different now, however you cannot change history (beside in
the schoolbooks of course).
[...]
Exactly what history must be changed in order for someone to improve
the compiler?

The 'const' attribute could be stored as an attribute in the parameters'
metadata, similar to how it is done for optional parameters and parameter
default values. That's not the problem.

The main problem I see is that the .NET Framework's class library currently
does not make use of such an attribute, but this would be crucial for its
overall success because most of the code makes calls to this class library.
In addition, all 3rd-party code would have to be reworked to make use of
const-correctness.
 
Herfried,
The 'const' attribute could be stored as an attribute in the parameters'
metadata, similar to how it is done for optional parameters and parameter
default values. That's not the problem.

Ok. That was my understanding.

The main problem I see is that the .NET Framework's class library currently
does not make use of such an attribute, but this would be crucial for its
overall success because most of the code makes calls to this class library.
In addition, all 3rd-party code would have to be reworked to make use of
const-correctness.

In my experience with C++, I've made use of the Win32 API which is
written in C, which doesn't use "const" (please correct me if I am
wrong). But, I still implemented "const" myself, for my own
libraries, and derived a benefit from them.

But, I do see your point. If almost ALL of the program's data is
passed to library calls, and this data disallows change, the library
functions will complain that they are expected data they are allowed
to modify.

However, consider a next generation .NET could implement "const" --
even only partially -- to the library, without any detriment to
existing code. A function that never changed its parameter data will
not care that it is no longer allowed to change it. Also, such
functions will continue to accept ANY type of data (readonly or not).
VB programmers could continue on with no knowledge of the changes...

No major internal architectures must change to make this happen, as we
seen with the VB6 to VB.NET switch. And, it can be introduced
incrementally. This is Good News.

Zytan
 
Back
Top