What is your evaluation of the proposal?
-1. I don't consider iteration over optional sequence to be so special to get its own sugar. Moreover, i think it will have a negative impact on the language (more below).
Is the problem being addressed significant enough to warrant a change to Swift?
No and the proposal provides no proof or explanation that this is a significant improvement over the existing, so-called "workarounds".
Does this proposal fit well with the feel and direction of Swift?
No. In my opinion, this proposal will have negative impact on a couple of aspects:
1. Learning Swift
Right now, unwrapping optionals and iterating sequences are two distinct ideas in Swift and can be easily understood in isolation. Beginners learn how to do these things and then they can glue this knowledge together when facing an optional sequence.
Introduction of special control flow operator for this case will only make the language more complex and will raise further questions, like where's while?
, switch?
, if?
.
2. API design
After this feature is introduced, thus making optional sequences a "blessed" type, I feel that API authors will be more inclined to misuse optional sequences where other types would make more sense.
For instance, I think usage of optional sequences will increase in return types and completion closures, where non-optional sequence wrapped in Result type, or throwing function would be a better choice.
3. Safety
This is my most important point, I'll do my best to explain what I mean. TL;DR: For me this syntax shares similar safety implications as the ability to send messages to nil
s in Objective-C.
Going through explicit unwrapping or coalescing has the advantage that... a developer must actually write that. And as they write it, they usually think about the difference between an empty and an optional sequence. In the end, they might decide to deal with the optionality in an earlier stage.
With the introduction of for?
, the difference between iterating on a non-optional empty array and an optional array becomes blurred. So blurred, it might go unnoticed during development and code review and might have serious complications, where a different code path is required for these two cases.
Now, re. the proposed fix-it — I think fix-its should increase program safety and teach developers how to properly handle cases that caused them. In my opinion, this particular fix-it should draw developer's attention to the difference between optional sequences and non-optional empty sequences. It should not suggest omitting one of these cases silently. There's a reason for that when you write try
, Swift doesn't suggest adding try?
— instead, it suggests adding a proper do/catch
.
To sum up, I feel this proposal will make it harder for developers to catch and distinguish the use of optional sequences, thus making it easier to introduce bugs in our products. Swift, with its opinionated focus on safety, should not go in that direction.
Not all developers are experienced enough that they won't fall into the aforementioned trap. Swift should make it harder for less experienced developers to make mistakes. And this proposal undermines that mission.
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Nah, I don't think any other language has it.
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I read the proposal, scanned the initial pitch thread and read discussion in this thread.