in reply to Re: How do I test for a NULL string?
in thread How do I test for a NULL string?

The simple answer, which is probably "right" for much of the audience is to explain undef and how you test for it.
You show your SQL bias as much as djantzen shows his C bias!

There is no "right" answer for "much of the audience", except to ask what is meant. And that's my original point. My litany of possible responses is meant to describe how many "right" answers there could be possibly, and no answer is more right than any of the others, except determined by context!

-- Randal L. Schwartz, Perl hacker

  • Comment on Re: Re: How do I test for a NULL string?

Replies are listed 'Best First'.
Re: Re: Re: How do I test for a NULL string?
by djantzen (Priest) on Feb 13, 2002 at 18:53 UTC

    1. The phrase 'NULL string' has a well-known and precise meaning in C ('""').

    2. Whatever meaning this phrase has in SQL is derived from it's meaning in C. It does not have the well-known and precise meaning in the former as in the latter and the question 'How do I test for a SQL NULL string?' is better rephrased 'How do I test if a char/varchar field declared 'NULL' contains a C-style NULL string ('""')?'.

    3. Employing the eminent philosopher of language Donald Davidson, I introduce "the principle of charity", according to which a listener wishing to interpret a speaker accurately "must maximize the self-consistency attribut(ed) to him, on pain of not understanding him" (From "Truth and Meaning").

    While the term 'NULL' is obviously part of SQL, and it is not impossible to define the phrase 'NULL string' within the semantics of SQL, it does not follow that it is equally likely that the questioner was in fact importing those semantics rather than the semantics of C.

    Similarly, although the romance languages share cognates derived from Latin, take libre for example, when I speak Spanish I am not also speaking French by virtue of the shared term. In such a situation the listener must determine from the context which language I am speaking. If I make the utterance "Creo en habla libre, y cerveza gratis", it is wholly incorrect to believe that I am speaking French, but poorly, because an interpretation of the utterance that attributes self-consistency to me is available. To conclude that I am speaking French on the basis of the appearance of "libre" is to attribute to me a great deal of nonsense surrounding that one term, and this is not sound interpretation.

    Therefore, because there is a well-known and precise meaning available to the phrase 'NULL string', and because I believe that the principle of charity will yield in general better interpretation, to conclude that the speaker refers to it's meaning in C is a reasonable conclusion, indeed, more reasonable than any other, including SQL.

    Now according to merlyn's clarifications, his point is that the listener must be sensitive to different meanings possibly at work in a question. This is fine, however I would suggest that an orthogonal pressure here ought to be the principle of charity. It is better to risk thinking too highly of your interlocutor than to assume immediately that his utterances are largely nonsense. If the point here is not to give a real answer to the question 'How do I test for a NULL string', for which there is a sensible answer in Perl, but to give an exhortation to be careful about importing meanings carelessly across language boundaries, then I suggest the question be rephrased in such a way that the principle of charity not demand a particular interpretation. The rather more innucuous "How do I test for a string that is null?" would make the point better.

      You continue to miss the point here.
      • You cannot control how they ask it.
      • You cannot presume what context they are using.
      • You cannot even presume that they are perfect in constructing the question even if you could know the context.
      You can theorize all you want. In practice, I've heard "NULL string" mean all of the things I've listed, whether that was right, wrong, or even possible! And learning to deal with that ambiguity makes me a better answerer.

      -- Randal L. Schwartz, Perl hacker

        You cannot control how they ask it. You cannot presume what context they are using. You cannot even presume that they are perfect in constructing the question even if you could know the context.

        I agree, however I'm not presuming anything. I am, at least initially, trying to attribute a self-consistent set of beliefs to the person asking because this in general facilitates understanding among speakers.

        learning to deal with that ambiguity makes me a better answerer.

        But wouldn't you have saved yourself some time by asking the simple clarifying question, "Are you referring to the empty string in C?", which is a starting point justified by the wording of the question. If at this point they indicate a lack of understanding, then move forward in a different manner.