Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ElCondemn
Aug 7, 2005


RonaldMcDonald posted:

In my opinion you can see a lot about languages from how they solve simple problems. So, for :science: how would the following PHP code look in RoR?

php:
<?
$result = mysql_query("select * from people order by lastname asc");
if (!$result)
    throw new Exception(mysql_error());

echo '<table>';
while ($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>', $row['lastname'], '</td>';
    echo '<td>', $row['firstname'], '</td>';
    echo '<td>', $row['age'], '</td>';
    echo '</tr>';
}
echo '</table>';
?>

If you want to compare RoR with PHP you would need a framework of some sort, my own combination with adodb and smarty would be...

php:
<?
$db = new Query();
$result = $db->exec( 'SELECT * FROM people ORDER BY lastname ASC' );
$tpl->assign( 'result', $result );
$tpl->display( 'person.tpl' );
?>
with html template like...

code:
<table>
<% foreach key=$i var=$result %>
    <tr>
        <td><% $i.lastname %></td>
        <td><% $i.firstname %></td>
        <td><% $i.age %></td>
    </tr>
<% /foreach %>
</table>
Not exact syntax but something like that, I understand RoR is "easy" because it has the whole framework, but PHP with a framework is just as easy.

On that note, RoR is neat but it's not the solution everyone claims it is. I just don't understand the whole buzz around RoR and why it's so great.

Adbot
ADBOT LOVES YOU

ElCondemn
Aug 7, 2005


floWenoL posted:

Because Ruby is just a better language than PHP, and Rails meshes really well with the language. Notice how your PHP framework still requires you to write SQL, assign the result, and name the template manually.

Actually I do have a query builder in my framework... that was just a basic example. I'd rather be in control of the queries though, I can imagine inexperienced Ruby developers are writing applications that will easily crumble under heavy load.

Not knowing how the framework builds these queries for you and helps you do everything is a sure fire way to write horrible code. From my understanding, a lot of the popular RoR apps override the built ins anyway. I didn't mean to make it a PHP vs. RoR argument, you say "Ruby is just a better language" without stating why. I just wanted to understand why so many people are on this bandwagon because I just can't seem to figure out why I should use this language. I've tried it out but anything that ruby does, perl does better, and the whole rails thing... PHP is more stable and not really a moving target like RoR.

edit: I can understand an argument about following proper code ethics, MVC and all of that...

ElCondemn
Aug 7, 2005


ryanmfw posted:

You keep comparing apples and oranges. Ruby is not an MVC framework, just like PHP. RoR, and PHP along with the several well developed frameworks like CakePHP, Symfony, and CodeIgniter make MVC development easy. Ruby itself does not make it easier, just like PHP itself does not.

This is exactly why I don't understand what the big deal about ruby is. Sure it has an "official" framework but other than that I don't see any benefits.

Like that other dude said in his argument against perl, the only thing perl excels at compared to ruby is in performance and aesthetics(not sure I agree with that but I'll take it), but what else is there?. I just can't figure out a niche or function that Ruby/RoR fills for me as a developer.

ElCondemn
Aug 7, 2005


take boat posted:

Ruby is a unix-oriented scripting language with a number of libraries built for it, and it combines a number of programming paradigms and clever language tricks and syntax in a way that many find elegant and usable. Perl, by contrast, is a unix-oriented scripting language with a number of libraries built for it, with a syntax that is nothing short of god awful. Much like Perl and PHP and Python, Ruby has no special domain where only it can ever be used.

Alright, that's all I wanted to know, it's just a preference in synax. I guess my issue is just that I'm used to perl, php and other languages that are similar. It's kind of difficult for me to pick up/use ruby because it's quite different and the approach is different than what I'm used to.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply