It’s just data

Ruby 1.8 vs LINQ

Jon Udell: I’ve been checking out the LINQ technical preview, and it’s definitely an eye-opener. The following snippet does a three-way join across an XML data source and two CLR objects. The XML data source is the content of this blog. The objects are a dictionary of date mappings, and an array of strings. The output is constructed as XML.

As an educational exercise, I’ve converted this to Ruby

doc = REXML::Document.new open("blog.xml")
d = {"2005/09"=>"September 2005", "2005/08"=>"August 2005"}
a = ["greasemonkey", "ajax"]
 
xml = Builder::XmlMarkup.new
 
REXML::XPath.match(doc,"//item").select {|item|
 
  d.keys.find {|key| item.elements["date"].text.include? key} and
  a.find {|tag| item.elements["tags"].text.include? tag}
 
}.sort_by {|item| item.elements["date"].text}.reverse.each {|item|
 
  xml.item {
    xml.month d[d.keys.find {|key| item.elements["date"].text.include? key}]
    xml.date item.elements["date"].text
    xml.title item.elements["title"].text
    xml.tags item.elements["tags"].text
  }
 
}
 
puts xml.to_s

Things to note:

All in all, a little competition in language design is a good thing.  Ruby would do well to study LINQ.  And, of course, Perl 6 (if it ever ships) would allow third parties to design such syntaxes for themselves.


Man your code is beautiful. Looking back at the LINQ code it’s quite obvious. In order to comprehend it, the “SQL” has to be separated into separate lines with indentation. Whereas the ruby code just flows like water...

Posted by Sharon Rosner at

typo: “Conversely, [in] the Ruby implementation”

The “yoda-like” syntax is supposedly there to allow autocomplete in Visual Studio. I wonder if it makes a little dropdown based on a schema.

Posted by Robert Sayre at

Sam Ruby: Ruby 1.8 vs LINQ

[link]...

Excerpt from del.icio.us/tag/ruby at

(X)Linq vs Ruby

The buzzwords of the moment: Linq for the .Net world, Ruby for the open source world. Jon Udel wrote the following example for the .Net world to show of the nice things about Linq: The following snippet does a three-way join across an XML data...

Excerpt from Mischa Kroon at

Nicely done sir.

I had to quickly hack a port to Groovy to join in the fun :)

Cheers,

Dion

Posted by Dion Almaer at

links for 2005-10-02

Mobile Phone As Home Computer (tags: ideas future phones usability) PyMP3Cut (tags: python mp3) SharkJumping: Podcasting Ad Insertion - Stop the Madness (tags: advertising podcasting vc startups) Sam Ruby: Ruby 1.8 vs LINQ (tags: ruby xml .net sql...

Excerpt from Coty's Weblog at

SPARQLScript?

Microsoft’s LINQ is pretty cool, it allows you to address diverse data sources with the same (programmatic) query syntax. But looking over Sam Ruby’s rendition of an example in Ruby (also cool) and his comments, both versions are very...

Excerpt from Raw at

Sam Ruby: Ruby 1.8 vs LINQ

Sam Ruby: Ruby 1.8 vs LINQ...

Excerpt from Random Notes & Bookmarks at

eBay SOAP Update: Syntax Matters

I saw a request for some actual SOAP code, so I will try and oblige. I don’t want to publish the entire code because there’s lots of messy stuff that’s specific to eBay’s SOAP API. I’ll talk about that some other time, but for now, those details...

Excerpt from Adam Trachtenberg at

native queries

for example. A solid relational foundation inside a programming language (whichever one is used) still seems to be a long way off. I sure wish I had more answers ready. ]]>...

Excerpt from Jean-Claude Wippler at

Programmer Intent or What you’re not getting about Ruby and why it’s the tits

... [more]

Trackback from Scott Hanselman's Computer Zen

at

Programmer Intent or What you're not getting about Ruby and why it's the tits

A user named yesthatmcgurk  left a comment on DotNetKicks where he/she said: I must be a complete loser, because I can’t see where Ruby is such hot shit. I’d love to read a story, “What you’re not getting about Ruby and why its the tits.” Such a...

Excerpt from Scott Hanselman's Computer Zen at

Programmer Intent or What you’re not getting about Ruby and why it’s the tits

... [more]

Trackback from Scott Hanselman's Computer Zen

at

Programmer Intent or What you’re not getting about Ruby and why it’s the tits

... [more]

Trackback from Scott Hanselman's Computer Zen

at

The yoda like syntax you mention is actually how SQL server or any database parses a normal textual query.  While it might be “backwards” in way of traditional select statements, to me it’s actually more intuitive.  It’s like an upside down pyramid.  For example, I want to get customers (from) that have the first name with “t” (where) let me get their first name’s and address (select).  I feel that traditional SQL is more “yoda-like.”

Posted by Tyler Garlick at

Querying mobile data objects with LINQ

I’m using US census data to look up the estimated populations of the cities and towns running elmcity hubs. The dataset is just plain old CSV (comma-separated variable), a format that’s more popular than ever thanks in part to a new...

Excerpt from Jon Udell at

Sam Ruby: Ruby 1.8 vs LINQ

[link]...

Excerpt from Delicious/tag/ruby at

Add your comment