Less Talk
July 16, 2020
Back when I worked in radio (kind of like podcasts but we mostly played music where I worked and you listened to whatever was on at the time).
Anyway, back when I worked in radio, many of the DJ's didn't want their names listed in the phone book (a big book with everybody's number listed in alphabetical order along with their phone number - before we called them land lines.)
Anyway, it was more expensive to have your number not be listed in the phone book so many DJ's just made up another name to list the phone in (in those days the phone number belonged to the house you lived in and stayed there so often multiple people were available at the same phone number).
Anyway, this DJ told me about a friend of his who always listed his phone number under the name "Lester Talk". Many stations described themselves as "More Music and Less Talk" so this guy decided that he'd be "Less Talk".
Anyway, that's a long way of saying that one of the things I really like about the direction Swift has been taking is that we're eliminating words that can be inferred by the compiler. You're average .swift file is more music and less talk.
Recently, we've been able to eliminate many of the selfs from closures.
There's one bit of verbosity I wish we could eliminate.
From the beginning, in Swift if you had a struct, say this one.
struct Person {
let name: String
let phoneNumber: Int
}
You didn't have to write the init. The following was created for you.
init(name: String, phoneNumber: Int) {
self.name = name
self.phoneNumber = phoneNumber
}
That's code you didn't have to write.
Except.
Except if you put Person in a separate module. Of course you know to make Person public.
public struct Person {
let name: String
let phoneNumber: Int
}
But when you try to create an instance of Person from outside the module you get the error that there is no accessible init().
When I said "the following was created for you" I meant exactly that. The access level is missing so of course it is internal.
And so, just to add the word public to the front of the derived init you have to actually type all of this.
public struct Person {
let name: String
let phoneNumber: Int
}
public init(name: String, phoneNumber: Int) {
self.name = name
self.phoneNumber = phoneNumber
}
What happened to more music and less talk?
I'd love to type something like this:
public struct Person {
let name: String
let phoneNumber: Int
}
public init
or
public struct Person {
let name: String
let phoneNumber: Int
}
public @init
Using some mechanism similar to @main.
I don't want the init to automatically be public. I often want to create a custom init() and hide the one that is created by default. I want to make it private.
I'd like to be able to type
public struct Person {
let name: String
let phoneNumber: Int
}
private @init
init(name: String) {
self(name: name, phoneNumber: 5551234)
}
There have been proposals for this in the past, and I'd bring it up again but you now have to submit implementations along with proposals and I'm certain I can't do so.
I just want more music and less talk.