RSS
3 Feb 2010

Why You Should Be Grateful for Coding in Ruby

Author: ceefour | Filed under: Opinions

Being grateful

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. :-P

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! :-)

Image credits

No related posts.

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

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

  • Matti Kotsalainen
    While I prefer programming in Ruby and I think Rails & Sinatra are great frameworks that I'll use when I want to build with full control, there are some great PHP CMS engines (Drupal, Expression Engine) that I don't want to be without. If I need to get something simple out the door quick, its great to be able to leverage the fantastic stuff already built on top PHP. On some projects I've used both PHP and Ruby. Ruby for the backend services and general maintenance tasks, PHP for the CMS engine.
  • ndogbosok
    Ofcourse doing complex/enterprise thing, programmers want to use and make code simple as do boiling water. Nice share..
  • In HAML:

    - content_for :title do
    = "#{@job.company} is looking for a #{@job.position}"
  • Eric
    True.

    You could even show the haml equivalent to put one more nail on the coffin!
  • Matt Jones
    You think *that's* obtuse? Try taking a look at the associations code in CakePHP; it's clearly inspired by Rails associations but with a bucket of dreck added thanks to PHP's lack of some of the introspection bits that make has_many and friends "magic".

    Docs at: http://book.cakephp.org/view/78/Associations-Li...
  • Thanks Matt for the up :-) Great catch! Man that's scarryy...

    I loved PHP back then. I hope PHP 6 will fix this in some way. I like having
    choices that are all delicious. :-)

    It's amazing how the underrated 'syntax sugar' may benefit to a programmer
    in practice. After all we're humans, not CPUs.
blog comments powered by Disqus