[Issue 5603] Initialization syntax for dynamic arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 17 10:16:34 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5603



--- Comment #4 from bearophile_hugs at eml.cc 2011-02-17 10:13:58 PST ---
(In reply to comment #3)

> First, this only really happens when the type is numerical.  For example, a
> string array would fail to compile with an integral initializer.  Also, a void
> initializer cannot be mistaken for a dimension size.
> 
> Second, I can see what you are saying, but I don't think this error will affect
> much in practice.  It isn't often that one changes the number of dimensions. 
> Readability-wise, however, it's not obvious whether the last element is an
> initializer (an IDE might make this clearer with syntax coloring).
> 
> Your proposal clearly separates the value from the dimensions, but it probably
> is unacceptable due to parsing requirements.  Plus it looks very bizarre.

It looks somewhat like the fixed-sized initialization syntax.


> If we are doing syntax changes, I think we need something unorthodox if we want
> to make this clear.  What about:
> 
> auto a = new int[][](5, 5; 2);
> auto a = new int[][](5, 5, =2);
> auto a = new int[][](5, 5 : 2);
> auto a = new int[][](5, 5) : 2;

The last line is very close to my suggested syntax, and it has the advantage to
be intuitive for D programmers, because it's a copy of the fixed-sized
initialization syntax:

auto a = new int[][](5, 5) = void;
instead of:
int[5][5] a = void;


> I still think the original syntax I proposed is not different from functions
> that contain default parameters,

Named arguments (as Python ones) are safer than default ones.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list