This post is an extension to my original post on IFNULL.
The comments it received (thanks to everyone) got me thinking a little differently and somewhat deeper (I think). The upshot is that I propose this as a workable improvement to the current IFNULL
function:
new IFNULL
IFNULL(expr1, expr2, expr3)
Its structure matches the language:
IF expr1 IS NULL
THEN expr2
ELSE expr3
Benefits
- The logic is clear and transparent.
-
It's more powerful and flexible, with the opportunity to provide an explicit non-NULL value when
expr1
IS NULL. - It avoids backwards compatibility problems—a new function, it doesn't conflict with existing calculations.
Drawbacks
-
In the normal (maybe) case,
expr3
will be the same asexpr1
; this will be a bit if a cognitive burden, but not all that much.
About the current IFNULL
new - Mapping IFNULL parsing
I'm adding this section because I'm pretty sure that my objection to the current IFNULL operation is clear. So, pictures being better than words in some circumstances, I mapped it out:
Even though these formulations are logically equivalent, I'm confident that the second one is clearer than the first, and it matches the current IFNULL documentation in the function editor.
The problem with the second reading is that the function's name is the reading's negation. It's this collision that I'm urging be fixed.
I understand that the current formulation is readable by programmers and technical people who are experienced in interpreting these things (I've been at it since 1974). But, and this really is the whole point of this blog, Tableau was invented to move data analysis and visualization from the technical-only realm and open it up to non-technical people who need to understand their data but shouldn't be burdened with the arcane technical aspects. Every single thing that's not as clear and transparent as it could be is an impediment to real human people. Forcing non-technical people to adapt to the technical conventions is contrary to the whole idea of eliminating the friction between between people and the information and insights in their data.
addendum to original post
Note: in my original post's comments, this section was unclear because I used angle brackets—< and >, and these were interpreted as invalid tags and not shown. Sorry about that.
In a nutshell, my objection to the current IFNULL(expr1,expr2)
function is that from a human standpoint, the reader has to figure out:
- what, exactly, is being evaluated to see if it's null, and depending upon the assessment:
- what positive action is being taken when it is null, and
- what positive action is being taken when it's not null.
If I have it right (it's been a long time since undergraduate logic class), the two semantic constructions for {FUNCTION}(expr1,expr2)
are:
-
If {IS NOT NULL -expr1-}, then return expr1 else return expr2
-
If {IS NULL -expr1-}, then return expr2 else return expr1
-
parses strictly right to left and is easy to understand
- requires a forward leapfrog when -expr1- IS NULL, followed by a backreference when -expr1- IS NOT NULL, and is, at least for me, twisty and unclear
I believe that:
- 1. is better than 2., and
- the documentation describes 1., although it's not as clearly worded as it could be.
I understand the problems associated with 1., most notably that a negative expression is typically harder to parse and a negative–null coupling is doubly difficult to wrap one's head around, and changing the expression causes backward compatibility problems (and Tableau hasn't yet implemented self-analysis).
Footnote: I'm sure someone could do a better job on the logical formalisms.