2008/7/15 Charlie Savage <[EMAIL PROTECTED]>: > > >> On Tue, Jul 15, 2008 at 12:30 PM, Sean Chittenden <[EMAIL PROTECTED]> >> wrote: >>>>> >>>>> But since you went ahead with swapping XML => LibXML, that probably >>>>> best anyway. I wonder about one thing though, is backward >>>>> compatibility best preserved with: >>>>> XML = LibXML >>>>> or as you have it: >>>>> module XML >>>>> include LibXML >>>>> end >>> >>> Use an environment variable at require time and the module assigns. >>> >>> # XX untested >>> if ['0','false','no','off',false,nil,'hell god damn "no!" me >>> harder'].include? (ENV['RUBY_LIBXML_SHORT_PATH'].nil? ? true : >>> ENV['RUBY_LIBXML_SHORT_PATH'].downcase]) >>> # Only LibXML class >>> else >>> XML = LibXML >>> end >>> >>> Then users can set the env variable and goto town however they want. >>> >>>> FYI, I moved to XSLT to LibXSLT to be consistent. Although when I >>>> started >>>> using it, I found it to be a bit ugly. Take a look: >>>> >>>> # Create a new XSL Transform >>>> stylesheet_doc = LibXML::Document.file('files/fuzface.xsl') >>>> stylesheet = LibXSLT::Stylesheet.new(stylesheet_doc) >>>> >>>> # Transform a xml document >>>> xml_doc = LibXML::Document.file('files/fuzface.xml') >>>> result = stylesheet.apply(xml_doc) >>>> >>>> >>>> Notice how hard it becomes to distinguish the namespaces (LibXML and >>>> LibXSLT). Compare: >>>> >>>> # Create a new XSL Transform >>>> stylesheet_doc = XML::Document.file('files/fuzface.xsl') >>>> stylesheet = XSLT::Stylesheet.new(stylesheet_doc) >>>> >>>> Thoughts? >>> >>> Use of XML was actually a conscious choice on my part. Ditch the >>> puritanical or egalitarian thoughts. Odds of two XML parsing libraries >>> loaded into the same instance is rare. I imagined there would be little >>> to >>> no contention for the XML namespace because everyone would've treated it >>> as >>> holy. Bah! A "User" identifier is holy, but XML is not (one is >>> application, the other is library). I think the above 'LibXML'-ification >>> of >>> the namespace is appropriate, however, but focus on making the library >>> easy >>> to use, hence XML vs LibXML. >>> >>> Don't step on other people's dicks intentionally, but it's okay for the >>> library to be assertive and to match its ambitions. Tip-toeing around >>> 'what >>> if' is an endless rabbit hole. We'll adapt and find a solution if there >>> is >>> a problem at some point in the future. Cool? >> >> Actually I agree. XML:: and XSLT:: are a lot better. Trying to find >> the right balance between ease-of-use and interoperability can be >> difficult. > > Ok, everyone agrees here. > >> I think we should reconsider wrapping what we have in a LibXML >> namespace. This provides for both possibilities. Usage would entail: >> >> require 'libxml' >> >> module MyApp >> include LibXML >> >> # Create a new XSL Transform >> stylesheet_doc = XML::Document.file('files/fuzface.xsl') >> stylesheet = XSLT::Stylesheet.new(stylesheet_doc) >> ... >> end >> >> See that's nice to use and proper! :-) >> >> I think we tend to think in terms of the toplevel, but in most >> applications this isn't the case. > > Its a clever idea. But I'm not convinced because I really don't like the > extra include. Why exactly would I want to mixin libxml into my own classes > or modules - just to make coding a bit easier doesn't seem enough > justification?
It strikes me as a bit funny that "good practice" seems cleaver :-) I know it may seems inconvenient, but it is worth it. Moreover, there is a simple solution to achieving the effect you want (though I would discourage it in any code you intend to be reusable by others). Just use: require 'libxml/xml' Were libxml/xml.rb is simply require 'libxml' include LibXML > I'd just as soon do this: > > XML = LibXML > > And be done with it. I agree you could do this though: > > XML = LibXML::XML > > Um, are you really tied to this idea? Going through and changing everything > again sounds really uninteresting. Please? T. _______________________________________________ libxml-devel mailing list libxml-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel