News for hackers. Stuff that matters.
Re:What’s New in Swift 5.2 by Razengan on Thursday February 06, 2020 @01:08PM (#22258488)
This kind of magic sugar may have been spurred by the requirements for SwiftUI and its evolution, in which case, I’m all for it.

I can already imagine cases where callAsFunction() would be handy. For example, having a viewTemplate = SomeView(customization: etc) then creating copies via viewTemplate()

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...
Re:What’s New in Swift 5.2 by Razengan on Thursday February 06, 2020 @03:53PM (#22260169)
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.

Re:What’s New in Swift 5.2 by zionic on Thursday February 06, 2020 @05:10PM (#22260962)
Playing code golf with the language syntax isn't the point, clarity and expressiveness is.
Re:What’s New in Swift 5.2 by oaiey on Thursday February 06, 2020 @01:37PM (#22258814)
That is the point. Swift has a primary usage unlike other languages. That is okay.
Re:What’s New in Swift 5.2 by gilgoomesh on Thursday February 06, 2020 @04:19PM (#22260445)
`callAsFunction` is not for Swift's primary usage. It is for Python interop, used by Swift For TensorFlow. Its design is such that you should never need to know it exists unless you're designing your own Python (or other scripting) interop layer.
Re:What’s New in Swift 5.2 by zionic on Thursday February 06, 2020 @04:53PM (#22260795)
Then it should be some kind of python-interop module. These kinds of useless syntax hax shouldn't be introduced into the main language. >99% of swift devs will never ever "interop with python", yet they all have to pay the price of this change.
Re:What’s New in Swift 5.2 by cygx on Thursday February 06, 2020 @04:35PM (#22260597)
I could see its use in math-heavy code as well. That might be a rather narrow domain, but one where features like this (or operator overloading for another example) do help to reduce syntactic pain.