Skip to main content
Code Review

Return to Answer

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytimeevery time you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbilityreadability benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually every time you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readability benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

Added a note about copy-then-move.
Source Link
Morwenn
  • 20.2k
  • 3
  • 69
  • 132

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

There are several small things that you can easily improve:

  • Tell me if I am mistaken, but it seems that the macro PNEU_EXCEPT_TO_METHODRES needs some trailing while (0) if you don't want to add it manually everytime you invoke it.

  • In MethodResult, you explicitly defaulted the copy constructor and the destructor. You could actually totally get rid of these lines by using the rule of zero: don't write any copy/move constructors/operators, and the compiler will generate them for. Unless you intend to make a non-copyable class or a RAII one, you generally want to use the rule of zero.

  • If you want to copy a string, don't pass it by const&, but use the copy-then-move idiom instead:

     MethodResult(bool ok, std::string desc)
     :
     fOk(ok),
     fDescription(std::move(desc)) { }
    
  • The function trailing return type is fine, but if you want to get the readbility benefits, you can put the type name on the following line. That really helps to visually separate the return type and avoids having overly long function declarations. That said, it is most useful when you have long template types.

     static auto ok()
     -> MethodResult
     {
     return MethodResult(true, "");
     }
    

    Note that I did not chose the best function to prove my point. However, this allows to split long declarations in two lines and still have both the function names and the return types aligned. Example with Window class declaration:

     auto update()
     -> void;
     auto pollEvents()
     -> void;
     auto renderFrame()
     -> void;
    

    The obvious drawback is of course the fact that the declaration now takes two lines. There is a choice to make, and it is yours.

  • You can use list initialization in a return statement when you create and return an object and the same line. That will help avoiding to repeat the type:

     static auto ok()
     -> MethodResult
     {
     return { true, "" };
     }
    
  • Two small things concerning your main: don't bother to add argc and argv if you are not going to use them. You don't have to write return 0; at the end of main; if the compiler reaches the end of main without having encountered a return statement, it will automatically add a return 0;.

Source Link
Morwenn
  • 20.2k
  • 3
  • 69
  • 132
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /