xsl-list
[Top] [All Lists]

Re: [xsl] Best practice for typing?

2019-11-22 20:26:14
  On Fri, Nov 22, 2019 at 5:43 PM David Birnbaum djbpitt(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
.  .  .

Is there consensus among XSLT developers about whether it might be better
to use @as everywhere it is allowed,
or, alternatively, better to avoid using it redundantly? What is the
practice of other readers of this list?

I believe specifying the type everywhere is better than relying on the XSLT
processor's type inference capability -- and sometimes being surprised by
these ...

Another benefit that cannot be overestimated is that this forces the
programmer to think in types, and thinking in types (especially finding the
correct types) is sometimes 90% of the solution to a problem in a typed FP
language. One example is the case when there is no contradiction in the
declared and the (run-time) used type but just looking at the type the
programmer realizes that another, better type should be used.

Readability is also greatly enhanced when types are explicitly stated.

We don't have generics in XSLT, but even in a language that supports
generics, using and naming the right type variable prevents type errors and
enhances readability. Maybe type aliases can also help for this (I believe
these are implemented as Saxon extensions ???).

Just my 2¢.  :)

Dimitre

On Fri, Nov 22, 2019 at 5:43 PM David Birnbaum djbpitt(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Dear xsl-list,

Is there a consensus about best practice with respect to possibly
redundant typing? For example, we can specify a type using @as on
corresponding <xsl:param> and <xsl:with-param> elements, but if the type is
specified on <xsl:param>, it seems as if that might make it redundant also
to specify it on <xsl:with-param>, since using the wrong type at the level
of <xsl:with-param> will be caught by the type specification on <xsl:param>
anyway. Similarly, if I construct the return value of a function by using
<xsl:sequence> inside the body of the function, I can specify the typing on
<xsl:sequence>, but also on <xsl:function>, and it seems as if specifying
it in either of those places will catch the same errors as specifying in
both. (I am only beginning to learn to use schema-aware processing, and
therefore less certain about how specifying @type when constructing an
interim element or attribute interacts with specifying @as when using it.)

Is there consensus among XSLT developers about whether it might be better
to use @as everywhere it is allowed, or, alternatively, better to avoid
using it redundantly? What is the practice of other readers of this list?

Thanks,

David
djbpitt(_at_)gmail(_dot_)com
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
email <>)

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>