Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize approach for passing string parameters in VTK and Qt classes #7622

Open
jcfr opened this issue Mar 5, 2024 · 0 comments
Open
Labels
Type: Enhancement Improvement to functionality
Milestone

Comments

@jcfr
Copy link
Member

jcfr commented Mar 5, 2024

Is your feature request related to a problem? Please describe.

The function parameters of type std::string and QString are not consistently passed, this leads to inconsistent API and related discussions1

To both spare review cycles and also improve the developer experiences, we should develop guidelines suggestion which approach should be used.

This will also be helpful when refactoring existing one that has been using char* parameters.

In a nutshell:

void doSomething(std::string parameter);
void doSomething(QString parameter);

vs

void doSomething(const std::string& parameter);
void doSomething(const QString& parameter);

Describe the solution you'd like

Use of const references

Consistently using const std::string& parameter and const QString& parameter

In addition of avoiding unnecessary copy, it also indicates that the uidName parameter will not be modified within the function.

Use of pass by value with std::move

Describe alternatives you've considered

Additional context

Use of std::string vs const std::string&

As of 5e831bc, the use of std::string vs const std::string& is distributed ...

$ ack --headers "\(.+std::string \w+" --no-filename | wc -l
108

$ ack --headers "const std::string\& \w+" --no-filename | wc -l
199

Use of QString vs const QString&

As of 5e831bc, the use of const QString& is dominant:

$ ack --headers "\(.+QString \w+" --no-filename | wc -l
47

$ ack --headers "const QString\& \w+" --no-filename | wc -l
491

Footnotes

  1. https://github.com/Slicer/Slicer/pull/7616#discussion_r1510816301

@jcfr jcfr added the Type: Enhancement Improvement to functionality label Mar 5, 2024
@jcfr jcfr added this to the Backlog milestone Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvement to functionality
Development

No branches or pull requests

1 participant