This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
spec:om-apis [2012/01/25 14:46] – created TabAtkins | spec:om-apis [2012/01/26 16:06] – tabatkins | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Use Strings, not Numeric Constants ===== | ===== Use Strings, not Numeric Constants ===== | ||
- | When an API needs to take or return an enumerated value, many older APIs follow the C convention and use numeric constants, stored on some interface object. | + | When an API needs to take or return an enumerated value, many older APIs follow the C convention and use numeric constants, stored on some interface object. |
An anti-example can be found in CSSTransformValue, | An anti-example can be found in CSSTransformValue, | ||
Line 8: | Line 8: | ||
- it is much longer to type than a string like " | - it is much longer to type than a string like " | ||
- the name of the constant is different than the name of the function it corresponds to, while a string can be the same. | - the name of the constant is different than the name of the function it corresponds to, while a string can be the same. | ||
- | - simply printing or storing the value reveals an opaque integer, which can't be translated back into a transform type without testing against every constant | + | - simply printing or storing the value reveals an opaque integer |
- long experience shows that, given the choice of using a named constant or an integer, authors will end up using the integer form instead, often due to cargo-cult "speed improvements" | - long experience shows that, given the choice of using a named constant or an integer, authors will end up using the integer form instead, often due to cargo-cult "speed improvements" | ||