[Issue 4733] Possible bugs caused by dynamic arrays in boolean evaluation context

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 10 03:53:27 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #20 from bearophile_hugs at eml.cc 2013-12-10 03:53:21 PST ---
(In reply to comment #19)
> 1. making this change will break existing code

Yes, it's one of the small breaking changes, this one I have asked since
2010-08-26. There are about ten more tiny breaking changes I am asking since
lot of time in Bugzilla. Do we want to close them all as WONTFIX? Having
similar warts in D is not good.


> 2. forcing people to use if(arr.ptr) instead is just ugly

It's not something you do often. I don't think I have 1 case in my code where I
need to do this. In 99% of the D code using ".empty" or even ".length == 0" is
more clear and less dangerous (because it's more clear). The problems with
finding a good error message show the old situation is not clear.

The code being a tiny bit ugly could be an advantage if it helps show unusual
(low-level) qualities of the code. Even using cast(int) is a little ugly
compared to (cast) but that was done for some practical reasons. Using ".ptr"
shows it's special code, while using empty or length shows it's normal D user
code fit for @safe functions too.

The idea that instances int[] are "pointers" is not a good idea. They are at
best fat pointers, and conflating the idea of pointer with the idea of dynamic
array was a design mistake that we are slowly fixing with tiny/small breaking
changes. This ER is another step in that direction.

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


More information about the Digitalmars-d-bugs mailing list