[swift-evolution] A path forward on rationalizing unicode identifiers and operators

Xiaodi Wu xiaodi.wu at gmail.com
Mon Oct 2 21:57:40 CDT 2017


On Mon, Oct 2, 2017 at 9:04 PM, David Sweeris <davesweeris at mac.com> wrote:

>
> On Oct 2, 2017, at 5:45 PM, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> On Mon, Oct 2, 2017 at 19:28 Ethan Tira-Thompson via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> I’m all for fixing pressing issues requested by Xiaodi, but beyond that I
>> request we give a little more thought to the long term direction.
>>
>> My 2¢ is I’ve been convinced that very few characters are “obviously”
>> either a operator or identifier across all contexts where they might be
>> used.  Thus relegating the vast majority of thousands of ambiguous
>> characters to committee to decide a single global usage.  But that is both
>> a huge time sink and fundamentally flawed in approach due to the contextual
>> dependency of who is using them.
>>
>> For example, if a developer finds a set of symbols which perfectly denote
>> some niche concept, do you really expect the developer to submit a proposal
>> and wait months/years to get the characters classified and then a new
>> compiler version to be distributed, all so that developer can adopt his/her
>> own notation?
>>
>
> The Unicode Consortium already has a document describing which Unicode
> characters are suitable identifiers in programming languages, with guidance
> as to how to customize that list around the edges. This is already adopted
> by other programming languages. So, with little design effort, that task is
> not only doable but largely done.
>
> As to operators, again, I am of the strong opinion that making it possible
> for developers to adopt any preferred notation for any purpose (a) is
> fundamentally incompatible with the division between operators and
> identifiers, as I believe you’re saying here; and (b) should be a non-goal
> from the outset. The only task, so far as I can tell, left to do is to
> identify what pragmatic set of (mostly mathematical) symbols are used as
> operators in the wider world and are likely to be already used in Swift
> code or part of common use cases where an operator is clearly superior to
> alternative spellings. In my view, the set of valid operator characters not
> only shouldn’t require parsing or import directives, but should be small
> enough to be knowable by memory.
>
>
> The set notation operators should be identifiers, then?
>

Set notation operators aren't valid identifier characters; to be clear, the
alternative to being a valid operator character would be simply not listing
that character among valid operator or identifier characters.


> Because the impression I got from the Set Algebra proposal a few months
> ago is that there are a lot of people who’ve never even seen those
> operators, let alone memorized them.
>

That's not the impression I got; the argument was that these symbols are
hard to type and _not more recognizable that the English text_, which is
certainly a plausible argument and the appropriate bar for deciding on a
standard library API name.

MHO is that the bar for a potentially valid operator character _for
potential use in third-party APIs_ needn't be so high that we demand the
character to be more recognizable to most people than alternative
notations. Instead, we can probably justify including a character if it is
(a) plausibly useful for some relatively common Swift use case and (b) at
least somewhat recognizable for many people. Since set algebra has a
well-accepted mathematical notation that's taught (afaict) at the _high
school_ level if not earlier, and since set algebra functions are a part of
the standard library, that surely meets those bars of usefulness and
recognizability.

Keep in mind that Swift already goes far above and beyond in terms of
operators, in that: (a) it allows overloading of almost all standard
operators; (b) it permits the definition of effectively an infinite number
of custom operators using characters found in standard operators; (c) it
permits the definition of custom precedences for custom operators; and (d)
it additionally permits the use of a wide number of Unicode characters for
custom operators. Most systems programming languages don't even allow (a),
let alone (b) or (c). Even dramatically curtailing (d) leaves Swift with an
unusually expansive support for custom operators. What it does conclusively
foreclose is something which ought to be stated firmly as a non-goal, which
is the typesetting of arbitrary mathematical equations as valid Swift code.
Quite simply, Swift is not math; simple addition doesn't even behave as it
does in grade-school arithmetic, so there is no sense in attempting to
shoehorn calculus into the language.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171002/41ca466d/attachment.html>


More information about the swift-evolution mailing list