[swift-evolution] Thoughts on clarity of Double and Float type names?

Brent Royal-Gordon brent at architechies.com
Thu Jan 7 21:26:07 CST 2016


> What perceived problem are you solving?

Here are the problems I see it solving:

- **Swift makes no recommendations about which floating-point type to use.** Integer types have a clear recommendation: use Int unless you have a compelling reason to use something else. Which float type should you use? Swift just kind of shrugs. This is especially ugly because Swift is so strict about mixing numeric types; by making no recommendation, Swift encourages people to create systems with inconsistent numeric types that require more conversions. And conversions are especially dangerous in floating-point types which are by their nature imprecise.

- **`Double` is a meaningless name unless you come from a C-style background.** This is particularly true for learners. With `Float`, you can at least explain that the type name is short for "floating point", which is the way the number is represented in the computer. But `Double`? Why is `Double` a double-precision float, not a double-wide integer, or a UTF-16 string, or something? Why isn't it a generic type representing a pair of same-typed instances? Unlike, for instance, `switch`/`case`/`default`, where these are plausible names you might pick even without C's influence, `Double` is pure C jargon.

- **The naming of float types is unrelated to the naming of integer types.** Swift's integer types have a rationalized, ergonomic naming scheme. Swift's float types have a haphazard naming scheme. It just doesn't feel like the same language. By matching the floating-point types' naming scheme to the integer types, you can bring your knowledge of the integer types over to the floating-point types.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list