Ad
  • Default User Avatar

    I have heard opinions that it is best to stick to the standard of the project you work in, so that the new code is written in a similar style, then the code is easier to read. Unfortunately most C/C++ projects are very old, so they are written in different styles, then refactoring the file you are changing looks like a good approach.

  • Custom User Avatar

    Thanks for the quick reply. Makes sense. I overlooked the multiple return statements.

    Do you know if there is a best practice in c++ for single vs multiple returns? Or is that more preference or just debated?

  • Default User Avatar

    I cannot agree with that for the above case.
    Since we have a return in each if, the program will not check the next conditions. So using an else if here will have the same effect and it only increases the length of the code and may only be puzzling for the reader of the code why some put else keyword.

  • Custom User Avatar

    Wouldn't it be more efficient to use "else if" statements. This would require all statements to be run, where else if would stop once a match was found.