Re: string - null/bool implicit conversion

2015-08-24 Thread Kagamin via Digitalmars-d
On Friday, 21 August 2015 at 20:01:21 UTC, Vladimir Panteleev wrote: This warning almost doesn't break any code! Yes it flipping does. It does break some code, but only in certain extremely specialized contexts like memory allocation! No it's bleeping not. Many of those warnings are probably

Re: string - null/bool implicit conversion

2015-08-24 Thread Kagamin via Digitalmars-d
On Saturday, 22 August 2015 at 21:23:19 UTC, Timon Gehr wrote: For the comma operator, I think it's pretty clear that the usage of ',' to separate components of a tuple would be more useful. Why not use C/C++/C# initializer syntax? Technically it's a tuple, but not related to comma operator.

Re: string - null/bool implicit conversion

2015-08-24 Thread Kagamin via Digitalmars-d
On Friday, 21 August 2015 at 11:34:42 UTC, Marc Schütz wrote: On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal.

Re: string - null/bool implicit conversion

2015-08-23 Thread ponce via Digitalmars-d
On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Hi! string a = ; string b; writeln(a ? a : null); writeln(b ? b : null); This program outputs: a null What? I suppose this is by design, but are there any plans to deprecate this? Sounds correct to me.

Re: string - null/bool implicit conversion

2015-08-22 Thread Timon Gehr via Digitalmars-d
On 08/22/2015 12:04 AM, Jonathan M Davis wrote: On Friday, 21 August 2015 at 21:13:35 UTC, David Nadlinger wrote: On Friday, 21 August 2015 at 20:01:21 UTC, Vladimir Panteleev wrote: This warning almost doesn't break any code! It indeed doesn't break almost any code. Yours is quite the

Re: string - null/bool implicit conversion

2015-08-22 Thread deadalnix via Digitalmars-d
On Saturday, 22 August 2015 at 21:23:19 UTC, Timon Gehr wrote: For the comma operator, I think it's pretty clear that the usage of ',' to separate components of a tuple would be more useful. (With L-T-R evaluation, replacing usages of the comma operator is easy, e.g. 'a,b,c' becomes

Re: string - null/bool implicit conversion

2015-08-22 Thread Timon Gehr via Digitalmars-d
On 08/23/2015 01:09 AM, deadalnix wrote: On Saturday, 22 August 2015 at 21:23:19 UTC, Timon Gehr wrote: For the comma operator, I think it's pretty clear that the usage of ',' to separate components of a tuple would be more useful. (With L-T-R evaluation, replacing usages of the comma operator

Re: string - null/bool implicit conversion

2015-08-21 Thread Timon Gehr via Digitalmars-d
On 08/22/2015 02:04 AM, deadalnix wrote: On Thursday, 20 August 2015 at 20:39:01 UTC, Timon Gehr wrote: On 08/20/2015 10:26 PM, David Nadlinger wrote: On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Having 2 empty strings evaluate differently is very unintuitive and

Re: string - null/bool implicit conversion

2015-08-21 Thread via Digitalmars-d
On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal. If you really want to check for null, then you need to use is

Re: string - null/bool implicit conversion

2015-08-21 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 11:15 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 20:43:39 UTC, Steven Schveighoffer wrote: This makes me think you misunderstand what I am doing. If you care about whether an array is empty, you check whether its length is 0 or you call empty (which checks whether

Re: string - null/bool implicit conversion

2015-08-21 Thread Timon Gehr via Digitalmars-d
On 08/21/2015 12:50 PM, Steven Schveighoffer wrote: So checking whether the array is null (i.e. empty) *is* what I'm doing, Nah, you're checking whether it /equals/ null. :-)

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 10:50:40 UTC, Steven Schveighoffer wrote: On 8/20/15 11:15 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 20:43:39 UTC, Steven Schveighoffer wrote: This makes me think you misunderstand what I am doing. If you care about whether an array is empty, you

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 13:54:04 UTC, Vladimir Panteleev wrote: Also, at least spell my name right please. Sorry. - Jonathan M Davis

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 09:14:16 UTC, Kagamin wrote: On Thursday, 20 August 2015 at 20:26:09 UTC, David Nadlinger wrote: It's even worse: http://dpaste.dzfl.pl/ba3376feca8e The arrays are equal, but their Boolean value is not. I don't get how Andrei can reconcile this with his D avoids

Re: string - null/bool implicit conversion

2015-08-21 Thread Steven Schveighoffer via Digitalmars-d
On 8/21/15 10:12 AM, Jonathan M Davis wrote: I know full-well that that's what you're doing, but that's not what your average programmer is going to expect. Anyone not intimately familiar with the ins and outs of D's arrays - or even a D programmer who's not paying really close attention - is

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 11:43:11 UTC, Steven Schveighoffer wrote: On 8/21/15 7:34 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr

Re: string - null/bool implicit conversion

2015-08-21 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 20 August 2015 at 17:32:24 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:01:07 UTC, anonymous wrote: A compiler change disallowing such use of arrays was done and then reverted. See https://issues.dlang.org/show_bug.cgi?id=4733. I haven't followed things closely

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 14:34:49 UTC, Steven Schveighoffer wrote: On 8/21/15 10:12 AM, Jonathan M Davis wrote: I know full-well that that's what you're doing, but that's not what your average programmer is going to expect. Anyone not intimately familiar with the ins and outs of D's

Re: string - null/bool implicit conversion

2015-08-21 Thread David Nadlinger via Digitalmars-d
On Friday, 21 August 2015 at 13:54:04 UTC, Vladimir Panteleev wrote: It broke a crapton of my code. … in a way for which a fix is trivial to automate, even without a full-fledged parser. – David

Re: string - null/bool implicit conversion

2015-08-21 Thread via Digitalmars-d
On Friday, 21 August 2015 at 13:54:04 UTC, Vladimir Panteleev wrote: On Thursday, 20 August 2015 at 17:32:24 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:01:07 UTC, anonymous wrote: A compiler change disallowing such use of arrays was done and then reverted. See

Re: string - null/bool implicit conversion

2015-08-21 Thread David Nadlinger via Digitalmars-d
On Friday, 21 August 2015 at 20:01:21 UTC, Vladimir Panteleev wrote: This warning almost doesn't break any code! It indeed doesn't break almost any code. Yours is quite the outlier. — David

Re: string - null/bool implicit conversion

2015-08-21 Thread Timon Gehr via Digitalmars-d
On 08/21/2015 10:01 PM, Vladimir Panteleev wrote: I just write code this way, because I find the empty/null distinction obvious and useful. Shocking, I know. One of the main reasons this might be considered shocking is because DMD does not cleanly make this distinction. [] is null.

Re: string - null/bool implicit conversion

2015-08-21 Thread Vladimir Panteleev via Digitalmars-d
On Friday, 21 August 2015 at 16:55:18 UTC, David Nadlinger wrote: On Friday, 21 August 2015 at 13:54:04 UTC, Vladimir Panteleev wrote: It broke a crapton of my code. … in a way for which a fix is trivial to automate, even without a full-fledged parser. Sure. All things considered, I'm not

Re: string - null/bool implicit conversion

2015-08-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, 21 August 2015 at 21:13:35 UTC, David Nadlinger wrote: On Friday, 21 August 2015 at 20:01:21 UTC, Vladimir Panteleev wrote: This warning almost doesn't break any code! It indeed doesn't break almost any code. Yours is quite the outlier. In general, it gets a bit interesting when

Re: string - null/bool implicit conversion

2015-08-21 Thread Steven Schveighoffer via Digitalmars-d
On 8/21/15 7:34 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should

Re: string - null/bool implicit conversion

2015-08-21 Thread Timon Gehr via Digitalmars-d
On 08/21/2015 01:34 PM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null

Re: string - null/bool implicit conversion

2015-08-21 Thread via Digitalmars-d
On Friday, 21 August 2015 at 11:43:11 UTC, Steven Schveighoffer wrote: On 8/21/15 7:34 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: I disagree. `is null` is the one that should be illegal. `is` is supposed to do a bitwise comparison, but `null` is usually just a pointer/reference,

Re: string - null/bool implicit conversion

