Proposal: Drop parentheses for initalization from tuple


(Daniele Riccardelli) #1

Hi all,

I was thinking that the syntax for initialization from tuple is a bit more
verbose than needed, i.e. why not simply drop the tuple parentheses and go
from this :
*let* (name, surname) = (*"*John*"*, *"*Doe*"*)

to this:
*let* name, surname = (*"*John*"*, *"*Doe*"*)

similarly to what Python does with "unpackable" types:
name, surname = ("John", "Doe")

This is not a revolution, but if the concern is the trade-off between
conciseness and readability, I think this way we are being more concise
while not losing points in readability.

This would of course break existing code, but updating to this syntax would
be trivial.

What do you think?

Thanks,

Daniele


(Basem Emara) #2

Hi Daniele, to me at first glance, it looks like a shorthand for creating multiple variables. I would expect to try something like this later: “print(name); print(surname)”, which of course wouldn’t be the intent.

Basem

···

On May 7, 2016, at 3:42 PM, Daniele Riccardelli via swift-evolution <swift-evolution@swift.org> wrote:

Hi all,

I was thinking that the syntax for initialization from tuple is a bit more verbose than needed, i.e. why not simply drop the tuple parentheses and go from this :
let (name, surname) = ("John", "Doe")

to this:
let name, surname = ("John", "Doe")

similarly to what Python does with "unpackable" types:
name, surname = ("John", "Doe")

This is not a revolution, but if the concern is the trade-off between conciseness and readability, I think this way we are being more concise while not losing points in readability.

This would of course break existing code, but updating to this syntax would be trivial.

What do you think?

Thanks,

Daniele
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Daniele Riccardelli) #3

Hi Basem,

Thank you for the answer. It is indeed a shorthand for unpacking the tuple,
which is nothing new to Swift.

My suggestion is simply to go from this syntax:
let (name, surname) = ("John", "Doe")

to this:
let name, surname = ("John", "Doe")

So it is not about a new feature of the language, simply a small change in
the syntax.

Let me know what you think.

Thanks,

Daniele

···

2016-05-07 20:49 GMT+01:00 Basem Emara <contact@basememara.com>:

Hi Daniele, to me at first glance, it looks like a shorthand for creating
multiple variables. I would expect to try something like this later:
“print(name); print(surname)”, which of course wouldn’t be the intent.

Basem

On May 7, 2016, at 3:42 PM, Daniele Riccardelli via swift-evolution < > swift-evolution@swift.org> wrote:

Hi all,

I was thinking that the syntax for initialization from tuple is a bit more
verbose than needed, i.e. why not simply drop the tuple parentheses and go
from this :
*let* (name, surname) = (*"*John*"*, *"*Doe*"*)

to this:
*let* name, surname = (*"*John*"*, *"*Doe*"*)

similarly to what Python does with "unpackable" types:
name, surname = ("John", "Doe")

This is not a revolution, but if the concern is the trade-off between
conciseness and readability, I think this way we are being more concise
while not losing points in readability.

This would of course break existing code, but updating to this syntax
would be trivial.

What do you think?

Thanks,

Daniele
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution