Re: null == "" is true?

2022-07-20 Thread Antonio via Digitalmars-d-learn
On Wednesday, 20 July 2022 at 13:35:14 UTC, Kagamin wrote: On Tuesday, 19 July 2022 at 18:05:34 UTC, Antonio wrote: In a relational database, `NULL` is not the same that `""`... and `NULL` is not the same that `0`. Are semantically different and there are database invariants (like foreign key

Re: null == "" is true?

2022-07-20 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 18:05:34 UTC, Antonio wrote: In a relational database, `NULL` is not the same that `""`... and `NULL` is not the same that `0`. Are semantically different and there are database invariants (like foreign keys) based on it. Trying to "mix" this concepts in a databas

Re: null == "" is true?

2022-07-20 Thread Antonio via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 16:55:39 UTC, Kagamin wrote: As I understand, in your scenario there's no difference between null string and empty string, they both work like empty string, and D treats them as empty string. That's what I mean when I said that distinction between null and empty is

Re: null == "" is true?

2022-07-19 Thread Antonio via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 17:05:27 UTC, Kagamin wrote: Also what's the difference between null and empty phone number? In a relational database, `NULL` is not the same that `""`... and `NULL` is not the same that `0`. Are semantically different and there are database invariants (like fore

Re: null == "" is true?

2022-07-19 Thread Kagamin via Digitalmars-d-learn
Also what's the difference between null and empty phone number?

Re: null == "" is true?

2022-07-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 10:29:40 UTC, Antonio wrote: The summary is that a DTO that works like a Map needs to represent the absent key ant this is not the same that the Null value Example: ```d struct Null { /*...*/ } struct Undefined { /*...*/ } struct ContactDto { DtoVal!(Undefined, str

Re: null == "" is true?

2022-07-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 15:30:30 UTC, Bienlein wrote: If the destination of a carrier was set to null, it implied that the destination was currently undefined. Then the robot brought the carrier to some rack where it was put aside for a while till the planning system had created a new produ

Re: null == "" is true?

2022-07-19 Thread Bienlein via Digitalmars-d-learn
why? Because an empty string is, by default, represented by an empty slice of the null pointer. I don't program in D. I just read from time to time posts in the D forum because of the good quality of what people write. So, I'm not proficient in D, but in general internals should not boil up

Re: null == "" is true?

2022-07-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 10:29:40 UTC, Antonio wrote: NULL is not the same that UNDEFINED The distintion is really important: NULL is a valid value (i.e.: The person phonenumber is NULL in database)... Of course, you can represent this concept natively in you language (Nullable, Optional,

Re: null == "" is true?

2022-07-19 Thread Antonio via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 08:10:25 UTC, Kagamin wrote: On Monday, 18 July 2022 at 21:23:32 UTC, Antonio wrote: I will study it in detail and report (if required). May be, I will write the DTO problem with D article if I find time in august. In my experience null and empty in DTOs usually pl

Re: null == "" is true?

2022-07-19 Thread Kagamin via Digitalmars-d-learn
On Monday, 18 July 2022 at 21:23:32 UTC, Antonio wrote: I will study it in detail and report (if required). May be, I will write the DTO problem with D article if I find time in august. In my experience null and empty in DTOs usually play the same logical role. It's a very contrived technical

Re: null == "" is true?

2022-07-18 Thread Antonio via Digitalmars-d-learn
On Monday, 18 July 2022 at 17:20:04 UTC, Kagamin wrote: ... If you want such difference, use the Nullable wrapper or Algebraic. I do :-) In fact, I use algebraic types supporting Null and Undefined for DTOs representation (and REST APIs). But I discovered some "rare" side effects in librari

Re: null == "" is true?

2022-07-18 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 18 July 2022 at 17:20:04 UTC, Kagamin wrote: Difference between null and empty is useless. Not really. `null` typically means that the value is missing, irrelevant and not usable, which is quite different from having "" as a usable value.

Re: null == "" is true?

2022-07-18 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 20:36:03 UTC, Antonio wrote: Honestly, it is difficult to understand for newcomers... there is a reason, but there is a reason in javascript for `0 == ''` too People would have different preferences there. Difference between null and empty is useless. D does the ri

Re: null == "" is true?

2022-07-15 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 15 July 2022 at 11:12:07 UTC, Steven Schveighoffer wrote: Note that the term `null` and `[]` are special tokens that morph type to whatever is most appropriate at the time. `null` implicitly can be typed as any pointer type, or any array type. `[]` can be typed as any array type. How

Re: null == "" is true?

2022-07-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 15 July 2022 at 06:38:58 UTC, Salih Dincer wrote: Consider null type array which is a related topic but it cannot get a null element! The first is ok, but the second is legal. So no effect, is it normal? ```d auto p = [ null, null ];//* assert( is(typeof(null)[] : type

Re: null == "" is true?

2022-07-14 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 22:58:32 UTC, Steven Schveighoffer wrote: ```d string a = "abcabc"; assert(a[0 .. 3] == a[3 .. $]) assert(a[0 .. 3] !is a[3 .. $]) ``` The point is, `==` compares *value*, `is` always compares *identity*. Consider null type array which is a related topic but it ca

Re: null == "" is true?

2022-07-14 Thread Palak via Digitalmars-d-learn
Hi @Steven Schveighoffer, Yes solution looking useful and sure it will work. Thanks.

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 4:36 PM, Antonio wrote: On Tuesday, 12 July 2022 at 18:56:43 UTC, Paul Backus wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's possible so

Re: null == "" is true?

2022-07-12 Thread Antonio via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 20:36:03 UTC, Antonio wrote: Honestly, it is difficult to understand for newcomers... there is a reason, but there is a reason in javascript for `0 == ''` too Correction ```d string a = null; assert(a is null); assert(a == ""); string b = ""; assert(b !is null); a

Re: null == "" is true?

2022-07-12 Thread Antonio via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 18:56:43 UTC, Paul Backus wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's possible sometimes to get an empty string that

Re: null == "" is true?

2022-07-12 Thread user1234 via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 19:55:46 UTC, ag0aep6g wrote: On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: [...] Do not rely on this, however; Absolutely. I'd like to add: especially as default parameter value that's an ar

Re: null == "" is true?

2022-07-12 Thread ag0aep6g via Digitalmars-d-learn
On 12.07.22 22:14, H. S. Teoh wrote: Pedantically, no, they're not the same. You can assign null to a pointer, but you can't assign [] to a pointer. `null` is a supertype of `[]`. But probably nobody actually cares about this distinction. :-D If we're ignoring context, "null" has four characte

Re: null == "" is true?

2022-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2022 at 07:55:46PM +, ag0aep6g via Digitalmars-d-learn wrote: > On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote: > > On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: > [...] > > > Do not rely on this, however; > > > > Absolutely. I'd like to add: especially

Re: null == "" is true?

2022-07-12 Thread ag0aep6g via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: [...] Do not rely on this, however; Absolutely. I'd like to add: especially as default parameter value that's an array. Never use null. use `[]` (empty array literal). Jus

Re: null == "" is true?

2022-07-12 Thread user1234 via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: On Tue, Jul 12, 2022 at 04:27:44PM +, Antonio via Digitalmars-d-learn wrote: It works ```d void main() { assert(null==""); } ``` why? Because an empty string is, by default, represented by an empty slice of the null pointer.

Re: null == "" is true?

2022-07-12 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's possible sometimes to get an empty string that isn't null, e.g., if you incrementally shrink a slice over a

Re: null == "" is true?

2022-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 7/12/22 10:11, Steven Schveighoffer wrote: > The algorithm to compare *any* arrays is first verify the lengths are > the same. Then for each element in the array, compare them. Since there > are 0 elements in both the empty string and the null string, they are > equal. Checking .empty() cover

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 12:40 PM, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. No, it's not a null pointer. It's a pointer to a zero-character. But it is indeed an empty slice. -Steve

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 12:27 PM, Antonio wrote: It works ```d void main() {    assert(null==""); } ``` why? A string is not exactly a reference type. It's a length and a pointer. This can be confusing to newcomers, especially ones that come from languages that treat arrays and strings as object refere

Re: null == "" is true?

2022-07-12 Thread Hipreme via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: On Tue, Jul 12, 2022 at 04:27:44PM +, Antonio via Digitalmars-d-learn wrote: It works ```d void main() { assert(null==""); } ``` why? Because an empty string is, by default, represented by an empty slice of the null pointer.

Re: null == "" is true?

2022-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2022 at 04:27:44PM +, Antonio via Digitalmars-d-learn wrote: > It works > > ```d > void main() > { >assert(null==""); > } > ``` > > why? Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's possible

null == "" is true?

2022-07-12 Thread Antonio via Digitalmars-d-learn
It works ```d void main() { assert(null==""); } ``` why?