You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/09/18 08:21:32 UTC

[GitHub] [nifi-minifi-cpp] hunyadi-dev opened a new pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

hunyadi-dev opened a new pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911


   Simple change extracted as separate commit, so that further changes will be easier to review.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911#discussion_r542421625



##########
File path: libminifi/include/core/FlowFile.h
##########
@@ -129,7 +130,9 @@ class FlowFile : public core::Connectable, public ReferenceContainer {
    * @param value value to set
    * @return result of finding key
    */
-  bool getAttribute(std::string key, std::string& value) const;
+  bool getAttribute(const std::string& key, std::string& value) const;
+
+  utils::optional<std::reference_wrapper<const std::string>> getAttribute(const std::string& key) const;

Review comment:
       I am not arguing for safety, to plut it blunt I just do not like unnecessary copies.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev closed pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
hunyadi-dev closed pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911#discussion_r542328156



##########
File path: libminifi/include/core/FlowFile.h
##########
@@ -129,7 +130,9 @@ class FlowFile : public core::Connectable, public ReferenceContainer {
    * @param value value to set
    * @return result of finding key
    */
-  bool getAttribute(std::string key, std::string& value) const;
+  bool getAttribute(const std::string& key, std::string& value) const;
+
+  utils::optional<std::reference_wrapper<const std::string>> getAttribute(const std::string& key) const;

Review comment:
       Note: An optional of reference handlers should in general be replaced by a non-owning pointer. They have the same semantics, but tooling is better equipped to handle pointers.
   
   `auto` generally means safe value semantics, and it becoming a "serious misuse" is another footgun that reference types currently have to live with. How is this safer otherwise, than returning a const ref or non-owning pointer to const?
   
   (I'm continuing because I want to either convince you that this is better or understand your standpoint and why I'm wrong.)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911#discussion_r490898307



##########
File path: libminifi/include/core/FlowFile.h
##########
@@ -129,7 +130,9 @@ class FlowFile : public core::Connectable, public ReferenceContainer {
    * @param value value to set
    * @return result of finding key
    */
-  bool getAttribute(std::string key, std::string& value) const;
+  bool getAttribute(const std::string& key, std::string& value) const;
+
+  utils::optional<std::reference_wrapper<const std::string>> getAttribute(const std::string& key) const;

Review comment:
       Why reference wrapper? I would avoid returning a reference to some internal data by default because of possible lifetime issues. If there is a certain need for this, I would call the function something else, like `getAttributeRef`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911#discussion_r540307778



##########
File path: libminifi/include/core/FlowFile.h
##########
@@ -129,7 +130,9 @@ class FlowFile : public core::Connectable, public ReferenceContainer {
    * @param value value to set
    * @return result of finding key
    */
-  bool getAttribute(std::string key, std::string& value) const;
+  bool getAttribute(const std::string& key, std::string& value) const;
+
+  utils::optional<std::reference_wrapper<const std::string>> getAttribute(const std::string& key) const;

Review comment:
       +1. 
   
   Moreover I also think that copying a string is not going to be the bottleneck in this software, so for safety reasons I would simply make it a copy. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev closed pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
hunyadi-dev closed pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #911: MINIFICPP-1373 - Add proper FlowFile::getAttribute getter [QoL][mini-PR]

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #911:
URL: https://github.com/apache/nifi-minifi-cpp/pull/911#discussion_r542227113



##########
File path: libminifi/include/core/FlowFile.h
##########
@@ -129,7 +130,9 @@ class FlowFile : public core::Connectable, public ReferenceContainer {
    * @param value value to set
    * @return result of finding key
    */
-  bool getAttribute(std::string key, std::string& value) const;
+  bool getAttribute(const std::string& key, std::string& value) const;
+
+  utils::optional<std::reference_wrapper<const std::string>> getAttribute(const std::string& key) const;

Review comment:
       One needs to call `.value().get()` or `->get()` on an optional of reference handlers. It indeed would be an issue if someone seriously misused `auto` for holding the return value, but otherwise this is even safer than returning a const ref.
   https://godbolt.org/z/jbhf3n
   
   Will change this to **return a copy**  :cry:




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org