C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Possible deprecation of -> operator

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Fri, 31 Jan 2025 11:37:32 +0100
On 31/01/2025 11:22, Filip via Std-Proposals wrote:
> Are there any good reasons to keep that syntax?

IMNSHO there's a very strong coding convention / software engineering
reason: it makes the reader of the code aware that they are accessing
something which may be null/empty/..., so they need to check whether
this is actually safe to do before doing it.

This is true for raw pointers (may be null), but also for smart
pointers, optional, etc. (for which, by the way, you'll need to continue
to use operator->).

Consider:

use(obj->data); // `obj` may be null, did I check for it?
use(obj.data); // always safe


And if you go all in:

use(obj.priv.engine.paramA.speed)

where some of those `.` may or may not be performing an indirection, are
you positive you did all the checks you needed to do?


My 2 c,
--
Giuseppe D'Angelo

Received on 2025-01-31 10:37:37