[swift-evolution] Beyond Typewriter-Styled Code in Swift, Adoption of Symbols

André Videla andre.videla at gmail.com
Thu Aug 31 16:13:38 CDT 2017


I would like to mention two things that I didn’t see mentioned in this thread (and if so, not emphasied enough since I missed it)

1. Swift already has pretty good unicode support, operators like ∷ for `cons` or prefix operators like `==` for partial functions work extremely well. Coincidentally I have written a bit about it on this blog post: https://medium.com/@andre_videla/elegant-swift-ec702fc84f11

If matrix literals were added, we could imagine that the current operator support would make their use extremely readable to the trained eye. The only concern that I have on the subject is about overloading resolution: Being a heavy operator user, I see the error “Expression too complex, could not be inferred in reasonable time” more often that I would like. So even if support for fancy “non-typewriter-style” code were to be implemented in the language. Overload resolution would need to be much more robust than it currently is.

2. There already exists a programming language that experiments with unicode AND mixfix operator support making it the perfect playground for trying out other style of “code input”. This language is Agda. 

Agda is quite the experimental playground and that’s why it’s useful to look at what it’s done. Mostly used by academic, their users do not have to share code across large scales of peoples and time. And even then, my limited and anecdotical, experience tells me that users have struggles simply copying their Agda code snippets to LaTeX on their own machine, let alone sharing it with other people across different systems. 

Here is an example of unicode mixfix operator in Agda https://github.com/sstucki/system-f-agda/blob/8ebbe32968c3ec9e046240cc6621166adcd23180/src/SystemF/Reduction.agda#L224

Another programming language inspired by Agda, Idris, completely ditched unicode and mixfix operator for reasons exposed here: 
https://github.com/idris-lang/Idris-dev/pull/694#issuecomment-29559291

With that said, I have to concede that I am quite fond of unicode operators and quite jealous of Agda mixfix syntax. It is truly a pleasure to read `check Γ ⊢ t ∈ a`  (from the definition `check _ ⊢ _ ∈ _` where underscores are the position of the argument of the function) instead of some verbose description that is not linked in anyway with the traditional representation of the function.

Even though my personal opinion brings me to enjoy unicode operators and code that looks like arcane incantations, I have to admit that this particular feature does not participate strongly in making Swift a strictly better language. Indeed, how do we achieve world domination if Swift code cannot be reliably shared across many people, in many countries, many cultures, and many different input devices and symbol conventions?


PS: agda even has “IDE” support with unicode input in emacs http://agda.readthedocs.io/en/latest/tools/emacs-mode.html?#unicode-input

