3 ms·
NULL is the lack of any string. If one view a string as a result of an operation, then an INVALID string is the consequence of bad input to an operation.
by codehero 7y ago
NULL is the lack of any string.
If one view a string as a result of an operation, then an INVALID string is the consequence of bad input to an operation.
- saagarjha 7y agoWhy can’t NULL serve as the invalid string in this case? It’s clearly not a valid string that an operation will return.
- codehero 7y agoIf you have studied Computer Science, you should know that the null string is quite a valid string. Let's take strstr, which finds a matching substring needle in a haystack string. -returns a NULL string if the needle is not in the haystack. -returns pointer to first matching substring. Extend strstr with VALIDITY Understood behaviour if both are valid. Say the haystack is INVALID...as the return value is NULL or a strict substring of haystack, should return INVALID. A poison haystack should poison dependent strings. Say the haystack is valid but the needle is INVALID...should return NULL. A valid string never contains an INVALID string as a subsequence.
- saagarjha 7y agoHere's my behavior: strstr(NULL, /* valid string */) I can't find the needle in the haystack (actually, I can't find anything in the haystack. I can't find the haystack.) Thus I return NULL. strstr(/* valid string */, NULL) I can't find the needle in the haystack (actually, I wouldn't be able to find it: I don't know what I'm looking for.) Return NULL.
- codehero 7y agoYou're explanation is not inconsistent with my proposal, but you don't seem to grasp VALIDITY.