Me
About
Gallery
Company
Girl


Projects
Ruby on Rails
Basecamp
Highrise
Backpack
Campfire
Ta-da List
Writeboard


More
Feed
Archives

March 26, 1:48

Russell Beattie secretly lusts for Ruby on Rails

As a Ruby developer, the tune of all these trumpets heralding the coming of SimpleXML in PHP5 sounds a bit out of key. Gutmans and Suraki from Zend gets really carried away in the introduction to PHP 5:

PHP 5 also introduces new revolutionary ways of dealing with XML that make it the ideal platform for XML processing—no other solution comes even close!

I can forgive their overreaching enthusiasm, though, they're just really proud of their creation. It's somewhat harder to forgive "Java heads" like Russell Beattie getting all giddy about PHP 5 because of the introduction of SimpleXML and XPath.

Beattie brings about this example to show the "simplicity" of that combination:

$sxe = simplexml_load_file("articles.xml");
 
foreach($sxe->xpath('/articles/item/title') as $item) {
    print $item . "\n";       
}

I'm sorry, but that can't really impress me when the standard library for XML in Ruby has been able to do exactly the same in less and more readable code since the beginning of 2002:

doc = REXML::Document.new(File.new("articles.xml"))
 
doc.elements.each('articles/item/title') { |title| 
  puts title.text
}

"Oh", I hear you cry, "but I don't need to call any methods on my item in PHP!". If that's the key to your fancy, then consider this:

class REXML::Element
  def to_s() text end  
end

Yes, that would indeed be a run-time extension of the standard library. Just one of the reasons languages like Ruby and Smalltalk are such a joy to work with. You're not bound by neither limitations nor design choices made by the original developers. With that extension in place, you can discard the call to text and just write puts text.

Beattie continues his tale of envy for the scripting world with a keen observation on logic and views. If I didn't know better, I'd think had a peak at Rails and was building its case for world domination:

I'm not interested in artificially limiting the power of the script on the pages. There's always tricky logic to be had on the view side of things. Always. No matter what you do, no matter what project I've worked on, there's always a requirement in the view layer that ends up needing a lot of logic

This is exactly why Rails doesn't attempt to build Yet Another Templating Language, but relies on Ruby itself (through ERb) to power the templates. Ruby is incredibly well-suited for templating purposes with constructs like:

<select>
<%= [ "Denmark", "Spain", "USA" ].collect { |country|
    "<option>#{country}</option>" }.join %>
</select>

Of course you don't want to litter your views with a ton of hard-coded constructs for something as common as this, so how about using that wonderful run-time extension feature again:

class Array
  def html_options
    collect { |element| 
      "<option>#{element}</option>" 
    }.join
  end
end

That's right. I'm extending the core library in Ruby. The C constructs Matz spent all those years perfecting. This leads to a more tolerable and reusable code, like (the %w-style is Ruby shorthand for the same array we used before):

<select>
<%= %w(Denmark Spain USA).html_options %>
</select>

Beattie goes even further by almost suggesting the un-suggestible: Why use Java at all?

What I'd like to see is a PHP-like solution, but with Groovy as the language being used not Java. And I want to put the controller logic in Groovy as well - since, hey, it ends up as bytecode, why not? Rapid App Development plus MVC goodness. I'm down with that... (my emphasis)

This is exactly what Rails is all about. The flexibility of PHP with the beauty and elegance of a well-factored MVC solution. Thanks for making that point so clearly, Beattie.


Challenge by Russ on March 26, 4:02


Interesting article! I'll have to take a minute and do a tutorial on Ruby. But honestly, the thing I'm really lusting for is that you spell my name correctly.

;-)

-Russell

Challenge by David Heinemeier Hansson on March 26, 9:05

Doh! That was imbarresing. Correction made :)

Challenge by Carlos Perez on March 26, 13:25

Got a time line on when you're going to release Rails to the public?

Challenge by David Heinemeier Hansson on March 26, 13:50

I'm planning on doing a two-staged release. First, I'll release the heart of Rails, which is the ORM-solution based on the Active Record pattern called just that: Active Record. This package is already fairly well documented, has samples, and a small group of developers working on testing and extending it. I see this happening within the month for sure.

Then there's the Action Controller and Template View projects, which probably won't be released until Rails (the glue for all these pieces) is somewhat stable. I think that could also happen in about 3-6 weeks from now.

These wouldn't be untested proof-of-concept type releases, but the very foundation that Basecamp is based on. So they've already proven their worth in production.

Challenge by Tomas on March 26, 16:17

You know, we're _already_ sold on Rails. Now we want to see it! ;-)

Challenge by David Heinemeier Hansson on March 26, 16:29

It's not quite there. It seems that now that I've build up a certain amount of anticipation, I need to deliver something at the same level as well :). So rather than delivering something with spotty documentation and few samples, I'd rather wait until there's a really impressive package (yes, yes, I know — release early, realease often).

In the meanwhile, I'll keep posting examples and commentary on Rails here. I even got a plan to do some video and show the building of a sample app.

Challenge by Tomas on March 26, 16:37

Sounds very nice to me, I'm looking forward to some comprehensive stuff on Rails.

Challenge by gabriele on March 26, 20:22

yes, video!
Oh btw, if in the proces you could even use WebPublisher (ruby/ERB plugin for eclipse) that may be even more impressive :)

Challenge by Florian Weber on March 27, 0:53

I really think its bad design to implement a html_options method for the array class. why does every array need to know about html? You should rather pass the array to a class or method which knows about html and does the option convertion for you..

Challenge by David Heinemeier Hansson on March 27, 1:02

Actually, html_options is currently just a method on a template helper in Rails. Not implemented on array itself. But I have been thinking about moving back to the on-array solution if it can be done within the scope of arrays in the template.

It's much more readable to have something like post.title.textilize.truncate(25) than truncate(textilize(post.title), 25) and as long as it can be kept within the confinement of the templates, I think it makes plenty of sense. Call it Segregated Usage Specialization Extension Reactions and it's a SUPER pattern :)

Challenge by Florian on March 27, 11:04

hehe..

i just thought about this a bit more. maybe its not that bad. i really have to get used to how dynamic ruby is. i think i would just add the methods when the the template process begins and remove them afterwards..

Challenge by Humphrey on May 25, 22:16

Hello world!

Challenge by robze on April 11, 1:51

oupsi. phpxpath (a native phplib http://sourceforge.net/projects/phpxpath/) was there long before rexml was usable. anyway simple apis are not easy to find...

Challenge by angel on June 04, 12:01

Hello. I am new here. It is very interesting.
mature bitches mature gallerys mature gallerys mature bitches mature spunker mature living mature video mature living classic mature south indian mature women mature video mature amature older s3xy women mature nud3 pics classic mature mature living mature living mature women stories nud3 senior women mature gallerys mature amature nud3 senior women mature ladies in lingerie mature living nud3 senior women mature living mature amature mature living mature nudists photos mature spunker older s3xy women mature nudists photos south indian mature women south indian mature women mature women stories south indian mature women free thumbnail pictures of older women mature spunker lyrics to older country songs south indian mature women

Challenge by bob on June 04, 19:46

Hello. I am new here. It is very interesting.
creampie video store creampies free creampies movies creampies free ass creampie mature creampies creampie video clips ass creampie free anal creampie movies xyx creampies creampies free creampies free creampie t9p free creampie video creampie pussies mature creampies wife oral creampies free creampie pics free xyx creampies free creampie thumbnails creampie ass creampies movies creampie t9p creampie ass free creampie pics free creampies free hairy creampie wife oral creampies mature creampies xyx creampies creampies movies wife oral creampies free creampie thumbnails creampie video store creampies free wife oral creampies free creampie video creampie video clips teen anal creampies cum creampie

Challenge by ivan on June 05, 5:29

Hello. I am new here. It is very interesting.
free panty thumbnail gallery pantyhose chat free panty thumbnail gallery pictures of crossed nylon legs men pantyhose girls in fishnet stockings nylon galleries russian pantyhose women cum on panties girls in fishnet stockings pantyhose and nylon feet and toes free panty thumbnail gallery pantyhose crossed legs men who wear pantyhose cum on panties pantyhose crossed legs nylon galleries pictures of crossed nylon legs girls in body stockings russian pantyhose women men who wear pantyhose pantyhose chat pictures of crossed nylon legs free pantyhose thumbs pantyhose chat men who wear pantyhose girls in body stockings pictures of crossed nylon legs mature pantyhose pictures russian pantyhose women pictures of crossed nylon legs free pantyhose thumbs pantyhose chat men pantyhose men who wear pantyhose free panty thumbnail gallery russian pantyhose women girls in fishnet stockings pantyhose and nylon feet and toes free panty thumbnail gallery

Challenge by nelly on June 05, 9:30

Hello. I am new here. It is very interesting.
latina creampie creampie movie creampie pic pictures creampie creampies free pictures creampie creampie pic creampie anal latina creampie pictures creampie creampies xyx creampie pussies free creampie pics and stories creampies xyx gangbang creampies videos creampie movie free creampie pics and stories creampie internal, cumshots free creampie s3x free creampie pics and stories creampie anal creampie anal amature creampies creampie anal free creampie pics and stories creampie movie interracial wives bareback creampies interracial wives bareback creampies latina creampie free creampie s3x free anal creampie pics creampie internal, cumshots interracial wives bareback creampies free creampie pics free creampie pussies creampie pussies creampies xyx free creampie pics free creampies xyx latina creampie

Challenge by jon on June 05, 17:22

Hi. This is my links.
dating mature women free mature mature amateur mature 1esbians free mature s3x older thumbs mature wives mature nud3 women mature 1esbians mature men galleries free mature p0Rn mature 1esbians mature women in stockings free older women free older women old naked women free mature old naked women mature over 50 mature 1esbians mature women t9p mature women in stockings free mature p0Rn mature over 50 mature women nud3 free older women mature women in stockings mature women in stockings older thumbs dating mature women mature women t9p older women younger men free older women mature men galleries mature 1esbians free mature p0Rn mature nud3 women old naked women older men younger women free older women

Challenge by juju on June 06, 19:24

Hi. This is my links.
stories of 1ncest stories of 1ncest 1ncest t9p family s3x stories mom son galleries mom son galleries 1ncest t9p mom son galleries real 1ncest real 1ncest 1ncest chat free 1ncest storys 1ncest free gallery s3x 1ncest mom son russian 1ncest free 1ncest storys mom son brother sister s3x 1ncestgrrl's free 1ncest stories father son 1ncest father son 1ncest free 1ncest storys 1ncest t9p free er0t1c 1ncest stories family s3x stories brother sister s3x free 1ncest photos mom son galleries russian 1ncest 1ncest free gallery free 1ncest photos mom son 1ncestgrrl's free 1ncest stories family s3x stories brother sister s3x teens 1ncest pics 1ncest t9p s3x 1ncest real 1ncest

Challenge by jon on June 08, 0:26

Hi. This is my links.
mature women in pantyhose wet pantyhose panty fetish free wet panty hooters girls in pantyhose wet pantyhose panty fetish free teen panties mature ladies in pantyhose white pantyhose cheerleader panty pics free wet panty office girls in nylons men caught wearing pantyhose mature pantyhose pics winnie-cooper pantyhose girls in nylons winnie-cooper pantyhose girls in nylons panty thumbnails celebrities in pantyhose panty thumbnails free teen panties men caught wearing pantyhose men caught wearing pantyhose free teen panties winnie-cooper pantyhose office girls in nylons mature women in pantyhose panty fetish winnie-cooper pantyhose men's pantyhose hooters girls in pantyhose hooters girls in pantyhose pantyhose images free wet panty men caught wearing pantyhose free wet panty office girls in nylons wet pantyhose

Challenge by nickol on June 08, 4:08

Sorry for my links
teens in pantyhose free pantyhose sites pantyhose pic gallery wolford pantyhose silkies pantyhose free panty galleries teen panty pictures teen panty pictures men in panty pics free panty galleries silkies pantyhose pantyhose men bra and panty pics panty line pics crotchless pantyhose shiny pantyhose panty line pics panty girls crotchless pantyhose free panties free pantyhose pics free panties panty line pics panty girls crotchless pantyhose free pantyhose sites men in panty pics pantyhose pic gallery pantyhose pic gallery panty girls pantyhose pic gallery teen panty pictures panty girls teen panty pictures panty girls teens in pantyhose panty girls mature women in nylons silkies pantyhose pantyhose fetish

Challenge by mary on June 08, 19:11

Hello. I am new here. It is very interesting.
nud3 mature men older women pictures mature 1esbian s3xy mature women nud3 mature men s3xy mature women bcn mature victor mature bcn mature nud3 mature black women bcn mature top mature t9p's top mature t9p's victor mature free pics mature ladies mature cart00ns nud3 mature older pussy daily mature boobs free mature s3x pics free mature movies mature s3x pics mature 1esbian free mature movies nud3 mature black women nud3 mature black women bcn mature nud3 mature free pics mature ladies mature older t9p free mature s3x pics nud3 mature black women free mature s3x pics nud3 mature men nud3 mature older pussy s3xy mature women free pics mature ladies daily mature boobs victor mature

Challenge by poker rules on June 20, 23:19

Take your time to visit some helpful info on poker rules poker rules http://poker-rules.zindagi.us/ ... Thanks!!!

Challenge by free poker on June 21, 7:05

You may find it interesting to visit the pages on free poker free poker http://www.poker-adventure.com/free-poker.html .

Challenge by internet casino on June 22, 6:03

Take your time to visit some relevant information about internet casino internet casino http://www.scottishtutors.com/internet-casino.html .

Challenge by pharmacy on June 24, 5:01

You are invited to visit some relevant pages about online pharmacy online pharmacy http://www.thebest-pills/online-pharmacy.html pharmacy pharmacy http://www.thebest-pills/pharmacy.html weight loss pills weight loss pills http://www.thebest-pills/weight-loss-pills.html ...