> On 31 Aug 2017, at 22:13, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Aug 31, 2017, at 3:16 PM, Taylor Swift via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> Where is the source for this number? XCode is not even available for Linux. And XCode’s market share is only shrinking as Swift expands more into the open source world. To make Swift depend on proprietary XCode features would nullify all of the work that has been done in the past 2 years to bring Swift to Linux platforms.
>> 
>> On Thu, Aug 31, 2017 at 12:44 PM, John Pratt <jprattx at gmail.com <mailto:jprattx at gmail.com>> wrote:
>> XCode is not just one of many editors to edit Swift you asshole.
> 
> John, this sort of personal attack is not acceptable behavior in the Swift community, and sending it privately does not alter that.  If you would like to continue participating in this community, please learn to treat your fellow contributors with respect.
> 
> I don't think this thread is entirely off-topic.  While Swift as a language is committed to allowing code to be edited in a simple text editor, we also recognize the importance of graphical programming environments, and we are certainly open to adding features that primarily benefit them — as we did with color and resource literals.  Of course, it would necessary to show that the language feature was both necessary and likely to see significant editor adoption.  At least some of these ideas, like rendering a power operator with a superscript, do seem like they could implemented in an editor without any language support.
> 
> John.
> 
>> 
>> 
>> 
>>> On Aug 31, 2017, at 11:27 AM, Taylor Swift <kelvin13ma at gmail.com <mailto:kelvin13ma at gmail.com>> wrote:
>>> 
>>> If you ask me this thread is off topic and belongs on an Apple issue tracker or forum. XCode is just one of many editors used to edit Swift code, and it should by no means be used as a baseline for language design considering it is closed source and only available on one platform, compared to a large number of great open source editors.
>>> 
>>> On Thu, Aug 31, 2017 at 7:53 AM, Jonathan Hull via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> A few thoughts:
>>> 
>>> 1) I would like to see Xcode gain a couple more literal types using the same strategy it does for Image and Color literals
>>> 
>>> 2) I would LOVE to see simple equation typesetting in Xcode
>>> 
>>> (Those two are mostly up to the Xcode team as opposed to swift, I suppose)
>>> 
>>> 3) Why are we pretending like we can always edit swift in a ASCII editor?  The argument that actually using unicode would break things doesn’t seem valid, because Swift has supported unicode since version 1, and people have been using it since that time to name both variables and operators. That doesn’t mean we need a super fancy editor, but I think requiring unicode awareness is completely reasonable.  If your editor from the 1970’s breaks something, it is both your and your editor’s fault, not the code or the library, because Swift has unicode in it’s spec.
>>> 
>>> 4) I don’t think we should let the difficulty of typing certain things stop us.  It is an issue we need to consider, but it is an issue which can be solved fairly easily with good UI design if there is a need. Sure, different editors might solve it in different ways, but they will all solve it if it is useful (and in a few years, we will have all settled on the best approach).  As people have mentioned, it can be difficult to type ‘{‘ on certain language layouts, so if we limited ourselves by that we couldn’t do anything.  We shouldn’t adopt a lowest common denominator approach.
>>> 
>>> 5) The lack of ‘≤’ has driven me absolutely nuts since Swift 1. It won’t be confusing if we let people do either ‘<=‘ or ‘≤’ (there is research by Apple in the late 80’s that proves this).  We all learned the symbol in math class. Even non-programmers know what it means.  Assigning it any other meaning would be confusing because it’s meaning is so widely known.  Every time I bring this up, I am told to just roll my own (which I have)… but it means that my code will now clash with everyone else’s identical implementation (because there is only one sane way to implement it).  The fact that there are multiple identical implementations interfering with each other (and no real way to make a significantly different implementation) tells me it really should be part of swift itself. Every time I bring it up, people complain about it being extended ASCII instead of pure ASCII, and that it is hard to type on a German keyboard (those people can either just type ‘<=‘ or use a better editor which autocompletes ‘<=‘ to ‘≤’).
>>> 
>>> 6) My recommendations for typing symbols would be:
>>> 	a) Choose a subset of useful and well-known symbols instead of every symbol
>>> 	b) Allow autocomplete on those symbols by name
>>> 	c) Optionally choose a little-used guardian character to start the names of symbols (to avoid accidental autocompletion). 
>>> 
>>> Thanks,
>>> Jon
>>> 
>>> 
>>>> On Aug 28, 2017, at 7:57 PM, John Pratt via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> 
>>>> I sent a postal envelope to the Swift team with an article I wrote, arguing that
>>>> symbols and graphics would push the programming language forward.
>>>> 
>>>> Wouldn’t it be nice to have an actual multiplication matrix broken out into code,
>>>> instead of typing, “matrix()”?  It seems to me Swift has the chance to do that.
>>>> 
>>>> Also: why does "<==" still reside in code as "less than or equal to” when
>>>> there is a unicode equivalent that looks neat?  
>>>> 
>>>> Why can’t the square of x have a superscript of 2 instead of having “pow(x,2)?  
>>>> I think this would make programming much easier to deal with.
>>>> 
>>>> I expound on this issue in my article:
>>>> 
>>>> http://www.noctivagous.com/nct_graphics_symbols_prglngs_draft2-3-12.pdf <http://www.noctivagous.com/nct_graphics_symbols_prglngs_draft2-3-12.pdf>
>>>> 
>>>> Thank you for reading.
>>>> 
>>>> 
>>>> -John
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> 
>>> 
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170831/4db9ae26/attachment.html>


More information about the swift-evolution mailing list