From: msergeant@... (Matt Sergeant) Date: 2002-02-07T20:43:38+09:00 Subject: XML::SAX2 critique This isn't exactly a critique of XML::SAX2 per-se, but more of the tack taken in that project... XML::SAX2 seems to be an almost verbatim copy of the Java SAX2 APIs. I strongly believe that they have made a very poor choice in their API by passing the node information to the callbacks as a list of parameters. Here's an example in Ruby: handler.start_element(uri, localname, qname, attrs) Now while the element data is passed as individual parameters, the attrs are passed as an object (of the Attributes class). This is a nasty design "smell". It also broke things for Java when they went from SAX1 to SAX2, because the APIs were different, so they had to change the name of the handler classes to avoid confusion and breakage. Now you may say "but XML is at 1.0 and isn't likely to change", but that's a falsehood, because XML Schemas extend the infoset with type information, which you cannot represent using the above SAX notation. Now picture a cleaner API: handler.start_element(el) Where element is a lightweight class Element [1], which encapsulates the above information and the attributes. Simple to construct, but most importantly: extensible. This is how the Perl SAX APIs have been designed, right from the start, and it meant that Perl SAX1 was mostly compatible with Perl SAX2 [2]. I really urge people to consider the implications of something like this - it's a major design decision - if you carve in stone the Ruby SAX2 API now, and copy the Java design, you may regret it. I hope you don't see me as being purely critical. I think Maki has done an amazing job in putting together all this code. I just don't want you to lose out on a better option. Matt. [1] Could be as simple as: class Element attr_reader :uri, :qname, :localname, :attrs attr_writer :uri, :qname, :localname, :attrs def initialize(uri, qname, localname, attrs) @uri = uri @qname = qname @localname = localname @attrs = attrs end end [2] http://sax.perl.org/