Skip to content

Improve readibility of method command via modular helper functions #1129

Closed
@mitzimorris

Description

@mitzimorris

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions