|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: RE: Namespaces Best Practice
David Brownell wrote: > > > > > > In every style guide I've ever seen, the guidance for lexical scoping > > > mechanisms is to use them to localize information to its most natural > > > scope. Loop-private variables are invisible outside the loop, etc. > > > > For the record, this best practice is lifted from "Common XML" itself a best > > practices guideline: > > http://www.simonstl.com/articles/cxmlspec.txt > > That writeup adopts a per-file definition of "most natural scope", > which is more extreme than any definition I'd adopt, though > it fits into the "wriggle room" which I mentioned. > > That's a bit less extreme than what you wrote, though > that still wouldn't make me adopt it! :) I really wasn't intending to be extreme, nor to indicate that this "best practice" is intended in any way to be some sort of law that must be followed, rather it is intended simply as a "best practice" to be used as a guideline. I don't myself follow these guidelines in all cases, but do try to adhere unless there is a good reason not to. These practices are in no way intended to supercede the XML Namespace recommendation itself, rather to provide guidance on usage of this rec in ways that tend to avoid problems. > > > > I fail to see how a "loop private variable" relates to a namespace defined > > by a URI. This is like comparing apples not with oranges but with entire > > countries which themselves have farms which themselves contain orange > > groves. > > That's like ... hyperbole! The relationship is: "loop private variable" denotes a transient value that most optimizing compilers optimize out of existence. In contrast a namespace name is a URI. A URI defines a point in web space, one that itself may be associated with all sorts of individual resources. So the analogy is between a single thing and a potentially complex container of things. In terms of such declarations, an XML document provides for a DTD at the top of the document, not fragments of DTD intermixed with XML. The so-called > > The relationship is: both bind values to names. > Both use "lexical scoping" to determine values at use point. > I see where you are coming from. During parse phase a variable is not typically bound to a value. Of course locally scoped variables may often be replaced with constants during an optimization phase but only in certain circumstances. Frequently the values of a program variable are only determined when the program is actually run. On the other hand, I am strongly suggesting that the URI bound to a prefix ought not change. In any case this value is always available at parse time. Perhaps this may make this more clear: XML Documents should be designed to allow a human to easily determine the namespace URI associated with an element prefix. It seems to me that placing the prefix-URI bindings at the top would ease this task, but if you would rather perform this somewhere else in a document, then I see no problem. What ever is more clear for a person to read. (this -ought- not make any difference to a well designed XML parser so this guideline exists entirely to allow people, so inclined, to better read XML documents) In contrast the value of a variable typically changes as a program is run, so there is no way to ensure that a human will be able to know the value of any variable simply by looking at a program -- of course you may have more intrinsic Mhz than me, but my own brain it still stuck at less than HP programmable calculator speeds. Furthermore, programs may have large numbers of variables and so it is often of true benefit to declare them close to use. Most XML documents ought not have so many namespaces and indeed if we start getting into single documents with hundreds of namespaces, we ought either consider using fewer namespaces, or changing the best practice at that time. > > Information scoping (one variant is "information hiding") is a classic > best-practice in systems development. Lexical scoping isn't only to > support rebinding of names to values; it's also to minimize the amount > of global state (vs maximizing it, per the CXML policy or the one > which you proposed). Sure. However my intention is to point out that best practice for systems design is not necessarily best practice for document design. Similarly minimizing global state is not always the most efficient nor desirable way to do things. For example in XML parsing assuming that prefix-URI bindings always occur at the root, this will minimize the number of namespace binding and unbinding events. Jonathan
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








