APIs should provide convenient methods that handle common operations directly, rather than requiring users to write helper functions or use verbose patterns. This improves developer experience and reduces boilerplate code.
Key principles:
Example of good API design:
# Good: Simple constructor with direct parameter passing
CC = car.CarControl(cruiseControl={'cancel': True})
# Avoid: Verbose chaining that could be simplified
CC = car.CarControl.new_message(cruiseControl={'cancel': True})
test_car_controller(CC.as_reader())
When designing APIs, consider what the most common use cases will be and optimize the interface for those scenarios. If you find yourself writing helper functions or seeing users write repetitive boilerplate, that’s a signal the API could be more convenient.
Enter the URL of a public GitHub repository