21
Sat, Dec
3 New Articles

Finally! Ruby on Rails on IBM i!

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Waiting for the next big thing on the i? Maybe this is it. Ruby on Rails, a very popular web language, is now available for use with the i. But what does that really mean for you?

 

Finally, Ruby on Rails, the Darling Parade of the Internet world, is on the IBM i. But before I begin, I want everyone to know exactly what this article is about.

 

First, I am not going to teach you how to code Ruby on Rails. Like I could actually do that in a magazine article anyway. Ruby is a powerful, full-function language, and learning it is not something that can be done in an afternoon, even with a glass or two of merlot.

 

Second, this is not going to be a sales article for Ruby. Some people might think it should be, but it isn't. Nor is it a hatchet job. Ruby on Rails is a great language and a great framework (Ruby is the language; Rails is the framework), and its appearance on the i is a really, really good thing. All I'm trying to do is present an unvarnished and fair appraisal of it and explain what it really means for the i.

 

What's Ruby's Story?

Ruby was initially developed back in 1993 by some guy, in this case Yukihiro "Matz" Matsumoto, who sounds like someone who either pitched for the Dodgers or was an Iron Chef. His motivation was to provide a language that would "help every programmer in the world be productive, and to enjoy programming, and to be happy." Interesting conjunction of thoughts. The name Ruby was basically pulled out of a hat (the other option was Coral, both birthstones) during an online chat session between the Matz and a buddy of his, Keiju "Wildbird" Ishitsuka. The oft-cited myth that it was named after the 1961 hit "Ruby Baby" by Dion and the Belmonts has been denied numerous times, but you know how those things are. They keep popping up.

 

What is Ruby? Well, if you look at Wikipedia, it describes it as a "dynamic, reflective, object-oriented, general programming language." Interesting. If you look at what may or may not be the official website of the Ruby language (because Ruby is completely open source and has no corporate sponsor), it says Ruby is "a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write."

 

Ruby was inspired by Perl and by Smalltalk, Eiffel, and Lisp, which means that it is similar to those guys and, indirectly, to Python (isn't everything?), but it's not really a direct copy of anything.

 

Unlike PHP, which is mostly overseen by Zend, and .Net, which is in the Microsoft world, Ruby has no single group that controls it. There are a number of different implementations from different groups. The most common version of Ruby is the one you can get from www.ruby-lang.org. It is called MRI for Matz's Ruby Interpreter, and the current version is 2.1.0. Because Ruby is open source, it can change quickly, which is both good and bad (deprecating obsolete code structures and so having to change old code before you upgrade to a new release of Ruby vs. not having to change code as you move to new releases even though you keep things that are not best practice). It's not a trivial question.

Interesting Stuff About Ruby

But none of that really answers the question: what is Ruby like? So let's take a look. Below is an example of some Ruby code. Can't tell too much from that other than it looks different from what I'm used to seeing in either PHP or RPG, although it's not that freaky. And, in fairness, you can do this whole "Hello World" thing with just a single statement where you hard code the verbiage. I'm not trying to make Ruby look unnecessarily complex, just showing an example of what the syntax looks like.

 

# The Greeter class

class Greeter

     def initialize(name)

         @name = name.capitalize

     end

 

     def salute

         puts “Hello #{@name}!

     end

end

 

# Create a new object

g = Greeter.new(“world”)

 

# Output “Hello World!”

g.salute

 

 

According to Matz, Ruby was written with the "Principle of Least Astonishment" in mind. POLA is a common term that means whatever happens in a language, it should cause the least amount of astonishment for an experienced programmer. That last part is important: "an experienced programmer." This is sometimes in opposition to the "Principle of Least Surprise," which refers more to new users, to not surprising people with the way the language works. And these are real terms too. I know they sound like something I would have made up, but they're real. What this means is that Ruby was written by an experienced programmer so that the language would behave the way an experienced programmer would expect or want it to. But that's not the same as saying that the language is intuitive or works the way a beginner might expect it to. Some Ruby adherents don't like it when I state it that way, like I'm making Ruby seem, again, unnecessarily complex. That whole POLA/POLS question really rests on what's important to you: learning it fast or it having it behave nicely when you really know it. Anyway, we'll come back to this in a bit when we try to decide whether Ruby is easy to learn or not. Just keep it in your back pocket.

More Interesting Facts About Ruby

First, Ruby is OO, from the ground up. PHP is OO too, but the OO was added on later. PHP can be done procedurally, although it seems that most of the cool kids now look down on you if you don't use OO. In PHP, you can define classes, and those classes contain methods (functions) and properties (data), but you can also define data or functions just on their own. In Ruby, everything is set up as a class, even things like the null or Boolean.

 

Another thing about Ruby is that it's interpretive for the most part. That is, most versions of Ruby that run are interpretive, including Matz's version. And that's par for the course for most web languages (but not Java or .Net). Ruby does have a reputation among the cool kids of being slower than either PHP or .Net, and the benchmarks I've seen bear that out. I believe efforts are underway to make it faster, and it does seem that recent versions of it have been speeded up, but it still seems to be the slowest of the three. Although, with today's processors, this should probably not be a reason for you to nix Ruby.

 

Ruby is both dynamic/strong- and duck-typing compatible. Dynamic typing involves allowing the data type for each variable to be set "on the fly" rather than requiring it be set prior to use (as with RPG). Strong typing means that once you do set the variable type, the system expects you to stick by that (as RPG does) and not pretend that it's something else. PHP by contrast is dynamic and weakly typed. The variables mean well, but they will be whatever you tell them to be, changing types as often as Florence changed its currency (see The Inferno by Dante Alighieri). Duck typing is related to classes. Instead of an object being given a specific class that it's related to and forcing it to operate only in that class, any class is free to use any object as long as it works. That is, we look at an object in terms of what it can do (i.e., if it walks like a duck, etc.) rather than how it was necessarily categorized.

 

Community. This is what I hear every time I check on Ruby. They have such a great community and so many Ruby Gems (modules that do specific things and that you can download) that it makes development very easy. And I have no doubt that's truethat the Ruby folks are really eager to help others and that there are a lot of Ruby Gems out there. What I'm not so sure about is whether this is the reason you should choose Ruby over any other language. All of the stats I've seen show that PHP is far and away the usage leader over Ruby, and there are tons of PHP plugins out there waiting for you to pick them up. But again, I don't think you should choose a language based specifically on a community. All of the major languages have communities, and web people just love to code stuff up and share it with others. It seems they just can't help it. Although this data is over a year old, I think the percentages are still fairly accurate: PHP vs. Ruby usage.

 

The other thing you will hear about Ruby, if you check out the blogs, is that it doesn't scale well. And I honestly don't know if this is true or not from a practical standpoint. It's based on Twitter's experiences, where they originally wrote the site in Ruby and then had to do a rewrite as traffic increased. Yeah, I'm really worried about this one. Because if I write an app for one of my clients, I fully expect it to have at least as much traffic as Twitter gets (yes, I'm being sarcastic). For most people, scalability at that level shouldn't be an issue. Again, not the reason to use or not use Ruby.

 

