Proposal: Make it easier to use unicode identifiers in Swift.


(Amir Michail) #1

In particular, allow the programmer to use text instead of unicode when convenient.

For example:

unicodealias alpha = α

let alpha = 5.0

print("α=\(α)”)

Every once in a while, the programmer could request that the IDE/editor transform the text names to their unicode counterparts as determined by unicode aliases throughout the source.


(Zhao Xin) #2

let unicodeScalar = UnicodeScalar("α") // 945

unicodeScalar.dynamicType // UnicodeScalar.Type

var unicodeScalars = "This is α".unicodeScalars // "This is α"

unicodeScalars.dynamicType // String.UnicodeScalarView.Type

let u1 = unicodeScalars.last! // 945

u1.dynamicType // UnicodeScalar.Type

let values = unicodeScalars.map({ $0.value })

values // [84, 104, 105, 115, 32, 105, 115, 32, 945]

values.dynamicType // Array<UInt32>.Type

let range = Range(start: unicodeScalars.endIndex.predecessor(), end:
unicodeScalars.endIndex)

let beta = UnicodeScalar(unicodeScalar.value + 1) // 946

unicodeScalars.replaceRange(range, with: [beta])

unicodeScalars // "This is β"

zhaoxin

···

On Fri, Jan 15, 2016 at 7:34 AM, Amir Michail via swift-evolution < swift-evolution@swift.org> wrote:

In particular, allow the programmer to use text instead of unicode when
convenient.

For example:

unicodealias alpha = α

let alpha = 5.0

print("α=\(α)”)

Every once in a while, the programmer could request that the IDE/editor
transform the text names to their unicode counterparts as determined by
unicode aliases throughout the source.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--

Owen Zhao


(Jordan Rose) #3

Hi, Amir. What benefit does this feature have for a Swift programmer? In my mind, it makes it harder to reason about what something does, because there may now be multiple names for the same variable.

Jordan

···

On Jan 14, 2016, at 15:34, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

In particular, allow the programmer to use text instead of unicode when convenient.

For example:

unicodealias alpha = α

let alpha = 5.0

print("α=\(α)”)

Every once in a while, the programmer could request that the IDE/editor transform the text names to their unicode counterparts as determined by unicode aliases throughout the source.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Amir Michail) #4

Hi, Amir. What benefit does this feature have for a Swift programmer? In my mind, it makes it harder to reason about what something does, because there may now be multiple names for the same variable.

Jordan

What’s the point of supporting unicode characters in identifiers if almost all of them are too hard to type?

With this approach, you can use standard text to type them and have them converted to unicode every once in a while (e.g., on a commit).

···

On Jan 15, 2016, at 6:37 PM, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 14, 2016, at 15:34, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

In particular, allow the programmer to use text instead of unicode when convenient.

For example:

unicodealias alpha = α

let alpha = 5.0

print("α=\(α)”)

Every once in a while, the programmer could request that the IDE/editor transform the text names to their unicode counterparts as determined by unicode aliases throughout the source.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jordan Rose) #5

I think the primary reason to support Unicode in identifiers is because some programmers use non-English names. Using them for e.g. math terminology is a bonus, but I don't think that's a reason to have special support in the core language.

Now, I could be convinced otherwise (cf. C++'s digraphs <https://en.wikipedia.org/wiki/Digraphs_and_trigraphs>), but I don't see why you wouldn't just name the APIs something convenient to begin with, or define a shortcut in your editor rather than in the language.

Best,
Jordan

P.S. As a general note, please include in the first message for a feature why you think a particular feature is a good idea for Swift. That saves a bit of time for those of us who may not immediately see the benefit.

···

On Jan 15, 2016, at 15:39, Amir Michail <a.michail@me.com> wrote:

On Jan 15, 2016, at 6:37 PM, Jordan Rose <jordan_rose@apple.com> wrote:

Hi, Amir. What benefit does this feature have for a Swift programmer? In my mind, it makes it harder to reason about what something does, because there may now be multiple names for the same variable.

Jordan

What’s the point of supporting unicode characters in identifiers if almost all of them are too hard to type?

With this approach, you can use standard text to type them and have them converted to unicode every once in a while (e.g., on a commit).


(Félix Cloutier) #6

It's to support the ones that are not too hard to type. É is a single key on my keyboard.

Félix

···

Le 15 janv. 2016 à 18:39:14, Amir Michail via swift-evolution <swift-evolution@swift.org> a écrit :

On Jan 15, 2016, at 6:37 PM, Jordan Rose <jordan_rose@apple.com> wrote:

Hi, Amir. What benefit does this feature have for a Swift programmer? In my mind, it makes it harder to reason about what something does, because there may now be multiple names for the same variable.

Jordan

What’s the point of supporting unicode characters in identifiers if almost all of them are too hard to type?

With this approach, you can use standard text to type them and have them converted to unicode every once in a while (e.g., on a commit).

On Jan 14, 2016, at 15:34, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

In particular, allow the programmer to use text instead of unicode when convenient.

For example:

unicodealias alpha = α

let alpha = 5.0

print("α=\(α)”)

Every once in a while, the programmer could request that the IDE/editor transform the text names to their unicode counterparts as determined by unicode aliases throughout the source.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Amir Michail) #7

Hi, Amir. What benefit does this feature have for a Swift programmer? In my mind, it makes it harder to reason about what something does, because there may now be multiple names for the same variable.

Jordan

What’s the point of supporting unicode characters in identifiers if almost all of them are too hard to type?

With this approach, you can use standard text to type them and have them converted to unicode every once in a while (e.g., on a commit).

I think the primary reason to support Unicode in identifiers is because some programmers use non-English names. Using them for e.g. math terminology is a bonus, but I don't think that's a reason to have special support in the core language.

Now, I could be convinced otherwise (cf. C++'s digraphs <https://en.wikipedia.org/wiki/Digraphs_and_trigraphs>), but I don't see why you wouldn't just name the APIs something convenient to begin with, or define a shortcut in your editor rather than in the language.

Consider a linear algebra library that makes use of unicode throughout its API. Having to define the shortcuts yourself is less convenient than having them come with the library.

Moreover, the IDE could even help you by showing you what you can type using standard characters to generate a particular unicode identifier as can be automatically determined via unicodealiases in the library source.

···

On Jan 15, 2016, at 6:50 PM, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 15, 2016, at 15:39, Amir Michail <a.michail@me.com <mailto:a.michail@me.com>> wrote:

On Jan 15, 2016, at 6:37 PM, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

Best,
Jordan

P.S. As a general note, please include in the first message for a feature why you think a particular feature is a good idea for Swift. That saves a bit of time for those of us who may not immediately see the benefit.


(Wallacy) #8

http://ericasadun.com/2016/01/13/a-few-thoughts-on-swift-symbologygist/

···

On Fri, Jan 15, 2016, 21:53 Amir Michail via swift-evolution < swift-evolution@swift.org> wrote:

On Jan 15, 2016, at 6:50 PM, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 15, 2016, at 15:39, Amir Michail <a.michail@me.com> wrote:

On Jan 15, 2016, at 6:37 PM, Jordan Rose <jordan_rose@apple.com> wrote:

Hi, Amir. What benefit does this feature have for a Swift programmer? In
my mind, it makes it harder to reason about what something does, because
there may now be multiple names for the same variable.

Jordan

What’s the point of supporting unicode characters in identifiers if almost
all of them are too hard to type?

With this approach, you can use standard text to type them and have them
converted to unicode every once in a while (e.g., on a commit).

I think the primary reason to support Unicode in identifiers is because
some programmers use non-English names. Using them for e.g. math
terminology is a bonus, but I don't think that's a reason to have special
support in the core language.

Now, I could be convinced otherwise (cf. C++'s digraphs
<https://en.wikipedia.org/wiki/Digraphs_and_trigraphs>), but I don't see
why you wouldn't just name the APIs something convenient to begin with, or
define a shortcut in your editor rather than in the language.

Consider a linear algebra library that makes use of unicode throughout its
API. Having to define the shortcuts yourself is less convenient than having
them come with the library.

Moreover, the IDE could even help you by showing you what you can type
using standard characters to generate a particular unicode identifier as
can be automatically determined via unicodealiases in the library source.

Best,
Jordan

P.S. As a general note, please include in the first message for a feature
*why* you think a particular feature is a good idea for Swift. That saves
a bit of time for those of us who may not immediately see the benefit.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution