Re: Anders Hejlsberg comment on immutable objects
From: Magnus Lidbom (magnus_lidbom_at_hotmail.com)
Date: 02/09/04
- Next message: Daniel O'Connell [C# MVP]: "Re: C# Standard and UserControls"
- Previous message: Ted Sung: "why do these 2 ways of invoking an external C function work?"
- In reply to: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Next in thread: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Reply: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 09 Feb 2004 19:55:46 +0100
On Mon, 9 Feb 2004 18:45:01 +0100, "Martin Maat [EBL]"
<dummy@somewhere.nl> wrote:
>"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
>news:MPG.1a91c58586299a9298a098@msnews.microsoft.com...
>> Martin Maat [EBL] <dummy@somewhere.nl> wrote:
>
>> > If I pass in a simple type by reference I typically want it to be
>changed.
>> > Had this not been my intent, I would have passed it by value. C# has ref
>and
>> > out for those purposes and they serve us well.
>
>> No they don't, because just passing in a reference by value doesn't
>> mean that the object it refers to won't be changed. Don't forget that
>> you never actually pass objects as parameters in C#.
>
>I was discriminating between simple types and objects, simple types being
>integer, DateTime and such. I got to the objects in the next paragraph.
>
>> For instance, take Array.Sort(Array). That doesn't change the
>> *parameter*, but it *does* change the array itself.
>
>If you are worried about this you don't make the argument a type that
>supports methods that can be used to change the object. This is a good
>example of a situation where a read interface does help out. If the
>interface offers only an indexed get property, the server method will be
>able to read the byte array, not change it. Only if you can't be bothered
>and trust the server method, you simply pass the full blown object.
I wrote a post, with a short comparison of const and read only
interfaces, not long ago that you may find enlightening:
>> Also, your argument doesn't extend to properties and return values - if
>> something returns a byte array, am I free to alter that or not?
>
>I wasn't considering return values but the same applies. If you intend to
>return an object with the sole purpose of providing information to the
>client, you should return a limited interface, not the object itself. It
>will be clear at least, the client will not have to wonder if it may change
>the object or not. I am not saying there will be no way to hack around it.
>
>As you pointed out with your examples it is hard to define what should be
>considered change, what is a violation of a const contract.
Not really. He just pointed out the fact that you must distinguish the
parameter from the object referenced by the parameter in the case of
reference type parameters, and that the ref and out keywords doesn't
help in managíng access to that object.
> With any complex
>type that is quite impossible,
>not only technically but even more so
>semantically. To what does the contract extend if you have contained and
>agrigated objects? I believe this is the shadow world Anders was refering
>to.
I've never seen or heard of any such impossibilities. How const
applies to aggregated objects has always seemed perfectly logical and
infinitely extensible to me. Could you provide a concrete example?
/Magnus Lidbom
- Next message: Daniel O'Connell [C# MVP]: "Re: C# Standard and UserControls"
- Previous message: Ted Sung: "why do these 2 ways of invoking an external C function work?"
- In reply to: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Next in thread: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Reply: Martin Maat [EBL]: "Re: Anders Hejlsberg comment on immutable objects"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|