Finally, Ruby is elegant. Everyone says that. I'm not sure what that means. I don't think it means it's easy to learn (see below). I think it means that it looks like you think code should look: easy to read, easy to follow, easy to figure out. I sort of think it's how I view /Free versus positional RPG. And I can't say how using an "elegant" language will impact your bottom line, although it is better to say that it looks "elegant" than it looks "like hell."

 

Everyone also talks about how productive Ruby is, how it eliminates code, how it makes things quick to do. Much of this relates to Rails (also see below), but I'm not sure exactly how to translate that. It does sound good though, doesn't it? And for many people, that's a solid reason for using Ruby over other languages. If you look over the web language blogs, everybody is always complaining about the PHP frameworks. They like this one, they hate that one, they will declare a blood feud with anyone they see using a third one. But not with Ruby. Everybody seems to love Rails and how productive they can be on it.

And What Is Rails?

There's a number (not a huge number) of frameworks in the Ruby world, but Rails is the overwhelming leader. Frameworks are very big in the web world, although I think they may be more important for people developing full web applications than they are for somebody using a web language to build a web page that interfaces to an RPG program. However, we're getting more and more into developing full web applications, so I think the importance of frameworks in our world is going to grow.

 

When I first heard about frameworks, I thought it was something like PDM or RDi; that is, I thought of it as more of a development environment. But frameworks are really more about setting up a structure for the application and letting you expand on and embellish that structure as you create your application. It gives you a starting point and some models to work with, and it also helps with version control and promotion to production. Sometimes an IDE is associated with the framework, such as using Zend Studio with the Zend Framework 2, but Ruby does not have a big-player IDE. Apparently, Ruby people like to work from a command line. There are a few IDEs out there, however, so don't despair. Although, when in Rome….

 

What everyone does agree on is that Rails is wonderful. It's easy to use and intuitive, and people feel very productive when they're using it, and I will not dispute that.

Is Ruby Easy to Learn?

Ah, finally we get to something where a fight is liable to break out. Step right up, gents, pick your side and roll up your sleeves for some bare-knuckle action.

 

One of the things I've read in a number of places is that Ruby is "intuitive" and "easy to learn."

 

And then I looked at the small slice of code above. And I thought about what "The Matz" said about it being designed to behave "the way an experienced programmer would think it should" rather than the way a beginner might expect it to.

 

And I thought about my own experiences with another language, PHP, which has been described as "easy to learn." I thought so too until I took a Zend Framework2 class a month or so ago. Heavy OO code. A very, very humbling experience. I'd rather not talk about it if that's OK with you.

 

Most sources talk about Ruby's "elegance" (and I read that and think "intuitive and easy"). But one post that I looked at by Leo Teo has a slightly different take. Now I don't know Leo. His picture on the site shows him wearing an Uncle Buck-style fur hat holding a dog. Maybe he lives in Alaska. Or maybe he's insane. Anyway, Leo likes Ruby. Has been programming in it for a couple of years. But his take is that it's easy to learn the basics of Ruby, but it is quite another thing to learn the full language. And apparently to do anything that is not trivial, you have to know quite a bit. That make sense to me.

 

At the same time, Leo says that PHP is easy to learn (compared to Ruby). OK, so consider this. As I said above, I thought PHP was easy to learn until I took the Zend Framework class. And now I realize that, to really understand PHP, I'm probably going to have to put in about a year's worth of study and testing. So if that's true of an easy language, how long will it take me to get good with Ruby? But what is really interesting is that Leo says that even though PHP is easier to learn and he likes it, he would much rather work with Ruby for the productivity and elegance. Now, I'm not suggesting you make your decision based on just what Leo says, but it's a good article. I just can't get past the hat.

 

So is it easy to learn? I don't know. I guess I'll spend a year really exploring PHP and then maybe two years learning Ruby, and then I'll let you know. Or maybe I will do neither and turn my attention to creating the perfect dirty martini. But my gut feel is that even though it may be easy to do something in Ruby, learning to do tough stuff in Ruby may just take a while. And the tough stuff is where it's at, Jack. .

And What About Interfacing It to the i?

Finally, how do we interface this Ruby program, written in a text file, into the i world?

 

Well, the script itself will go in the IFS, just as a PHP script would.

 

And the DB2 access? This has been taken care of through a wrapper written by IBMer Tony Cairns, who modified the existing ibm_db project for IBM i support and added a Ruby wrapper to the XMLSERVICE open-source project. I don't know any of the details behind that; it's yet to come out, but the path is there.

Is Ruby a Good Thing?

So, is Ruby on the i a good thing?

 

Dude, of course it's a good thing. Any time a real web language is ported over to the I, it's a good thing. It gives us street cred and makes us legit.

 

Downsides? Like what? Seriously? Some people will say that PHP is used a lot more than Ruby and that PHP programmers are both easier to find and cheaper than their Ruby counterparts. And that's true, but are you really trying to get the cheapest talent or the best language?

 

Maybe the real question is, do you personally have to learn Ruby to benefit from this? And I admit that people like me, journalists, feed the impression that you have to know everything or there must be something wrong with you. The simple truth, at least in my case, is that there's a lot I don't know yet I somehow seem to keep going. And I have friends and everything. Well, a couple.

 

So the answer to that (do you have to learn Ruby) is…no. And that's where I really make the Ruby people mad. Because they really want you to learn Ruby so you can appreciate it the way they do, but the truth is that you don't have to learn Ruby any more than you have to learn PHP. Because the web applications you're writing should be written from a modular perspective (that is, some in RPG and some in a web language), so you can easily contract out the web part.

 

I know, that's sort of wimpy, isn't it? We i people have always been very hands-on. But the truth is most i people are more business experts than they are anything else. And most of them have enough on their plate just staying current with RPG/ILE/Free plus keeping up with their users. When is there time to take on another language? I think for most people that's just plain unreasonable. If it isn't for you, or you feel you have to in order to keep your job, go for it. Learn Ruby, dabble in PHP, try .Net and then you can decide for yourself which one you like, because my belief is that much of it boils down to personal preference.

Final Analysis

Yes, there are other ways to do web work on the i, but Ruby is definitely a contender. Yes, some people think it's slower than some other methods, but unless you have a very high transaction rate app (and I'm guessing you don't), you'll never notice the difference. On the other hand, everyone that I have seen who uses PHP and Ruby agrees that Ruby is very elegant and yields high productivity. I discount the Ruby community and its Gems because I think the PHP community is larger and has more plug-ins. Yes, there are some concerns about how long it takes to really learn it, but I firmly believe that's true of all the web languages. Could you teach someone all you know about RPG in a week or through a demo? There are a ton of PHP vs. Ruby posts out on the web and I picked one or two or three at random. See what they think.

 

Ruby is a solid, excellent language that is a contender for title of Really Cool Web Language.

 

Is Ruby the long-awaited game changer, the one language that will usher in a golden age of web development on the i? No, I don't think so. It's another tool, and a good one, that will appeal to a lot of people in the web world, making the i less dinosaur-ish. The only thing that would be a true game changer would be either a web language that was truly native to the i and integrated directly with RPG or a version of RPG that ran on the web.

 

Want to know more about Ruby? Well, you can go to www.ruby-lang.org for starters. They have a bunch of references and documentation to get you started. Or you can go to Aaron Bartell's website, Power Ruby. Or just google Ruby and see what you get. Yeah, I dare you. If you want simple books, there's the Ruby for Kids website that tells you how to get Ruby on your machine (hey, Mac users, you already have it…so cool) and then how to get started. It says you can build a game in just an evening. Give it a try. You're as smart as a fifth-grader, aren't you?

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: