Re:Swift System Is Now Open Source
by cutler on Friday September 25, 2020 @07:55PM
(#24595240)
Swift has some really clunky "features" such as dual-identifier parameters and escaped opening parens as identifiers for string templates. WTF! As if function/method declarations weren't complex enough in a statically-typed language which supports generics.
[ Parent
| on HN ]
Re:Swift System Is Now Open Source
by santraginean on Saturday September 26, 2020 @12:34AM
(#24596438)
They’re not dual identifiers; one is an argument label and the other is the parameter name. Maybe it’s because I come from an ObjC background, but this is one of my favorite aspects of the syntax; IMO it makes code way easier to read without having to look up method definitions to figure out what each argument does.
From State of the Platform this year: https://pbs.twimg.com/media/Ebb51t6XkAIF4YD?format=jpg&name=...
Which for is for and would work as for for?
Madness.
As a disclaimer, I’ve written Swift, but this seems to be a simple concept. The first name is the interface and is used at the call site, and the second (optional) name is used within the scope of the function, should the developer want a more descriptive name.
> escaped opening parens as identifiers for string templates
Do you mean the use of “\(variable)” for string interpolation? What’s wrong with that?
It's just downright clunky. What's wrong with ${variable} as in Kotlin and Javascript?
I think that’s more a question of taste/what one is used to. I find that dollar sign a bit heavy, visually, but one could also argue that’s a plus.
Using backslash has the advantage that there’s only one ‘special’ character in strings, but of course, also has the problem can escape any character with a backsplash, except for opening parentheses.
They had good reasons, it means there's only two substrings that need escaping: the backslash and end string sequence. In hindsight, it's ugly and hard to read. A case of optimising for the wrong thing.