5 ms·
I'm pretty apprehensive about this "callAsFunction()" feature. Requiring users to name things in a specific way was the kind of awful UX our customers struggled
by metalgearsolid 7y ago
I'm pretty apprehensive about this "callAsFunction()" feature. Requiring users to name things in a specific way was the kind of awful UX our customers struggled with when using our hobbled-together marketing software.
IMO, some better alternatives, in order of personal preference:
* Give away the functionality to all types that implement only a single function.
* Require an explicit protocol conformance. I get that the language does not want features to be hidden away, but requiring a user to implement a function with a specific name and signature is literally the job of a protocol. It doesn't seem like much of a hurdle for non-beginners, who have likely been familiarized with core protocols like Sequence or Collection, to acquire a knowledge of a CallAsFunction protocol.
* Introduce a new keyword, or tag (like @implicit).
* Allow the user to unlock the functionality through a more obscure phrasing. Even something as ugly as "func ` `()" could be preferable.
- mantap 7y agoThere is a danger of overengineering. This is a feature that will only be used in rare situations. So it doesn't really matter that it's just a magic identifier. As long as you aren't likely to use it by accident... I'm assuming they checked GitHub that nobody has named anything callAsFunction before choosing it
- smabie 7y agoApply on objects is used constantly in Scala, why would it be different in Swift?