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

Improve readibility of method command via modular helper functions #1129

Closed
mitzimorris opened this issue Nov 15, 2022 · 0 comments · Fixed by #1134
Closed

Improve readibility of method command via modular helper functions #1129

mitzimorris opened this issue Nov 15, 2022 · 0 comments · Fixed by #1134

Comments

@mitzimorris
Copy link
Member

Summary:

Function command in the CmdStan interface in file command.hpp is 900+ lines long.
Refactor into per-method helper functions in file command_helper.hpp.

Whenever possible, use method get_arg_val when checking command arguments to improve code readibility.

Description:

The function command translates the command line arguments into calls to the core Stan services layer.

int command(int argc, const char *argv[]) {

This command is 900+ lines long. Running Cpplint on this results in the following:

src/cmdstan/command.hpp(1127): error cpplint: [readability/fn_size] Small and focused functions are preferred: command() has 951 non-comment lines (error triggered by exceeding 500 lines). [1]

The (relatively) new function get_arg_val

template <typename caster, typename List, typename... Args>
inline constexpr auto get_arg_val(List &&arg_list, Args &&... args) {
return dynamic_cast<std::decay_t<caster> *>(get_arg(arg_list, args...))
->value();
}
greatly improves code readibility; use this whenever possible.

Additional Information:

This refactor will not in any way change the interface behavoir, but it might make the code easier to maintain.

Current Version:

v2.30.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant