Back to all reviewers

Parameterize hardcoded API values

commaai/openpilot
Based on 2 comments
Other

When designing APIs or interfaces, avoid hardcoding string literals, configuration values, or identifiers that could be made configurable through parameters. This makes the API more flexible, reusable, and maintainable by allowing callers to specify their own values rather than being locked into fixed behavior.

API Other

Reviewer Prompt

When designing APIs or interfaces, avoid hardcoding string literals, configuration values, or identifiers that could be made configurable through parameters. This makes the API more flexible, reusable, and maintainable by allowing callers to specify their own values rather than being locked into fixed behavior.

Hardcoded values in APIs create tight coupling and reduce reusability. Instead, expose these values as parameters in your interface design, allowing different use cases to be supported without code changes.

Example of the problem:

// Bad: hardcoded "thumbnail" string
pm.reset(new PubMaster({encoder_info.publish_name, "thumbnail"}));

Better approach:

// Good: parameterize the thumbnail name through EncoderInfo
pm.reset(new PubMaster({encoder_info.publish_name, encoder_info.thumbnail_name}));

This principle applies to API endpoints, configuration keys, default values, and any identifier that might need to vary across different contexts or use cases. By parameterizing these values, you create more flexible interfaces that can adapt to different requirements without requiring code modifications.

2
Comments Analyzed
Other
Primary Language
API
Category

Source Discussions