In Bloch’s presentation, he said designer should look for good power-to-weight ratio for API. Moreover, he also stressed that ‘Conceptual weight more important than bulk’. I guess the weight is for ‘Conceptual weight’, bulk is for number of methods of a class.
But I couldn’t understand what ‘Conceptual weight’ is, what ‘power-to-weight ratio’ is. Welcome to any explanation!
Bloch gave an example: List.subList()
has good 'power-to-weight ratio'. If clients wants to know an index of a sub list, he doesn't need to call a low 'p2w ratio' method indexOfSubList(a,b,e)
, instead, he could call List.subList(a,b).indexOf(e)
. Bloch thought this is 'power-to-weight ratio'.
Origin:
API Should Be As Small As Possible But No Smaller
Power-to-weight ratio is a measurement of actual performance of any engine or power source. It is also used as a measurement of performance of a vehicle as a whole, with the engine's power output being divided by the weight (or mass) of the vehicle, to give a metric that is independent of the vehicle's size.
Your power-to-weight ratio can be calculated as watts (W) divided by your body weight in kilograms (kg), expressed as W/kg.
The Koeniggsegg One:1 has a power-to-weight ratio of 1:1, meaning that for every kilogram it weighs, it generates 1 horsepower.
The thrust-to-weight ratio and wing loading are the two most important parameters in determining the performance of an aircraft. For example, the thrust-to-weight ratio of a combat aircraft is a good indicator of the maneuverability of the aircraft. The thrust-to-weight ratio varies continually during a flight.
I'd interpret "conceptual weight" as the number of abstract concepts you have to learn and understand to use the API. Concepts usually map to public classes, while classes that are not public add to the bulk but not to the conceptual weight.
So if you put it technically, an API has a high conceptual weight if a typical client of the API has to explicitly use a lot of classes belonging to the API to work with it.
"good power-to-weight ratio" then means the API should use as few public classes as possible to offer as much functionality as possible. That means an API should:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With