SE-0243: Codepoint and Character Literals

What is your evaluation of the proposal?

I'm quite ambivalent.

  • Implementing the initializer for ASCII integer literals in the standard library before we can add the conformance seems a bit confusing. Sure, we can introduce the conformance ourselves where needed, but this is basically making one part of the core language optional. It's weird, even if temporary.

  • I'm not particularly convinced introducing a single-quote literal for the sake of representing one Character without type inference is that useful. At least the motivation part doesn't explain it well enough for me. It could be slightly better as a final result than using type inference, but is it really worth the trouble of deprecating the old syntax?

  • I do find it useful to be able to represent ASCII characters with single quotes for integer types and that it is statically checked to be ASCII. This is something I'd really like to see in the language. But the asymmetry between UInt8('8') vs. '8' as UInt8 is troubling I think.

Also, I'll echo others in that I don't see why UInt8(ascii: 64) need to be deprecated.

Is the problem being addressed significant enough to warrant a change to Swift?

There is basically two problems here:

  1. making literals characters/unicode scalars/integers easier to distinguish at the point of use versus strings.
  2. allow integers to be easily initialized from ASCII characters

I personally don't care for 1, but I think 2 is very worth it when parsing various kinds of data formats.

Does this proposal fit well with the feel and direction of Swift?

I'm not too sure.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

The current proposal is inspired from the C syntax using single quotes for single characters, which are really just numbers. C doesn't really understand Unicode, but C character literals make it easy to write low level algorithms that works fine with ASCII. And a lot of strings are guarantied to be ASCII in this world: numbers, dates, identifiers, etc. So it's great to be able to work in ASCII when needed, and this is much easier to do in C.

I wish Swift was better for expressing things of the sort, and this proposal does improve things a bit. At the same time I think it makes compromises by regrouping Unicode characters under the same umbrella and this creates tensions between the two usages. I proposed earlier in the pitch phase that we could simply use single quotes for ASCII scalars and double quotes for anything Unicode and I feel this would work better; it also avoids deprecating an existing syntax.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read the review thread and participated in the pitch.