[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: xml in Ruby or no xml it's just a question

Austin Ziegler

10/2/2003 6:10:00 PM

On Fri, 3 Oct 2003 01:46:38 +0900, paul vudmaska wrote:
"Chad Fowler" <chad@chadfowler.com>
>> I can't see how hard-wiring XML as a part of Ruby's syntax
>> provides much of a benefit at all. It would be fashionable
>> (though not really all that fashionable these days), but barring
>> that it's just more baggage to carry around.
> It's interesting to me that you would wrap an xml file(rss) in an
> object http://www.chadfowler.com... but belittle an
> offhanded attempt to make inherent those attributes that you so
> painstakingly crafted code for and call the former more baggage.
> Help me understand that, Chad!

I'm not Chad, but as someone who liked what Chad did and wrote a
follow-up library that (mostly) conformed to his API, I can explain
exactly why I did it much the same way. Basically, Chad is
representing an object (a rich site summary, or a channel). That it
happens to correspond to an XML format is somewhat irrelevant. There
are actually four common variants on this, and two less common
variants. By designing channels as objects, it becomes relatively
easy to support those variant formats.

>> more readable?
>> <list><item>blah</item><item>blah2</item><item>lkjsdf</item></list>
>> vs.
>> ["blah", "blah2", "lkjsdf"]
> More readable as in 'more context' not as in more succinct or
> fewer letters or anything else. (ie are those an array of items in
> a list or just a lot of blah?)

There is no meaningful distinction between an array and a list in
Ruby. In all likelihood, you might do:

class List
def initialize(*items)
@items = *items
end
attr_reader :items
end

list = List.new(%w{blah blah2 ljksdf})
list.items # => ["blah", "blah2", "lkjsdf"]

When you're writing a program, why would you want to add unnecessary
semantic information (e.g., encode the list as XML) when the
necessary semantic information is already present. The only time you
need to worry about such semantic information is when you write it
to an external format ... like XML.

>> With REXML in the distribution you can already do this. Just
>> requires a few more keystrokes.
> Sure but fewer works for me better.

Yeah, but you've traded fewer keystrokes here in favour of more
keystrokes elsewhere.

You may want to look around the archives for a discussion of %y{}
(for YAML) and the like that happened around the 10th of September.
Basically, some of the same suggestions you've made came up -- and
weren't really liked.

-austin
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.10.02
* 13.58.40



1 Answer

James Britt

10/2/2003 9:20:00 PM

0

Austin Ziegler wrote:

>
> I'm not Chad, but as someone who liked what Chad did and wrote a
> follow-up library that (mostly) conformed to his API, I can explain
> exactly why I did it much the same way. Basically, Chad is
> representing an object (a rich site summary, or a channel). That it
> happens to correspond to an XML format is somewhat irrelevant. There
> are actually four common variants on this, and two less common
> variants. By designing channels as objects, it becomes relatively
> easy to support those variant formats.

And this extends perhaps more so to such things as RDF and (XML) Topic
Maps. They both make extensive use of XML, but as a serialization
format. The markup is not the model, just a handy way of expressing it.

Once I've slurped in some XML I'm more interested in what role it's
meant to play in a given context than in the specifics of angle brackets
and nested text. Creating objects around the syntax allows the
developer to focus more on the information set than on the serialization.

Now, I can see the value in having an XML-centric syntax available when
the XML-ness of something is the primary concern. This would be a great
benefit to XML folks who (for whatever reasons) choose Ruby for their
XML manipulation. They might rather focus on an XML view of the world,
rather than adopt Ruby idioms, for DOM or text manipulation.

Some of these ideas have been disccussed on the RubyGarden wiki:
http://www.rubygarden.org/ruby...

I also proffered the idea of E4X-like syntax in Ruby, on the REXML
mailing list (ser-rexml-help@germane-software.com). There was a bit of
discussion, though overall it was not well recieved :).

By and large, it seems relatively easy to add such behavior when and
where you need it through the use of modules. I'm unconvinced there is
such a compelling need for this syntax in the core language.

(But such discussions may find there way into my presentation on the
state of XML processing in Ruby at RubyConf 2003. Be there or be square.)

James Britt
jbritt AT rubyxml DOT com