[Issue 3889] Forbid null as representation of empty dynamic array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 14 18:29:25 PDT 2011


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



--- Comment #9 from bearophile_hugs at eml.cc 2011-08-14 18:29:23 PDT ---
(In reply to comment #8)
> Regardless of how good or bad an idea this is, there is no way that this is
> going to change at this point. The current situation is very much by design
> and changing it would break a lot of code.

It's a design that I don't think is the best.

1) [] and null are two ways to do the same thing (empty array literal). Well
designed languages have (try to have) only one obvious way to do something. 

2) When you print an empty array writeln is supposed to write "[]", not null.
Having the code use the same representation produced by writeln is very handy
(example: for code generation, improve debugging output readability, etc).

3) Between [] and null the [] is more specific.

4) DMD needs to break the idea that arrays are pointers. New D programmers need
to be steered as soon as possible away from the idea that D arrays are like C
arrays. While the usage of null to denote empty dynamic arrays reinforces this
wrong idea.

Regarding the current bad D way of mixing the idea of pointers and dynamic
arrays at a visual level, see also issue 3990 that shows this example (it
compiles with DMD 2.054 too):

void main() {
   int[] a1 = [5, 4, 3];
   assert(*a1 == 5);
   alias typeof(a1) T1;
   assert(is(typeof(*T1)));
   int* p1 = cast(int*)a1;
   assert(p1 == a1.ptr);
}


I don't think you will be able to ignore all the things Steven Schveighoffer
says here:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=135391


This is not a single change, there are other related changes, see also issue
5788

A tool as Gofix gives a bit more freedom to change:
http://blog.golang.org/2011/04/introducing-gofix.html


Regarding "now it's too much late to change it" see also 3843. There are
several more enhancement requests in Bugzilla that as more time passes will
become "now it's too much late to change".

-- 
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