[swift-evolution] Allow ' in variable/constant names?
jgroff at apple.com
Wed Jan 11 22:36:35 CST 2017
> On Jan 11, 2017, at 2:07 PM, David Sweeris <davesweeris at mac.com> wrote:
>> On Jan 11, 2017, at 15:41, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>> On Jan 11, 2017, at 5:16 AM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
>>> -1. Why? Why not use foo2 instead? Is ' so much better?
>>> Instead, I'd personally love better character support in Swift in the future and allow a Character literals using ' - just like in C, except with Unicode support:
>>> let myChar = 'x' // Character
>>> let myChar2 = '∃' // Character
>>> let myChar3 = '\0' // NUL Character
>>> let myChar4 = 'xyz' // Error from compiler
>> These aren't necessarily mutually exclusive. If we require that an identifier can't start with an apostrophe, then we can support identifiers named `x'` and `'x'` as some kind of literal simultaneously.
>> I'm sympathetic to this since I personally find x', x'', etc. more attractive than x2, x3, etc. for totally superficial math weenie reasons, but although the surface level language design is fairly straightforward, the downstream tooling impact is nontrivial—we'd need a mangling for ' in symbol names, simplified parsing tools would need to cope with ', tools that attempt to parse out identifiers from error messages would have to deal with apostrophe-unsafe output, etc. Not sure it's worth it.
> Out of curiosity, instead of coming up with another mangling scheme, how hard would it be to add ' support to the downstream tooling? It's all open source, right?
Much of it is open source, but there's no telling how much other code is out there, and we'd have to find out. swiftc itself for instance already delimits identifier names with apostrophes in diagnostics, and while there are APIs for consuming the compiler's diagnostics in more readily parsable formats like JSON, there's no guarantee ad-hoc tools are using them properly.
More information about the swift-evolution