RSS
3 Feb 2010

Why You Should Be Grateful for Coding in Ruby

Author: ceefour | Filed under: Opinions

adaruby01 529710929 7b3d85e103 272x300 Why You Should Be Grateful for Coding in Ruby

How do you feel during your daily Ruby programming workflow? Do you feel fun or productive? Either way, you’ve got to feel grateful!

After several years not doing any serious PHP programming, today I get curious.

Right now, PHP has evolved. PHP programmers are not “script kiddies” anymore, they’re professional programmers with quality MVC web frameworks.

Now it won’t be fair if I compared Ruby on Rails with PHP, as that’d be like comparing apples and oranges. So I have to pick some killer app written in PHP that competes directly with Rails, as long as it’s not WordPress or Drupal. icon razz Why You Should Be Grateful for Coding in Ruby

So I checked out Symfony, the most popular PHP web framework out there. I’ve never programmed Symfony, but I’ve heard a lot of good things about it.

After initial reading on the documentation, it seems the good things I’ve heard about it are true. The development model is very similar to Ruby on Rails. Scaffolds and plenty of helpers.

However, the syntax is unbearable. (at least for me!) Check out this tutorial example code:

// apps/frontend/modules/job/templates/showSuccess.php
<?php slot('title') ?>
 <?php echo sprintf('%s is looking for a %s', $job->getCompany(), $job->getPosition()) ?>
<?php end_slot(); ?>

slot() and end_slot() aren’t even a proper block construct. They’re just two separate functions made to look like they’re blocks.

Compare with how to do the same in Ruby on Rails:

# app/views/jobs/show_success.html.erb
<% content_for :title do %>
  <%= @job.company %> is looking for a <%= @job.position %>
<!-- or: <%= "#{@job.company} is looking for a #{@job.position}" %> -->
<% end %>

It might be a simple example, but that begs your gratefulness even more: Imagine coding a much more complex web application!

I certainly won’t blame it on Symfony. Its developers have done a great job releasing an excellent web framework using PHP language as its foundation.

However, the PHP programming language (at least in its current incarnation v5.x) while makes great things possible unfortunately make them greatly ugly at the same time. To be fair, it’s not hard to abuse Ruby if you want to get cryptic. But at least, Ruby programming language when used properly will yield beautiful and highly readable code like the above example.

What’s your take? Time to get opinionated, guys! icon smile Why You Should Be Grateful for Coding in Ruby

Image credits

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: framework, php, Rails, Ruby, symfony, syntax