Tuple DIP

Timon Gehr timon.gehr at gmx.ch
Sat Jan 13 20:49:43 UTC 2018


On 13.01.2018 20:43, aberba wrote:
> 
> When I raised this feature for D, suggestions on the use of () instead 
> of {} got me concerned. All languages that I know to have this feature 
> (known as destructuring) use curly braces.

It seems that this is actually not the case.
Anyway, I'd suggest having a look at more languages.

> Thats what kotlin and JavaScript (that I know have support) use.

They actually do not.

https://kotlinlang.org/docs/reference/multi-declarations.html

I.e. Kotlin also uses parentheses. They do this because it is standard.


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

In JavaScript, curly braces are used for object destructuring, not tuple 
destructuring. JavaScript does not have tuples, because without typing, 
they would be redundant with arrays. For array destructuring, JavaScript 
uses square brackets. This makes a lot of sense, as square brackets are 
also used to write array literals. Tuples are usually written using 
parentheses.

> Let's not be Rust that goes 
> with different syntax without any technical advantage.

The syntax the DIP proposes is as close to standard as it gets.

(Also, the idea that Rust syntax has no technical advantage whatsoever 
over C syntax is ridiculous. Can't say I enjoy all of their choices 
though, e.g. using + for multiple trait bounds is atrocious.)

> curly braces are more common (So to speak).
> 

They really are not.

> auto (name, email) = fetchUser();
>     vs
> auto {name, email} = fetchUser();
> 



More information about the Digitalmars-d mailing list