On Wed, 29 Jul 2009 15:00:42 -0400, Ary Borenszweig <a...@esperanto.org.ar>
wrote:
Steven Schveighoffer Wrote:
On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig
<a...@esperanto.org.ar>
wrote:
> Steven Schveighoffer wrote:
>> On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig
>> <a...@esperanto.org.ar> wrote:
>>
>>> a.b.c = d;
>>>
>>> If b is anything that has a struct type, and c is anything else, the
>>> statement must report an error.
>> struct S
>> {
>> int *x;
>> void c(int n) {*x = n;}
>> }
>> struct S2
>> {
>> int n;
>> S b() { return S(&n);}
>> }
>> void main()
>> {
>> S2 a;
>> a.b.c = 5;
>> }
>> Why should this not be allowed?
>
> Because in the general case it might not work.
>
> It's simple: if you disallow it, no bugs caused because of this can
> exist. If you don't disallow it, sometimes it might work, sometimes it
> won't work. Which option do you prefer as a programmer?
I prefer to have the power to create whatever I want without the
compiler
telling me incorrectly that it won't work.
why allow any programming at all? The programmer might write incorrect
code!
-Steve
I reply using the web page because Thunderbird gives me a Bad Request
error (very strange).
I retracted my original message (just found out how to do that), because I
wrote "...without the telling me..." instead of "...without the *compiler*
telling me..."
You probably tried to reply to my original message ;)
The cases where you do:
a.b.c = 3;
where b is a struct are probably few
Let's not forget that structs are the vehicle to extend the type system.
I want to make my own pointer type, it has to be a struct. You're going
to predjudice the compiler against my wrapper types because I *might* do
something that confuses people.
and most of the time they lead to incorrect result, such as the Widget
and Rectangle examples, and many others.
In fact, this is the *only* example I've seen. It leads me to believe we
need a better approach to widgets and rectangles more than a better
approach to properties. Like maybe making Rectangles and Points
immutable? I think that's how C# does it.
So I prefer the compiler to tell me "Look, b is a struct, please make
sure you know what you are doing". And I can tell you, most of the time
you'll say "Thanks, compiler, I didn't notice that!". If the compiler is
wrong, you just do:
auto x = a.b;
b.c = 3;
and that's it. No big deal.
It is a big deal. Ever used Vista? It has a similar conservative
approach to security. It makes Vista unusable in my opinion.
-Steve