Refactor: config_create() 11-parameter constructor is unmaintainable #150
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The
config_create()function insrc/shared/config.c(line 12) takes 11 positional parameters — a mix ofchar*,bool, andint. At the call site inclient_cli.c:77-78, the argument list spans two lines and is nearly impossible to read correctly without counting parameters:This is fragile: adding a new field reorders or shifts all subsequent arguments, and nothing prevents the wrong
false/NULLfrom being passed in the wrong slot. Every time a new field is added to theConfigstruct, this constructor signature must change.A better approach would be:
Configinitializer macro.Location
src/shared/config.c:12-57andsrc/client/client_cli.c:77-78Suggested Fix
Replace the 11-parameter constructor with:
Config* config_create_default(void)that returns a config with all defaults.#define CONFIG_INIT { .version = str_dup(PROTOCOL_VERSION), .compression_level = 5, ... }This eliminates the risk of parameter misordering and makes call sites self-documenting.
Severity
Medium
Category
Quality / Maintainability