Talk:DIP32

From D Wiki
Revision as of 20:09, 31 July 2014 by Schuetzm (talk | contribs) (Created page with "== About $identifier == Why not require normal declaration syntax, when a variable should be declared in unpacking? Suggested in DIP: <source lang="D"> switch (tup) { ca...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

About $identifier

Why not require normal declaration syntax, when a variable should be declared in unpacking?

Suggested in DIP:

switch (tup) {
    case {1, 2}:
    case {$, 2}:
    case {1, x}:
    default:
}
// -----------------------------
int x = 1;
if (auto {$x, y} = coord) { ... }

My suggestion:

switch (tup) {
    case {1, 2}:
    case {$, 2}:
    case {1, auto x}:
    default:
}
// -----------------------------
int x = 1;
if ({x, auto y} = coord) { ... }

This would be more consistent with how if usually works (expression syntax => use existing variable, declaration syntax => declare variable initialized with the value of the comparison), doesn't require this special syntax which is used nowhere else in the language, and makes it obvious that a declaration takes place.

It also allows to use unpacking everywhere:

int x;
{x, int y} = tup;