array literal element types

bearophile bearophileHUGS at lycos.com
Fri Nov 13 04:18:19 PST 2009


Robert Jacques:

> Given how numeric literals currently work:
> vote--
> 
> for example currently:
> float[] = [1.0f, 2.5, 5.6, 0.8].dup;
> 
> under the proposal
> float[] = [1.0f, 2.5f, 5.6f, 0.8f].dup;

Yes, this proposal has some downsides too. You have to be careful regarding what you put inside the array, because a stray value may change the type of your whole array, and this can lead to problems if you use:
auto a = [1.0f,2.5f,5.6,0.8f];
If you forget a single "f" a becomes an array of doubles...

So no design is perfect here. But I think the new proposed design is the more handy of the two. If programming experience shows us this leads to problems we can switch back to the older design. Sometimes you need to use things for some time to know how good/bad they are.

Bye,
bearophile



More information about the Digitalmars-d mailing list