Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
When DBIx::Class can do what Re^2: OT: Ruby On Rails - your thoughts? describes, then I'll be impressed. Why isn't DBIx::Class required by Catalyst vs. Class::DBI? Why isn't DBIx::Class being trumpeted to the rooftops? Why is CDBI still forced onto poor unsuspecting users?!? The world wants to know!

A huge win that ActiveRecord and Rails have is the fact that they use Ruby. For example, here's some code I wrote in Ruby that directly uses DBI.

require 'dbi' insert_sql = "some SQL statement" DBI.connect( 'dbi:Mysql:database=some_db;host=some_host', 'user', 'pas +sword' ) { |dbh| dbh.prepare( insert_sql ) { |sth| File.open( File.join( File.dirname(__FILE__), 'some_file.txt' ) ) { |file| # Strip off the first two lines (1..2).each { file.gets } file.each { |line| fields = line.strip.split( ',' ) fields.each { |field| field.gsub!(/"/, '') field.strip! } # Adjust for stoopidity fields[5] = (2 - fields[5].to_i) + 1 ary = [ fields.values_at(1..4, 4..5), 0, 0 ].flatten sth.execute( *ary ) } } } }

This is the equivalent code in Perl.

use DBI; use FindBin; use File::Spec; use IO::File; my $insert_sql = "some SQL statement"; my $dbh = DBI->connect( 'dbi:Mysql:database=some_db;host=some_host', 'user', 'password', { PrintError => 0, RaiseError => 1, }) or die "Cannot connect\n"; my $sth = $dbh->prepare( $insert_sql ); my $fh = IO::File->new( File::Spec->catfile( $FindBin::Bin, 'some_file +.txt' ) ) or die "Cannot open file"; scalar(<$fh>) for 1 .. 2; while ( my $line = <$fh> ) { chomp $line; my @fields = map { s/"//g; s/^\s+//; s/\s$//; $_ } split ',', $line; $fields[5] = (2 - $fields[5]) + 1; $sth->execute( @fields[1..4], @fields[4..5], 0, 0 ); } $sth->finish; $dbh->disconnect;

Which one is easier to read? Which one is easier to modify? Which one is easier to verify in terms of variables staying in scope? And, this is an example that is not only written by someone who's an expert in Perl vs. a novice in Ruby, but it's an example that's catering to Perl's strengths! And, Ruby still is a win in my eyes. Just imagine this kind of code within a much larger application. By using the first-class blocks that Ruby provides, that's a huge amount of scoping ... for free!

The only true win Perl has in those snippets is the array slicing at the bottom. I'm pretty sure that's because I suck at Ruby and not because Ruby sucks vis-a-vis Perl.

Rails may suck relative to Catalyst, but it couldn't be written in Perl (or Java or any other language). I hate to say it, sri, but Catalyst could be written in Ruby.

For the record, Catalyst is my preference for new webapp development in Perl and I think it's an excellent step forward. Rails is my first choice for new webapp development in any language.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

In reply to Re^3: OT: Ruby On Rails - your thoughts? by dragonchild
in thread OT: Ruby On Rails - your thoughts? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (7)
    As of 2020-12-02 14:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (41 votes). Check out past polls.

      Notices?