constant references

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Gideon

    #31
    Re: constant references

    On Feb 5, 7:36 am, "Zytan" <zytanlith...@y ahoo.comwrote:
    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.AsReadOn ly" 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.AsReadOnl y(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
    Zytan,

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

    Brian


    Comment

    • Herfried K. Wagner [MVP]

      #32
      Re: constant references

      "Zytan" <zytanlithium@y ahoo.comschrieb :
      >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.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • Zytan

        #33
        Re: constant references

        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

        Comment

        Working...