Subject: [netmod] 1 when-stmt vs. N must-stmt

From: Andy Bierman <[email-masked]>
Date: Sun, 29 Nov 2009 09:51:54 -0800

Hi,

It seems odd to me that only 1 when-stmt is allowed
instead of AND-ing N of them together, like must-stmt.

There is already an implicit AND of when-stmts via
uses-stmt chain and augment-stmt chain.

The use-cases are really the same as must-stmt:
   - more flexibility for the YANG writer
   - easier to read for non-XPath experts
   - allows new 'when' constraints to be added
     to existing 'when' constraints more cleanly

We force all 'when' constraints into 1 giant XPath
expression, but not 'must' constraints.
Do we have a good reason for doing this,
and I just missed that meeting?

Andy

---

From: Martin Bjorklund <[email-masked]>
Date: Mon, 30 Nov 2009 08:25:27 +0100 (CET)

Hi,

> uses-stmt chain and augment-stmt chain.

I don't understand what you mean.  Can you give an example?

>      to existing 'when' constraints more cleanly

When you look at multiple XPath expressions, you can view each of them
independently - each such must expression must be true in a valid data
model.  When you write multiple must expressions, you probably make
them independent, i.e. each must expression verifies one specific
property.

If we had multiple when expressions that were AND:ed together, you can
not view each of them independently.  If one such when expression is
true, the object does not necessarily exist.  

Another way of seeing this is that the data model makes sense even if
you don't take all must expressions into account, but with AND:ed when
expressions, you need to take all of them into account in order to
understand the data model.

> and I just missed that meeting?

I think we allowed mulitple must expressions so that you can have
different error-message and/or error-app-tag statements for
independent expressions.  This doesn't apply to when.

/martin

---

From: Andy Bierman <[email-masked]>
Date: Mon, 30 Nov 2009 01:55:08 -0800

> I don't understand what you mean.  Can you give an example?

uses-stmt and augment-stmt both allow
the when-stmt, right?  These get added
in with the normal when-stmt:

   grouping x {
      leaf bar {
         when "../foo > 3";
         type string;
      }
      leaf foo { type int32; }
   }

   ...

   uses x {
     when "/a > 4";
   }

This obviously creates a combined 'when-stmt':
   when "(../foo > 3) and (/a > 4)";

The AND expression can grow via augment and
uses-stmt within groupings.

> them independent, i.e. each must expression verifies one specific

The same is true for 'when' stmt.
All of them must be true for the expression to be true.
I don't see how must-stmt is any different than when-stmt
in this respect.

> true, the object does not necessarily exist.  

This is nonsense.
Of course you can view them
just as independently as must-stmt,
which is not at all.  Must-stmts are
not independent.  They are all ANDed together,
so ignoring some of them is not possible.

> understand the data model.

There is no difference between must and when in this area.

> independent expressions.  This doesn't apply to when.

The ANDing of must-stmts is
no different than the ANDing of when-stmts
from a data modeling perspective.

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 30 Nov 2009 14:03:53 +0100

> and I just missed that meeting?

In my view, the 'when' mechanism is very scary, so I wouldn't make it
any easier to use. More restrictions may actually be needed, because
'when' can lead to situations like this:

leaf foo {
    type uint8;
    default 42;
    when "bar!=1";
}
leaf bar {
    type uint8;
    default 1;
    when "foo!=42";
}

If neither "foo" nor "bar" is present in an XML instance, we are in a
nice deadlock: if the defaults apply, 'when' statements make both leafs
invalid and so the defaults cannot apply.  

Lada

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 30 Nov 2009 14:28:52 +0100

Sorry, the XPath expressions were wrong, this is the correct version:

>     when "not(../bar=1)";
>     when "not(../foo=42)";

Lada

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Andy Bierman <[email-masked]>
Date: Mon, 30 Nov 2009 07:54:11 -0800

> 'when' can lead to situations like this:

Logic would suggest that the more difficult
it is to use, the more scary it becomes, not the
other way around.

> invalid and so the defaults cannot apply.  

What does this have to do with splitting a big AND expression
into multiple sub-expressions?  The scenario you describe
is a problem even with 1 when-stmt per leaf.

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 30 Nov 2009 17:24:24 +0100

> it is to use, the more scary it becomes, not the

The easier it is to use, the more module authors may be tempted to
really use it. Mostly (always?) there are alternatives for expressing
the same constraint, e.g., using 'must'.

> is a problem even with 1 when-stmt per leaf.

Indeed, but multiple statements may create unexpected combinations,
especially when one part comes from a remote place via augment.
A single expression can always be inspected in its entirety.

What does actually 'when' under 'uses' mean? This case seems to be
missing in Sec. 7.19.5.

Lada 

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Andy Bierman <[email-masked]>
Date: Mon, 30 Nov 2009 09:06:25 -0800

> A single expression can always be inspected in its entirety.

We already have this situation.
The when-stmts can be spread out all over
the place -- that is the nature of groupings.

My proposal does not affect any of these
issues that have been raised.

CURRENT:

   leaf X {
      when "A and B and C";
      must D;
      must E;
      must F;
      type string;
   }

PROPOSED:

   leaf X {
      when A;
      when B;
      when C;
      must D;
      must E;
      must F;
      type string;
   }

>From an XPath POV, there is no reason whatsoever
to treat must-stmt differently than when-stmt.

>From an implementation POV, the server already knows
how to AND some XPath expressions together because
must-stmt requires this functionality.

Why doesn't the when-stmt have description-stmt and
reference-stmt sub-clauses like must-stmt?

This is a good use-case for needing to split the
when-stmt into multiple sub-expressions.

   must-stmt           = must-keyword sep string optsep
                         (";" /
                          "{" stmtsep
                              ;; these stmts can appear in any order
                              [error-message-stmt stmtsep]
                              [error-app-tag-stmt stmtsep]
                              [description-stmt stmtsep]
                              [reference-stmt stmtsep]
                           "}")

  when-stmt           = when-keyword sep string stmtend

Does the WG think that XPath expressions for 'must' constraints
will be hard to understand, but not 'when' expressions?  If so, why?

> What does actually 'when' under 'uses' mean? This case seems to be

It means the uses-stmt does not really get expanded
except when the when-stmt expression is true.
The 'static' schema tree for the database changes on the fly,
based on the contents of the database. (Talk about scary...)

Andy