Date: Fri, 31 Jan 2025 14:06:20 +0100
Hello,
On 31/01/2025 12:02, Filip via Std-Proposals wrote:
> You’ve got a point with this but shouldn’t it be left to the programmer
> to know what they’re accessing?
That's my point: by using . instead of -> you're hiding that information
to the programmer. The programmer reads this added by a patch:
+ A a = getA();
+ use(a.b.c.d);
and may not realize that b.c is actually b->c, and maybe that required
an extra check that it's not there. The arrow makes the unsafe operation
more visible.
> Maybe a simple syntax should be introduced to help with semi-automatic
> checking if object is dereferencable?
> ‘’’
> try return ptr.innerStruct.member;
> else return defaultValue;
> ‘’’
>
> Which could be sugar syntax checking if everything being accessed by ‘.’
> Operator is dereferencable?
> Possible done like you would normally with if statements?
But there's absolutely nothing "simple" about this syntax (whereas
extending `.` to work on pointers is straightforward, as everyone agrees
on the semantics). See for instance the work in P2561.
C++26 *crossing fingers* will give us optional<T&>, but even that is not
going to be fully usable to express the above, because its monadic
value_or doesn't have reference semantics.
My 2 c,
--
Giuseppe D'Angelo
On 31/01/2025 12:02, Filip via Std-Proposals wrote:
> You’ve got a point with this but shouldn’t it be left to the programmer
> to know what they’re accessing?
That's my point: by using . instead of -> you're hiding that information
to the programmer. The programmer reads this added by a patch:
+ A a = getA();
+ use(a.b.c.d);
and may not realize that b.c is actually b->c, and maybe that required
an extra check that it's not there. The arrow makes the unsafe operation
more visible.
> Maybe a simple syntax should be introduced to help with semi-automatic
> checking if object is dereferencable?
> ‘’’
> try return ptr.innerStruct.member;
> else return defaultValue;
> ‘’’
>
> Which could be sugar syntax checking if everything being accessed by ‘.’
> Operator is dereferencable?
> Possible done like you would normally with if statements?
But there's absolutely nothing "simple" about this syntax (whereas
extending `.` to work on pointers is straightforward, as everyone agrees
on the semantics). See for instance the work in P2561.
C++26 *crossing fingers* will give us optional<T&>, but even that is not
going to be fully usable to express the above, because its monadic
value_or doesn't have reference semantics.
My 2 c,
--
Giuseppe D'Angelo
Received on 2025-01-31 13:06:25