Should we remove int[$] before 2.067?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 30 12:43:08 PST 2015


On 1/30/15 12:33 PM, Meta wrote:
> I'm somewhat neutral on [$], although I think it is useful. I like the
> partial type deduction feature and think we should keep that. It makes a
> lot of array declarations more concise, and subjectively, I think it
> feels like a natural extension of what D already does with auto.
>
> I think if you showed someone auto declarations and then showed them
> something like auto[] arr = [...], their likely reaction would be "well
> of course that works". Although maybe I'm too familiar with D at this
> point and that's not the case at all.

Yah, that's nice but needs appropriate formalization. How about 
auto[auto] to ensure an associative array type, or Xyz!(auto, auto) to 
ensure template Xyz with exactly two arguments, or even auto!(auto) to 
match any template instantiated with one argument...?

It's just getting weird, and not very useful because it's impossible to 
associate names with those "auto"s. As I mentioned this is sometimes 
used in C++ but I don't see vital idioms. I see people sometimes use

auto& a = arr[n];

to make sure they take a reference, but we can't define references 
locally so we can't use that :o).

>> Furthermore, one other unpleasant aftermath of int[$] is that new
>> syntax begets more new syntax. The proverbial ink was not yet dry on
>> the #3615 merge when a new, new syntax was proposed in this forum,
>> this time for statically-allocated statically-sized arrays. Far as I
>> can tell the main argument is "you have to write longer code" without it.
>
> If you're talking about Bearophile's proposed [1, 2]s syntax, he's been
> pushing that for a long time, possibly before [$].

The age of that proposal is irrelevant (except probably for the 
possibility of it being obviated by language development). The problem 
is now there is a precedent to back it up.

Let's stop adding every little tidbit to the language. Let's start 
_using_ the language for awesome things.


Andrei



More information about the Digitalmars-d mailing list