Date: Tue, 29 Oct 2024 19:49:09 -0500
> pmanager->GetDevice()->GetChan
nel(0)->GetLowPassFilter()->GetCodecName();
Thanks for sharing the motivation. This feels a lot like the monadic
operations introduced to things like std::optional in C++23. Given
that there are reasonable ways to achieve this sort of thing in the
language (various wrapping objects / smart pointer approaches, what
Thiago said with a default device, etc) I think those should be
preferred over allowing member function invocation on null pointers
which would be a counter-intuitive, error-prone, and a drastic change
to the language.
Cheers
Jeremy
On Tue, Oct 29, 2024 at 3:20 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Tue, Oct 29, 2024 at 5:01 PM Jeremy Rifkin via Std-Proposals wrote:
> >
> > Do you have a concrete example of a problem that could be uniquely
> > solved by being able to call a member function on a null pointer? My
> > gut feeling is that this is an anti-pattern and symptom of bad design
> > however, I might not be considering all possible use cases.
>
>
> Well what came to mind for me first was where you have code like the following:
>
> string GetCodecName(Manager *const pmanager)
> {
> if ( nullptr == pmanager ) return {};
> auto *const pdev = pmanager->GetDevice();
> if ( nullptr == pdev ) return {};
> auto *const pchannel = pdev->GetChannel(0);
> if ( nullptr == pchannel ) return {};
> auto *const plow = pchannel->GetLowPassFilter();
> if ( nullptr == plow ) return {};
> return plow->GetCodecName();
> }
>
> You could replace it with:
>
> string GetCodecName(Manager *const pmanager)
> {
> return pmanager->GetDevice()->GetChannel(0)->GetLowPassFilter()->GetCodecName();
> }
>
> That's the kind of lines I was thinking along.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
nel(0)->GetLowPassFilter()->GetCodecName();
Thanks for sharing the motivation. This feels a lot like the monadic
operations introduced to things like std::optional in C++23. Given
that there are reasonable ways to achieve this sort of thing in the
language (various wrapping objects / smart pointer approaches, what
Thiago said with a default device, etc) I think those should be
preferred over allowing member function invocation on null pointers
which would be a counter-intuitive, error-prone, and a drastic change
to the language.
Cheers
Jeremy
On Tue, Oct 29, 2024 at 3:20 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Tue, Oct 29, 2024 at 5:01 PM Jeremy Rifkin via Std-Proposals wrote:
> >
> > Do you have a concrete example of a problem that could be uniquely
> > solved by being able to call a member function on a null pointer? My
> > gut feeling is that this is an anti-pattern and symptom of bad design
> > however, I might not be considering all possible use cases.
>
>
> Well what came to mind for me first was where you have code like the following:
>
> string GetCodecName(Manager *const pmanager)
> {
> if ( nullptr == pmanager ) return {};
> auto *const pdev = pmanager->GetDevice();
> if ( nullptr == pdev ) return {};
> auto *const pchannel = pdev->GetChannel(0);
> if ( nullptr == pchannel ) return {};
> auto *const plow = pchannel->GetLowPassFilter();
> if ( nullptr == plow ) return {};
> return plow->GetCodecName();
> }
>
> You could replace it with:
>
> string GetCodecName(Manager *const pmanager)
> {
> return pmanager->GetDevice()->GetChannel(0)->GetLowPassFilter()->GetCodecName();
> }
>
> That's the kind of lines I was thinking along.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-10-30 00:49:22