Re:What’s New in Swift 5.2
by azinman2 on Thursday February 06, 2020 @01:15PM
(#22258548)
But why not just add a method like “.copy()” that’s explicit about what it does? Have to say I’m not a fan of this callAsFunction feature...
[ Parent
| on HN ]
Again, because this makes declarative UI cleaner to write, or if you prefer to put it this way: reduces clutter.
I could create button templates then make slightly different copies of those templates without having to subclass Button or attaching .copy()
SwiftUI is all about succinctness.
Re:What’s New in Swift 5.2
by rhysmorgan on Thursday February 06, 2020 @04:53PM
(#22260793)
Why is it all about succinctness?
Swift has never been about succinctness - it’s always been about clarity, without over-verbosity. Sometimes, it just takes a decent number of characters to describe something. That’s not necessarily a flaw, especially if it makes something easier to read.
Seeing .copy() makes it much clearer to understand that what I’m receiving is a copy of something.
If you want a Button template, either extend Button with a method taking the parameters you want, or write a curried free function or something. callAsFunction adds absolutely nothing to the language, bar confusion at the call site.