xsl-list
[Top] [All Lists]

Re: [xsl] Attribute order recommendations

2020-08-25 03:24:05
Michael Müller-Hillebrand mmh(_at_)docufy(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> writes:
Folks,
[…]
Have I missed some insightful source/post, or can we discuss the
benefits of attribute order conventions?

Readability is an important aspect of coding, but I’ve never really
considered having a rigid set of conventions for attribute order.

For things that have names, I always put the name first. I’d find it
disconcerting, I think, if I had to look past a few attributes to find
the name.

For things that have types (and yes, you should put the types on things
that have types!), I probably put the as="…" attribute last, unless the
select expression is very long.

This:

  <xsl:variable name="my-name" select="f:f($x)" as="xs:integer"/>

Or this:

  <xsl:variable name="my-other-name" as="xs:integer"
                select="if ($some-condition)
                        then f:f($x)
                        else f:g($x)"/>

(Maybe the rule I’m following is “put the ‘as’ attribute on the end of
the line that has the ‘name’ attribute”.)

I’d probably put other attributes between name and as, but I don’t feel
like the order is critically important. I probably go with an aesthetic
feel for what’s most readable in the more complicated cases.

Just trying it out, I can imagine writing:

  <xsl:param name="my-name" select="0" required="yes" tunnel="yes" 
as="xs:integer"/>

But that line is getting awfully long. Maybe this:

  <xsl:param name="my-other-name" as="xs:integer"
             required="yes" tunnel="yes"
             select="if ($some-condition)
                     then f:f($x)
                     else f:g($x)"/>

But I might at that point start to wonder if “tunnel” was getting a
little lost, so maybe:

<xsl:param name="my-other-name" as="xs:integer"
           required="yes"
           tunnel="yes"
           select="if ($some-condition)
                   then f:f($x)
                   else f:g($x)"/>

I guess I do have a strong (subconscious) preference for putting the
name and the type on the same line!

                                        Be seeing you,
                                          norm

--
Norman Tovey-Walsh <ndw(_at_)nwalsh(_dot_)com>
https://nwalsh.com/

At a certain point, ignorance becomes villainy.
--~----------------------------------------------------------------
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
--~--

Attachment: signature.asc
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>