Ruby on Rails Appeals to PHP Programmers
Sitepoint’s "The State of Web Development 2006/2007" paper cited an interesting statistic showing PHP programmers being the most likely group to switch to Ruby on Rails. More interesting was the reported gap between PHP and other languages in terms of the likelihood of a programmer jumping ship.
Matthew Magain, the article’s author said, "This surprised me, because it’s the Java developers that the Rails movement is targeting … [h]ere’s the question: do PHP coders know what they’re getting in for? Not to suggest that all PHP developers are burrowing away in an unstructured manner (we all know there are plenty of PHP frameworks these days that provide MVC separation and other similar benefits to Rails), but I wonder how many PHP developers are actually using them. Looking at some of the code out there, my guess is less than half."
Whether these statistics represent a fad or a trend is debatable, but two years after its birth Ruby on Rails is definitely still sparking interest in the web development community.
Similarly tagged OmniNerd content:
- GPU Password Cracking, by VnutZ almost 2 years ago
- Duke Nukem Forever - Capture The Babe, by VnutZ about 2 years ago
- Skin I/O, by VnutZ about 3 years ago
- Hacking the PS3 Hypervisor, by VnutZ over 3 years ago


Print Friendly
Write an Article
Toying with Rails by markmcb
I’ve been toying with Rails now for about a month (really only a few days if you count all the days I haven’t touched it). As a PHP programmer on OmniNerd, I must say that I like both the Ruby language and the Rails framework. There are some drawbacks, but they’ve seemed minor so far.
The key thing I’ve found with Rails is that it makes writing a new app fun in that you spend more time thinking about what you want to implement and not so much every little detail of how. For example, let’s say you’re writing some OmniNerd code and you need to be able to process the title of a person’s comment:
… even a non-coder can see the hassle that’s removed. Multiply this situation by 100 and you see the great burden a framework like Rails offers.
To be fair, Rails is a framework and PHP is a language. Of the frameworks available for php, none appealed to me too much. We’ll see how it goes. If you’re a web developer, I’d at least write a simple app in Rails just to see what all the hype is about. I think you’ll enjoy it. If nothing else, be sure to flip through why’s poignant guide to Ruby. It’s quite entertaining.
RE: Toying with Rails by varnerac
I have not toyed with Rails. I am a Java developer and there are many viable MVC frameworks: Struts 1, Webwork (soon to be Struts Action 2), Beehive, etc. I use Struts 1 and Beehive at the moment.
I like PHP but I have never used it with an MVC framework. I agree that most PHP programmers do not. You are lucky to find PHP code broken out into classes, much less a separation of business logic and presentation. The same sins can be commited with JSPs.
I think PHP is akin to Visual Basic in this respect. It is an easy language to start with. However, it’s easy to write bad PHP. Visual Basic is the same. Folks who start with VB write the worst Java code. That’s not the case with languages like Python or C++.
RE: Toying with Rails by markmcb
However, it’s easy to write bad PHP.
Yeah, you’re exactly right. What’s funny is that I know what good and bad code looks like, yet I’ll often be lazy and write quick but poor code. Then, months later when I want to upgrade I kick myself for being lazy and creating more work. I’ve never really give any framework a shot, but I think I will consider them more simply because they force certain restrictions and generally better code. I know there are exceptions, but I’m ok with that.
I’ve actually never touched Python or Java. I hear Java is where it’s at for big projects. One thing I’ve found I like about Ruby is that it’s easier to read in general, even for the simple stuff. So, I think only time will tell if RoR is something that will be of great use for me. I’m crossing my fingers because it’s been fun so far.
RE: Toying with Rails by Anonymous
I have seen plenty of people knock Ruby/Python for the wrong reasons. I am a Java guy, but I am not sure that the assertion:
I hear Java is where it’s at for big projects.
is on the money.
Java’s perks include:
Out of these strengths, corporate acceptance trumps the others.
I think the reality is that Java is where it’s at for mid-sized projects. I believe the big guys (Yahoo, Google, etc.) are not running J2EE. There are a number of reasons for this. Corporate acceptance in these enterprises is influenced by history. These business were built on Open Source technologies. The Internet was originally built on Perl and CGI.
The arguments folks make against Python/Ruby is speed, and I am not sure this is fair. Why is a synthetic benchmark based on Fibonacci numbers relevant to how my web application performs. It likely is not. Often, better is the enemy of "good enough". Is my web application better if a page loads 10x faster? Before you say yes, what is the difference between a page that loads in 100ms and 10ms? Requirements documents should specify how fast a page should load. The page either does or it does not.
For really big projects, upkeep is your nightmare. I think Python/Ruby are easier to read and are often self-documenting. Additionally, you can do more in less lines of code with Very High Level Languages (VHLL). Seasoned engineers know that a robust system is an iceberg. The development costs are the tip of the iceberg. Maintenance and enhancement are the dangerous portion below the water’s edge.
Java has lots of library support. This is a common reason it is used in enterprise apps. However, Python and Ruby can call most native C/C++ libraries via SWIG. So, there is good library support for both enviroments. Look at PHP. Any external functionality you could imagine has been integrated in one way, shape or form.
RE: Toying with Rails by VnutZ
So it’s been half a decade since you wrote this … just curious how your thoughts and impressions have changed or been reinforced.
RE: Toying with Rails by markmcb
Reinforced. The framework has come a long way since I wrote this bit. There’s a lot of new stuff out there, and Javascript is today what Rails was in 2006 in terms of hype, but despite the hype dissipation Rails still has a clear strength for the solution space in which it exists and remains competitive amongst all the options out there. I’d still recommend it to anyone.
That said, I’ve seen a lot of newbies get a little over-excited about it and think that they’re going to build the next Google simply because they wrote a blog in 10 minutes. Good code and good ideas still take time and hard work. Rails is like a really nice hammer. It’s good to have, but just because you have it doesn’t make you a good carpenter.
Ruby as a Standalone by VnutZ
Have you used Ruby for anything other than Rails based web servers?
I found some interesting uses for it in modeling various things, but generally found Python more useful as a high level scripting language. I can see Ruby really having value (again, standalone) for academic pursuits.
RE: Ruby as a Standalone by markmcb
If you mean, “is it easier than writing/reading a bash script,” then yes. I write little scripts all the time to make sense of things on my computer or to knock out some task. That said, I’ve not used python, so I can’t really compare. Why do you say python is more useful? Do you prefer it personally, or do you see specific advantages?
RE: Ruby as a Standalone by VnutZ
I think the utility of Python vs Ruby is very similar to the arguments of C vs Ada back in school. Ada was very structured and defined with a “way” to do things properly. But that was also it’s limitation. Whereas C was wild and woolly allowing you to get yourself into all kinds of problems … but that allowed it to fit itself into any shaped hole as needed. I see Python being more like a gas that can fill any room whereas Ruby needs somebody truly versed in the nuances of the language in order to either make it fit the room or declare the room doesn’t fit Ruby.
RE: Ruby as a Standalone by markmcb
I guess I’m not following your comparison. Rails has a “way” to do things, but not Ruby (at least not any more than any other language). I’ve only read up on Python, but as far as I can tell the only real differences are “in the weeds” and come down to programming preference.
If you have an example of what you think you can’t do in Ruby and have a Python example, I’m curious to see. On the contrary, check out class extensions in Ruby vs. Python.
RE: Ruby as a Standalone by VnutZ
Yeah … unfortunately all my examples would result in your death and my criminal incarceration.
Ruby & Pointers by VnutZ
Well – I can think of one quick example where Ruby was a pain in the ass. In any language that would allow me to use pointers within a buffer and treat an arbitrary address and size as a buffer, parsing a PE32 file would be remarkably easy.
Ruby however, required continually slicing the original object “string”. This isn’t necessarily bad … it did work. And you can certainly treat the base index as the pointer into the string. Where it really gets ugly is when you’re not parsing forward and continually jump back and forth through the buffer. This was a pain parsing out ZIP files as well.
There’s a reason a lot of the gem files for doing things like this are C code wrapped up into an object.
RE: Ruby & Pointers by markmcb
Ruby is not C. They’re two totally different classes of languages. See differences from C for a more complete list, which includes the lack of pointers. For your specific example, did you make use of Ruby’s IO class and the seek method? It provides pointer-like functionality.
I could throw out arbitrary cases where C can’t do what Ruby can easily. For example, what’s the fastest way to to get a list of folders in an arbitrary folder? For Ruby, from the command line …
$ ruby -e "puts Dir.new(Dir.pwd).entries.collect{|f| f if File.directory?(f)}.compact.join(', ')"A quick search for the easiest way to do this in C didn’t look that easy to me. And that’s just the code. You still have to save it in a file, compile it, make the binary executable, and run it. But that doesn’t mean C is a pain. It just means C is not Ruby.
RE: Ruby & Pointers by wyldeling
I’ll byte. In c++, based off of this tutorial
Obviously, the important line
is as simple as the ruby code, it just takes a little to set up. But, even that isn’t bad.
RE: Ruby & Pointers by scottb
I’m not sure I buy this. There’s no reason you ever actually need an actual pointer, unless you’re trying to reference memory-mapped hardware addresses.
A buffer is a contiguous block of bytes. In Ruby, that’s a String — you just don’t use the character-oriented methods, you use array indexing. A “pointer” into the buffer is just an array subscript.
For any other use, object references serve the role pointers do in C.
RE: Ruby & Pointers by Anonymous
There’s no reason you ever actually need an actual pointer …
Correct. I did implement the thing without pointers using a painful series of slices and variables to hold those indices. But my point was that it was gloriously painful to do it because many of the references are calculated on a daisy chain of prior values. In Ruby it was ugly to not be able to cast record structures against a pointer to various buffers within that string.
Another Ruby approach would have been to build a PE32 class with a shit-ton of accessors hiding all that kludge. But for a single use case that was not going to be inherited by anything, that was even more work than doing the crazy daisy chain of slice calculations.
It wouldn’t have been all that bad if files would always conform to the PE spec as opposed to doing extreme edge case things with it for the sake of being tiny files requiring a lot of sanity checks to fail out of the waterfall along the way.
And the array indexing is also non-elegant when each subsequent value is not going to be the same size or type and furthermore may be at varying offsets based on prior values or formatting triggers.
RE: Ruby & Pointers by scottb
In Ruby it was ugly to not be able to cast record structures against a pointer to various buffers within that string.
I still don’t buy it. In C, you’d have some sort of struct declaration to represent the data, and you’d cast a pointer to a byte in the array to be a pointer to that struct, and reference the pieces.
So:
In Ruby, your buffer is a String, and, instead of having a structure declaration, you unpack a chunk of the string into an array…
Seems pretty equivalent. Add a helper method or two to make it readable and it’s not bad. The biggest advantage you might get from C is that those structs are probably already declared for you in vendor-supplied header files somewhere.
RE: Ruby & Pointers by VnutZ
That’s exactly what I did. Trust me – it was not at all equivalent.
And where this code is going to migrate into, I really need to ditch interpreted language altogether in order to keep up with the deluge of buffers that it’s going to process against.
RE: Ruby & Pointers by scottb
Well, there’s not much to be done about performance. But a little bit of metaprogramming would make the unpacking much easier.
You could build a little DSL that let you do something like:
The class methods (“word”, “dword”, etc) would build up an unpacking string as a class variable, and Unpackable would also supply a method, let’s call it “view”, so you could write:
The end result is code that’s almost completely parallel to the C equivalent.
RE: Ruby & Pointers by VnutZ
Sure, for something that is unrelated to why I was doing this, you can do that for part of it.
But for what I needed to do … no … you … can’t. PE32 formats are only static like that for so far … and then the thing gets entirely calculated and can completely overlay itself with backwards addressing that can overlap its structure in horrible ways. And like I said, I’m only addressing a base example, the further details of which and subsequently the why you’d need a clearance to know anymore.
So let’s drop it here. Everything you’ve suggested … where it can be done, I’ve already done it. Nothing new is being presented here. Ruby doesn’t work for my purposes beyond that without being horribly ugly.
RE: Ruby & Pointers by scottb
… and then the thing gets entirely calculated and can completely overlay itself with backwards addressing that can overlap its structure in horrible ways.
But that’s no prettier to work with in C.
I’ll drop it, but like I said, I don’t really buy it.