2015-08-21 Thread Timon Gehr via Digitalmars-d
On 08/21/2015 01:43 PM, Steven Schveighoffer wrote: null is technically a no-type placeholder (defaulting to void * without context). It now defaults to typeof(null), which is a distinct type from void*. The same is confusingly not true for [] though, which still defaults to void[].

Re: string - null/bool implicit conversion

2015-08-21 Thread deadalnix via Digitalmars-d
On Thursday, 20 August 2015 at 20:39:01 UTC, Timon Gehr wrote: On 08/20/2015 10:26 PM, David Nadlinger wrote: On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Having 2 empty strings evaluate differently is very unintuitive and error-prone, in my opinion. It's even worse:

Re: string - null/bool implicit conversion

2015-08-21 Thread deadalnix via Digitalmars-d
On Friday, 21 August 2015 at 11:34:42 UTC, Marc Schütz wrote: On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal.

Re: string - null/bool implicit conversion

2015-08-21 Thread Kagamin via Digitalmars-d
On Thursday, 20 August 2015 at 20:26:09 UTC, David Nadlinger wrote: It's even worse: http://dpaste.dzfl.pl/ba3376feca8e The arrays are equal, but their Boolean value is not. I don't get how Andrei can reconcile this with his D avoids unforced errors stance. The only technical excuse for the

Re: string - null/bool implicit conversion

2015-08-20 Thread anonymous via Digitalmars-d
On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Hi! string a = ; string b; writeln(a ? a : null); writeln(b ? b : null); This program outputs: a null What? I suppose this is by design, but are there any plans to deprecate this? A compiler change disallowing such

Re: string - null/bool implicit conversion

2015-08-20 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 20 August 2015 at 20:43:39 UTC, Steven Schveighoffer wrote: This makes me think you misunderstand what I am doing. If you care about whether an array is empty, you check whether its length is 0 or you call empty (which checks whether the length is 0). If you care about whether

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 07:50 PM, Steven Schveighoffer wrote: Very true. Not much we can do about it. For now, the best thing to do is always compare arrays to null instead of simply if(arr): if(arr != null) Alternatively, but a little more ugly, is to check the length: if(arr.length) Isn't the best

Re: string - null/bool implicit conversion

2015-08-20 Thread via Digitalmars-d
On Thursday, 20 August 2015 at 18:04:00 UTC, Steven Schveighoffer wrote: On 8/20/15 1:50 PM, Steven Schveighoffer wrote: The truthiness of an array says it's true ONLY if both the pointer and length are 0. Ugh, *false* only if they are both 0. If either are not zero, then it's true.

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 08:05 PM, H. S. Teoh via Digitalmars-d wrote: On Thu, Aug 20, 2015 at 01:50:11PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...] The main reason why it caused issues is this nice idiom: if(auto arr = someFunction()) { // use arr } This would HAVE to be split out

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 07:32 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:01:07 UTC, anonymous wrote: A compiler change disallowing such use of arrays was done and then reverted. See https://issues.dlang.org/show_bug.cgi?id=4733. I haven't followed things closely enough to give you a

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 1:50 PM, Steven Schveighoffer wrote: The truthiness of an array says it's true ONLY if both the pointer and length are 0. Ugh, *false* only if they are both 0. If either are not zero, then it's true. -Steve

Re: string - null/bool implicit conversion

2015-08-20 Thread H. S. Teoh via Digitalmars-d
On Thu, Aug 20, 2015 at 01:50:11PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...] The main reason why it caused issues is this nice idiom: if(auto arr = someFunction()) { // use arr } This would HAVE to be split out to two statements, and the arr variable would be scoped

Re: string - null/bool implicit conversion

2015-08-20 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 20 August 2015 at 17:01:07 UTC, anonymous wrote: A compiler change disallowing such use of arrays was done and then reverted. See https://issues.dlang.org/show_bug.cgi?id=4733. I haven't followed things closely enough to give you a good summary. Basically, almost everyone wanted

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 12:45 PM, =?UTF-8?B?Ik3DoXJjaW8=?= Martins\ marcio...@gmail.com\ wrote: Hi! string a = ; string b; writeln(a ? a : null); writeln(b ? b : null); This program outputs: a null What? I suppose this is by design, but are there any plans to deprecate this? The truthiness of an

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 10:38 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote: On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, ==

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 10:43 PM, Steven Schveighoffer wrote: On 8/20/15 4:38 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote: On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 4:45 PM, Timon Gehr wrote: On 08/20/2015 10:43 PM, Steven Schveighoffer wrote: On 8/20/15 4:38 PM, Jonathan M Davis wrote: And why would you want that? The length is meaningless if the pointer is null. It shouldn't even be possible for the length to be anything other than zero if

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 4:38 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote: On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null

Re: string - null/bool implicit conversion

2015-08-20 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote: On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal. If you really

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 10:26 PM, David Nadlinger wrote: On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Having 2 empty strings evaluate differently is very unintuitive and error-prone, in my opinion. It's even worse: http://dpaste.dzfl.pl/ba3376feca8e The arrays are equal, but

Re: string - null/bool implicit conversion

2015-08-20 Thread via Digitalmars-d
On Thursday, 20 August 2015 at 18:42:56 UTC, Márcio Martins wrote: On Thursday, 20 August 2015 at 18:04:00 UTC, Steven Schveighoffer wrote: On 8/20/15 1:50 PM, Steven Schveighoffer wrote: The truthiness of an array says it's true ONLY if both the pointer and length are 0. Ugh, *false* only

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 3:04 PM, =?UTF-8?B?Ik3DoXJjaW8=?= Martins\ marcio...@gmail.com\ wrote: On Thursday, 20 August 2015 at 18:42:56 UTC, Márcio Martins wrote: On Thursday, 20 August 2015 at 18:04:00 UTC, Steven Schveighoffer wrote: On 8/20/15 1:50 PM, Steven Schveighoffer wrote: The truthiness of an

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 09:54 PM, Steven Schveighoffer wrote: On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal. If you really want to check for

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 09:08 PM, Steven Schveighoffer wrote: On 8/20/15 2:49 PM, Timon Gehr wrote: On 08/20/2015 08:05 PM, H. S. Teoh via Digitalmars-d wrote: On Thu, Aug 20, 2015 at 01:50:11PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...] The main reason why it caused issues is this nice

Re: string - null/bool implicit conversion

2015-08-20 Thread David Nadlinger via Digitalmars-d
On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote: Having 2 empty strings evaluate differently is very unintuitive and error-prone, in my opinion. It's even worse: http://dpaste.dzfl.pl/ba3376feca8e The arrays are equal, but their Boolean value is not. I don't get how Andrei

Re: string - null/bool implicit conversion

2015-08-20 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal. If you really want to check for null, then you need to use is null or !is null, whereas if you want to check that an array is

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 3:41 PM, Jonathan M Davis wrote: On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote: if(arr != null) Definitely don't do that. IMHO, == null and != null should be illegal. If you really want to check for null, then you need to use is null or !is null, whereas

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 2:49 PM, Timon Gehr wrote: On 08/20/2015 08:05 PM, H. S. Teoh via Digitalmars-d wrote: On Thu, Aug 20, 2015 at 01:50:11PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...] The main reason why it caused issues is this nice idiom: if(auto arr = someFunction()) { // use

Re: string - null/bool implicit conversion

2015-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/15 2:43 PM, Timon Gehr wrote: On 08/20/2015 07:50 PM, Steven Schveighoffer wrote: Very true. Not much we can do about it. For now, the best thing to do is always compare arrays to null instead of simply if(arr): if(arr != null) Alternatively, but a little more ugly, is to check the

Re: string - null/bool implicit conversion

2015-08-20 Thread Timon Gehr via Digitalmars-d
On 08/20/2015 09:08 PM, Steven Schveighoffer wrote: On 8/20/15 2:43 PM, Timon Gehr wrote: On 08/20/2015 07:50 PM, Steven Schveighoffer wrote: Very true. Not much we can do about it. For now, the best thing to do is always compare arrays to null instead of simply if(arr): if(arr != null)

string - null/bool implicit conversion

2015-08-20 Thread via Digitalmars-d
Hi! string a = ; string b; writeln(a ? a : null); writeln(b ? b : null); This program outputs: a null What? I suppose this is by design, but are there any plans to deprecate this? I understand this happens because in this context, string.ptr is evaluated, but should a string really