[swift-evolution] Thoughts on clarity of Double and Float type names?
Alex Johnson
ajohnson at quickleft.com
Mon Jan 4 14:58:01 CST 2016
Hi all,
I'm curious how other members of the Swift community feel about the clarity
of the "Double" and "Float" type names. It seems incongruous that the
default type for integers is "Int", but the default type for floating point
numbers is not "Float".
What if the name "Float" were given to the intrinsic, 64-bit floating point
type? (And the existing "Float" and "Double" names were removed in favor of
"Float32" and "Float64"?)
*Discussion:*
I understand the origins of these names in single- and double-precision
IEEE floats. But this distinction feels like a holdover from C (and a
32-bit world), rather than a natural fit for Swift.
Here are some reasons to *keep Double and Float as they are* (numbered for
easy reference, but otherwise unordered):
1. "Double" and "Float" are more natural for developers who are
"familiar with C-like languages."
2. A corollary: A 64-bit "Float" type could be confusing to those
developers.
3. Another corollary: Swift needs to interoperate with Objective C, and
its "float" and "double" types.
4. Renaming these types would open the door to bike-shedding every type
name and keyword in the language.
5. Changing the meaning of an existing type ("Float") would be a bit
PITA for existing code (although an automated migration from "Float" to
"Float32" and "Double" to "Float" should be possible).
6. Renaming a fundamental type would take considerable effort.
Here are some reasons to *rename these types*:
1. The default for a "float literal" in Swift is a 64-bit value. It
would feel natural if that that value were of type "Float".
2. There are size-specific names for 32-bit ("Float32") and 64-bit
("Float64") floating point types. For cases where a size-specific type is
needed, a size-specific name like "Float32" probably makes the intention of
the code more clear (compared to just "Float").
3. Apple's Objective C APIs generally use aliased types like "CGFloat"
rather than raw float or double types.
4. There is precedent for "Float" types being 64-bit in other languages
like Ruby, Python and Go (as long as the hardware supports it).
5. What kind of a name for a type is "Double" anyways, amirite?
(that last one is a joke, BTW)
What do you think? Do you agree or disagree with any of my assessments? Are
there any pros or cons that I've missed? Is the level of effort so large
that it makes this change impractical? Is it a colossal waste of human
effort to even consider a change like this?
Thanks for your time and attention,
Alex Johnson (@nonsensery)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160104/67410604/attachment.html>
More information about the swift-evolution
mailing list