You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Adam Hunyadi (Jira)" <ji...@apache.org> on 2021/02/08 09:59:00 UTC

[jira] [Resolved] (MINIFICPP-1264) Add getter interface helper

     [ https://issues.apache.org/jira/browse/MINIFICPP-1264?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adam Hunyadi resolved MINIFICPP-1264.
-------------------------------------
    Resolution: Won't Fix

Not fixed, we should extend the interfaces for the commonly used getters instead.

> Add getter interface helper
> ---------------------------
>
>                 Key: MINIFICPP-1264
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-1264
>             Project: Apache NiFi MiNiFi C++
>          Issue Type: Improvement
>    Affects Versions: 0.7.0
>            Reporter: Adam Hunyadi
>            Priority: Minor
>              Labels: MiNiFi-CPP-Hygiene
>             Fix For: 0.9.0
>
>
> *Background:*
> In our codebase we have quite a lot of getter functions that follow this signature:
> {code:c++|title=Current Interface}
> void getMemberField(Type& argToModify);
> bool getNullableMemberField(OtherType& argToModify);
> {code}
> Most developers would much rather use an interface that looks like this though:
> {code:c++|title=Proposed Interface}
> Type& getMemberField();
> const Type& getMemberField();
> optional<OtherType> getNullableMemberField();
> {code}
> The problem with the former version is that in some cases it makes the code unnecessary verbose. An example from our codebase:
> {code:c++|title=Example}
>  # Version 1
>  utils::Identifier sourceUuid;
>  source->getUUID(sourceUuid);
>  connection->setSourceUUID(sourceUuid);
>  # Version 2
>  connection->setSourceUUID(source->getUUID(sourceUuid));
> {code}
> Unfortunately more ofthen than not this is the exact pattern the getters appear in.
> *Proposal:*
>  As we do not want to break API, we cannot change the getters. However, we can resort to implementing a helper utility. A godbolt implementation for a convenience function is available here:
> [[Proof of Concept]|https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAM1QDsCBlZAQwBtMQBGAFlICsupVs1qhkAUgBMAISnTSAZ0ztkBPHUqZa6AMKpWAVwC2tLgDZSW9ABk8tTADljAI0zEuAZlI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uAADjMeGPAATm4VZJHpjx6bZoQ4e4JGUbR0gMYGJGvtWUgSdR6HSDgWAYEQFBUHnPB2DICgIDQVX1ZQYRRE4VYjdIKg1e9YgvogZw4aJ0hnDsTIXhtpHtb%2BehOVoVgnZl0gsG20R2FJpH8COYp0S%2Bn3MAADyKR5BmF1VlGdoQ8GcYhHb0LAg6lhYjGdroaHoJg2A4Hh%2BEEfWxGxmQU%2BcL7YErEAG1YUh0XcZ5vXJkWYUCCOAFpfxsiQZDkThhQmPvOQ8cW32KDQICsBo8i8KxWiqdwLF8fxYSXmot8iWg17iaoCln2FSnqfRchqQo59oC/yjsSpj435pL5CZe38fmJ15AMwugUHjfoXAYZw0RsjbOoso6Mz7mYbgExAwXkNlWVYKCJgQFwIQXKwxOD5j0DrNwUxCY6ixiPGQxMg5d0pvDSWsMBgC1IHnOBKD6aOnhvDYUwpDarDgcKCBPtRbixAJLaWZM5aKwgEgHoBBvCPHIJQbW3g1bVFwZgfAmJBCF0YCwQO9NSAAHd07eHznzBGgtIFwxwRMfRhAEATGgWYWB8DEGGmQag4WojoZdAQMcLA7grKmIYXnDw8Mqws04PTYU1NJCcxZizEJvAhbozhkIkRlCKYgHYVWYU8NEjcDMKseGLMuFmFwXQ6e/DhaCKluk0xkhzECJSTUmWXc27%2BA0NwIAA%3D%3D]
> We can introduce this and simplify later usages of getters.
> With this, the syntax would simplify to:
> {code:c++|title=Using a helper}
>  connection->setSourceUUID(ReturnVal(source, &Processor::getUUID));
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)