An anecdote from yesterday against allowing the elision of `some` ...
Yesterday I was speaking to a junior developer whose task was to make a new view controller with a certain set of simple characteristics, and he was attempting to copy and adapt the patterns he saw being employed in other view controllers. He ended up feeling the need to ask me for help, which after hearing him out I discovered was essentially entirely due to his confusion about what protocols really are and how they work.
One punch line of the situation was that his code already was correct by the time he reached out to me - he just had some wires crossed with regard to protocols which made it such that despite the fact that he had correctly copied and modified the other code, he was certain that it must not be setup correctly (because the role of the protocol mystified him).
I believe that the constant presence of one of the two keywords (some
or any
) very well could have caused his particular confusion about protocols to evaporate much earlier on his path as a developer, not only preventing him from feeling stuck in the situation that he was in this time, but also allowing him to write better code in general due to a better grasp of the tools he has at hand when writing Swift.
Basically, the view controller that he was using as a template had an initializer like this:
init (viewModel: PreexistingViewControllerViewModelProtocol) {
...
}
One line that struck me was that he said, "I mean if it were a struct, I'd know how that works."
I believe his confusion came about more or less like this:
- He had an understanding of what it means to define his own structs or classes and create instances of them.
- He had an understanding about what it means to invoke a function with an instance of a struct or a class as an argument.
- He had been forced to interact with protocols on various occasions but had never really finished absorbing the essence of what they are/how they work/when to use them.
- He had the notion that protocols "are, like, empty, right? They don't have real implementations or something?"
- He saw an initializer that looked exactly like initializers he had worked with dozens of times in the past, with the only exception being that when he jumped to the definition of the argument type he found a protocol, rather than a struct or a class like he was used to.
- To him, that seemed like a fatal substitution (
struct -> protocol
), because protocols are "empty" - he felt that he hadn't yet understood the types of abstract, high-brow situations in which it is somehow useful to work with "empty" versions of the useful things that he was used to working with, but it certainly didn't seem likely to him that an "empty" view model was going to suffice to make his actual view controller work.
I think that his confusion that I just witnessed "in the wild" is exactly the confusion that one would be worried would arise from allowing the elision of some
. I think some ViewModelProtocol
or any ViewModelProtocol
would contribute greatly to dispelling the confusing illusion that we are ever manipulating values that are somehow "empty".