Jump to page: 1 2 3
Thread overview
[Issue 4733] Possible bugs caused by dynamic arrays in boolean evaluation context
Nov 27, 2013
yebblies
Nov 27, 2013
yebblies
Nov 27, 2013
yebblies
Nov 27, 2013
yebblies
Nov 27, 2013
yebblies
Nov 30, 2013
Martin Nowak
Dec 10, 2013
Walter Bright
Dec 14, 2013
Martin Nowak
Dec 14, 2013
Martin Nowak
Dec 14, 2013
Martin Nowak
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |yebblies@gmail.com


--- Comment #5 from yebblies <yebblies@gmail.com> 2013-11-27 16:52:15 EST ---
Warning:

https://github.com/D-Programming-Language/dmd/pull/2885

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #6 from github-bugzilla@puremagic.com 2013-11-26 23:07:47 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/e5ed1beb8ebf86314136875801c2d929ddc32b9c Merge pull request #674 from yebblies/issue4733

Remove cases where an array is used in a boolean context

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #7 from bearophile_hugs@eml.cc 2013-11-27 01:13:24 PST ---
(In reply to comment #5)
> Warning:
> 
> https://github.com/D-Programming-Language/dmd/pull/2885

The new warning is:

warning("converting dynamic arrays to boolean is deprecated, instead use
array.ptr");

For normal D programmers the right way to tell if an array (and eventually associative array) is empty is with the std.array.empty function, that tests the length. You don't want future normal D programmers to start using .ptr everywhere they want to test array emptiness.

So perhaps a better warning is:

"converting dynamic arrays to boolean is deprecated, instead use std.array.empty"

On the other hand some programmers want really meant to use ".ptr". And some programmers want to test "arr.length || arr.ptr" and so on.

So perhaps an alternative error message is:

"converting dynamic arrays to boolean is deprecated"

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733


rswhite4@googlemail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rswhite4@googlemail.com


--- Comment #8 from rswhite4@googlemail.com 2013-11-27 02:05:23 PST ---
(In reply to comment #7)
> (In reply to comment #5)
> > Warning:
> > 
> > https://github.com/D-Programming-Language/dmd/pull/2885
> 
> The new warning is:
> 
> warning("converting dynamic arrays to boolean is deprecated, instead use
> array.ptr");
> 
> For normal D programmers the right way to tell if an array (and eventually associative array) is empty is with the std.array.empty function, that tests the length. You don't want future normal D programmers to start using .ptr everywhere they want to test array emptiness.
> 
> So perhaps a better warning is:
> 
> "converting dynamic arrays to boolean is deprecated, instead use std.array.empty"
> 
> On the other hand some programmers want really meant to use ".ptr". And some programmers want to test "arr.length || arr.ptr" and so on.
> 
> So perhaps an alternative error message is:
> 
> "converting dynamic arrays to boolean is deprecated"

Or simply: use arr.length != 0

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #9 from yebblies <yebblies@gmail.com> 2013-11-27 21:12:54 EST ---
How about:

"converting dynamic arrays to boolean is deprecated, instead use std.array.empty or array.ptr"

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #10 from yebblies <yebblies@gmail.com> 2013-11-27 21:15:07 EST ---
(In reply to comment #8)
> Or simply: use arr.length != 0

That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.

--- Comment #11 from yebblies <yebblies@gmail.com> 2013-11-27 21:15:07 EST ---
(In reply to comment #8)
> Or simply: use arr.length != 0

That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #10 from yebblies <yebblies@gmail.com> 2013-11-27 21:15:07 EST ---
(In reply to comment #8)
> Or simply: use arr.length != 0

That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.

--- Comment #11 from yebblies <yebblies@gmail.com> 2013-11-27 21:15:07 EST ---
(In reply to comment #8)
> Or simply: use arr.length != 0

That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #12 from rswhite4@googlemail.com 2013-11-27 02:20:29 PST ---
(In reply to comment #11)
> (In reply to comment #8)
> > Or simply: use arr.length != 0
> 
> That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.

No need to talk to me twice. Then !arr.length. That is the same as std.array.empty and it saves you the import.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #13 from yebblies <yebblies@gmail.com> 2013-11-27 21:31:49 EST ---
(In reply to comment #12)
> (In reply to comment #11)
> > (In reply to comment #8)
> > > Or simply: use arr.length != 0
> > 
> > That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.
> 
> No need to talk to me twice. Then !arr.length. That is the same as std.array.empty and it saves you the import.

`if (!arr.length) is the same as `if (array.length != 0), and neither are the
same as `if (arr)`, which expands to `if (arr.ptr)`.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4733



--- Comment #14 from rswhite4@googlemail.com 2013-11-27 02:37:17 PST ---
(In reply to comment #13)
> (In reply to comment #12)
> > (In reply to comment #11)
> > > (In reply to comment #8)
> > > > Or simply: use arr.length != 0
> > > 
> > > That is not the same as `if (arr)`, and I don't want this to make people accidentally break their code.
> > 
> > No need to talk to me twice. Then !arr.length. That is the same as std.array.empty and it saves you the import.
> 
> `if (!arr.length) is the same as `if (array.length != 0), and neither are the
> same as `if (arr)`, which expands to `if (arr.ptr)`.

I never said that it is the same. But it's the same as std.array.empty and saves you the import. That's all.

https://github.com/D-Programming-Language/phobos/blob/master/std/array.d#L41

I would prefer that the warning consider arr.length != 0 more than std.array.empty. Nothing else. Hope you understand me now.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3