[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

($possibly-empty, $default)[1] idiom optimisation

Subject: ($possibly-empty, $default)[1] idiom optimisation
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 24 Mar 2010 10:21:22 +0000
 ($possibly-empty
Hi,

This is often used as a nice way to avoid an if-then-else check to
display $default if $possibly-empty is empty:

($possibly-empty, $default)[1]

Out of interest, is it likely to be optimised to avoid evaluating
$default if the first item is not empty, because if $default takes a
reasonable amount of work to evaluate it's effectively wasted most of
the time (if $default is rare).  If it takes more work to evaluate
$default than to test whether $possibly-empty is empty each time, then
this is just a short cut rather than good practice.

It reminds me of advice I heard (for Java) to wrap all log statements
in an if test to check the log level first to avoid the unnecessary
creation of the log message.  For example, constructing a large
message for a debug log by combining several different things, only
for the constructed string to be discarded because the log level is
info. (testing the log level a 1000 times is far better than creating
and discarding 1000 strings)


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.