Green Ruby Programmer

This space will chart my progress through the world of Ruby programming. Hopefully, it will conclude with me becoming a master Ruby programmer. With a moniker like this one, I shall have plenty of motivation to make that sooner rather than later! My other favorite programming languages these days are Python and Java. I have known both of them for about a decade.

Tuesday, May 30, 2006

RadRails site came back up last week

The RadRails website was only down for a couple days. It has been up since around the latter half of last week.

I blogged something about it the day it came up, but that post got stuck in my blogging client somehow and never made it here.

I was finally able to see the plugins list show up last week. It is a pretty neat feature to have in RadRails GUI. I am really impressed with that that team has pulled off. Even more amazingly, I think they are in school too,

And the upside of that is - they hopefully have the summer off. So more code, more often - maybe.

Wednesday, May 24, 2006

RadRails - A Ruby on Rails IDE

The website for the excellent RadRails Ruby On Rails Eclipse-based IDE is back up today.

Technorati tags: , ,

Tuesday, May 23, 2006

99 bottles of (ruby-colored) beer on the wall

I wanted to create a really simple web page with Ruby On Rails.

I have been using HTML for about a dozen years. I have been doing some Ruby programming off and on for the past 6 months or so. I wanted to put the two together in an RHTML page.

Here is what I generated:
        4 bottles of beer on the wall,
4 bottles of beer.
Take one down, pass it around -
3 bottles of beer on the wall.

3 bottles of beer on the wall,
3 bottles of beer.
Take one down, pass it around -
2 bottles of beer on the wall.

2 bottles of beer on the wall,
2 bottles of beer.
Take one down, pass it around -
1 bottles of beer on the wall.

1 bottle of beer on the wall,
1 bottle of beer.
Take one down, pass it around -
no more bottles of beer on the wall.



Turned out to be pretty easy to coax my server to display this output. Other than zombie-drone work typing in the HTML and the non-varying parts of the text, all I did was read the parameter and execute a loop - using Ruby.

Here is the HTML that makes that web page show up:
<html>
<head>
<title>Beer Song in Ruby On Rails</title>
</head>
<body>

<pre>

4 bottles of beer on the wall,
4 bottles of beer.
Take one down, pass it around -
3 bottles of beer on the wall.

3 bottles of beer on the wall,
3 bottles of beer.
Take one down, pass it around -
2 bottles of beer on the wall.

2 bottles of beer on the wall,
2 bottles of beer.
Take one down, pass it around -
1 bottles of beer on the wall.

1 bottle of beer on the wall,
1 bottle of beer.
Take one down, pass it around -
no more bottles of beer on the wall.
</pre>
</body>
</html>


That is the goal actually, not the solution to the problem.


The whole solution is just about fifteen lines of RHTML, most of which is plain, old HTML.

The interesting part that generates the portion of the page that actually executes multiple times - and handles changing the text each pass through the loop - is here:

        <% start = params[:start].to_i %><% start = 99 unless start!=0 %>
<pre>
<% start.downto(2) do |bottles| %>
<%= bottles %> bottles of beer on the wall,
<%= bottles %> bottles of beer.
Take one down, pass it around -
<%= bottles-1 %> bottles of beer on the wall.
<% end %>


I made a couple mistakes as I put this together.
  1. Tried using the pound-sign/braces formatting trick that works in all Ruby double quoted literals.
  2. Tried using a more terse expression to set the default value of the start variable.


As you can see, neither of these things required a complicated fix.


Kicking it off was a piece of cake. The URL looks like this:

   http://www.yourhost.com/beer_song/sing?start=4



The need to have a start parameter instead of just hardcoding the value 99 as the loop count is dubious, I admit.

I forced that requirement in so I would have to read a parameter from the request and use its value in my view. Plus, I wanted to be able to have sample output that would not require 20 pages of output!


As I worked myself through these little self-generated exercises, I of course generated a couple application errors along the way. That was quite useful, actually.

I was impressed by the quality of the error messages. To me, an error message has to tell the person reading it what they are supposed to do - if anything - to fix the problem (or help get it fixed). Rails error message was great. I am the developer. It gave me a nice stack trace.


My next task is to create a few tables in an SQL database. Then I can have a page that modifies and displays these values in a web page.

I have a couple of useful applications in mind. So after I get these newbie etudes out of the way, I can move on to them.

At that point I will be checking off a lot of things on my personal TODO lists.



RadRails website is down

I tried to get to the Rad Rails site (www.radrails.org and plugins.radrails.org) today and cannot. It is broken.



www.radrails.org: Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

Technorati Tags:

Monday, May 15, 2006

RadRails 0.6.3 and getting my Ruby/Rails house in order on my Mac really helped

As I mentioned last week, I was experiencing a few new problems after upgrading to RailsRails 0.6.2

It looks like problems were coming at me from several difference sources. Here are at least a couple of them.

  1. regression bug in RadRails 0.6.2 which caused context-assist (control+space auto-completion) to fail
  2. my failure to define an up-to-date Ruby On Rails and Ruby environment outside of the RadRails IDE


Before, I was completely relying on a Rails bundle within Locomotive for to provide the environment for Creating a Rails application environment.


I think I remember hearing that RadRails needs an external environment defined which includes Ruby On Rails and Rails. And, it needs an up-to–date one as well.

Fortunately, I recently spotted an extremely useful tutorial on using Mac OS X for developing Rails applications by Apple Computer.

The tutorial included a link to a wonderful page containing step-by-step instructions for Building Ruby, Rails, LightTPD, and MySQL on Tiger. It was complete, and it results in the latest versions of all the programs Ruby On Rails needs, including itself, being installed in /usr/local. That was precisely what I wanted to do!


So this weekend, I did that. The process went smoothly.

Afterwards, I launched RadRails (0.6.2) and told it where these things were. It got much happier. It was still not quite itself - but very close. That was where I left things last night (Sunday).


This evening, I updated RadRails from version 0.6.2 to 0.6.3. This is now a piece of cake, thanks to the RadRails team using the Eclipse update feature. It probably made their builds a little more complicated. However, it sure makes life nice for us RadRails users!

Things in the IDE seem pretty close to working the way the RadRails guys intended now.


My hat is off to: Apple, Dan Benjamin of Hivelogic, the RadRails team, and the Eclipse developers.

If you are doing Ruby On Rails development on a Macintosh - and you are having some problems with your environment or running the right commands - visit the pages I cited and you will get yourself quickly unstuck.

RadRails releases 0.6.3 thus quashing its content-assist regression

People noticed that the content assist feature of RadRails was broken in version 0.6.2.

Last week, RadRails 0.6.3 was released - fixing this bug.



Technorati Tags:
, , ,


Sunday, May 14, 2006

Invoking Yahoo Search Services from Ruby

Looking for a way to access Yahoo Search web services from Ruby programs?


Premshree Pillai has written a very clean-looking Ruby API for Yahoo! Search Web Services.

It is published in a syntax-colored, pretty-printed programming listing on a Plone content management system (CMS).

Plone is written in Python. Python and Ruby are somewhat programming language rivals.

So it is kind of funny to see such a powerful, useful Ruby program hanging out on a Plone server.


I really have to hand it to Premshree. This is a very clean piece of programming.

The program, which was written in mid-2005, has no dependencies on any software that is not included in the standard Ruby 1.8 distribution. That means it can be used without any hassle at all.

The search functionality is implemented in a 2-layer hierarchy of classes. They are:
  1. Search class with the generic mechanisms common to all the searches
  2. Specific class for each different concrete search type


This is an excellent demonstration of the use of inheritance as a practical way to approach specialization in object-oriented programs.


Here are the classes that Premshree has defined for the specific types of searches on Yahoo:
  1. ImagesSearch
  2. NewsSearch
  3. RelatedSuggestion
  4. RelatedTags (My Web)
  5. SpellingSuggestion
  6. TagSearch (My Web)
  7. UrlSearch (My Web)
  8. VideoSearch
  9. WebSearch


All requests are sent using the simple REST protocol that Yahoo has defined for their services.

Here is an example of the easy-to-use API being told to carry out a search for videos on the subject of ruby.

# assume that MY_APP_ID has been set to your Yahoo application ID
video_search = VideoSearch.new(MY_APP_ID, 'ruby')
ruby_movies_dict = video_search.parse_results



The ruby_movies_dict will contain a hash with the results from the search in it. Simple!


The only flaw with it that I can see is that there are no RDoc comments included for the methods.

The classes have obvious purpose from their names and their superclasses.

However, the methods would really benefit from a sample piece of code, demonstrating an actual call to them - and sample results that could be returned from that call.

That would eliminate any questions about what to do with whatever comes back. Of course, one could simply look at the documentation over at the Yahoo Developer web site, which spells out the format all of all XML data returned by each service.

The results returned vary a little from service to service. So one should be visiting that site for the info anyway. Still, shortcuts to enlightenment by the author of a reusable piece of code are always appreciated.



I think it is a Ruby programming work of art!


Technorati Tags:
, , , ,


Wednesday, May 10, 2006

RadRails 0.6.2

I have been using the stand alone version of RadRails for a while now.

I had some problems with RadRails 0.6.1. Hoping that the RadRails 0.6.2 release that came out a month ago would solve them, I upgraded to this newer version of it today.

Instead, the problems seem to have gotten worse. Well, I am having more problems than I did before - so it seems worse to me.

Trac on the RadRails site tells a pretty glowing tale of a piece of software with no major problems.

I have a bunch of things I am trying to get done before I go to bed tonight. So I decided to put it aside until at least tomorrow.

Chances are I will come act it with a completely different tact when I try again. That should let me get maximum discernment on the cause of the problem - without going around in circles doing/undoing things. Instead, I plan to download/run it in a completely different environment with a clean install - and see if that helps.

At this point, I have more faith in the software itself than my configuration of the software. So that is the angle I am going to be hitting it hard on tomorrow.

Tuesday, May 09, 2006

sidebar for this blog updated

I updated the sidebar of this weblog tonight. So if you are a still finding out where important/useful things for Ruby programmers are located on the web, take a look. It should help.

Sunday, May 07, 2006

Yahoo Answers can get you quick answers to Ruby questions

Yahoo Answers has been up and running for over several months now.

The site can be very helpful when you have a programming question and want to bounce it off of someone else at 2 a.m. your time, or whenever.

There always seem to be people on the site.

Here is the section for Programming and Design questions.

There is an RSS feed for Programming and Design questions and answers too.


Note that another website which you can get a surprising amount of information from is Wikipedia.

When you think of casting about for some quick answers to some software question, the last thing you are generally going to try to lay your hands on is an encyclopedia.

That is probably because in the past, the set of encyclopedias you had in your house was 10 to 15 years old, and was hardly up to the minute or comprehensive when it came to computers and software.

Happily, things have changed - at least for Wikipedia readers!


So, when you get stuck - do not be afraid to ask for help or.... check out what the Wikipedia can tell you.

Ruby Programming Group on Yahoo Groups

There is a new Ruby Programming Group that has just recently started up over at Yahoo Groups.

So far, it looks like there are just some links to some useful web sites and some surveys. Looks like soon there will by a Ruby programming FAQ and a little repository of Ruby one-liners.

Friday, May 05, 2006

HOW-TO: Configure eclipse for Ruby on Rails

Sonjaya Tandon in her recent HOW-TO: Configure eclipse for Ruby on Rails says:

In this guide, I will go over how to configure Eclipse for Ruby on Rails. In the next one, I will go over setting up a simple project.


She points out two prerequisites in this fantastic, step-by-step, screenshot-laden tutorial:
  1. Make sure you are using Eclipse 3.1
  2. Make sure you have Ruby On Rails (and Ruby) already installed before you begin.

Some people have gotten burned by not heeding prerequisite number two... !

If you do not have Rails installed, you cannot configure Eclipse to use it. Then, major Rails related things are not going to be working - and you will be confused! The same holds true for having Ruby itself installed beforehand too.

Of course, there is a simpler way to get going with Rails development. You can simply download RadRails IDE, which is itself based on Eclipse IDE, and start using it right away. Again, make sure you have your prerequisite software installed before you run the application.

For now, I am simply using RadRails on my Macintosh.

Sonjaya Tandon » Hooked on Rails

Sonjaya Tandon::
I STRONGLY recommend anyone serious about software development to get this up and running on your development machines. Even if you don’t plan to develop your deployment applications on Rails there are simply too many good ideas that it captures to ignore it. It is a realization of decades of best practices around Model-View-Controller architecture. Make the time to prototype some applications in this environment. At the least, you will get some good ideas to take to your core development environment.


Well said, Sonjaya!

Ruby is a great language and Ruby On Rails is a framework worthy of the language.

There are a lot of good ideas and techniques in it. Hopefully, it will speed up adoption of a lot of the great approaches to software development that have gone unnoticed and unused by the bulk of programmers for so many years, and in some cases - decades.

I just realized the 2nd edition of the Rails book from the agile programmer was actually on sale in PDF form already, only an hour or two ago myself. I think I might do as she suggests and buy it.

Then I get the advantages of having it now, plus free updates for it later on.

I recently got an Amazon gift certificate for my birthday, so I will be picking up a couple more Ruby titles this month as well.

I finally am mastering the arcane art of blocks and procs. The result is I can do some really fun functional programming style things now in a very apt fashion.

I really am loving Ruby and it is great to see that programmers are finding Rails just as lovable.

AJAX validation in Rails

I have noticed it is pretty hard to get away with writing a software application without data entry validation.

It is kind of like eating a meal without opening your mouth. If you do manage to do it, you are going to be a real mess. And probably not fulfilled your technical requirements very well.

In AJAX validation in Rails, BigSmoke says:
This text discusses how I handled validation messages and other notices caused by AJAX requests.

Note that, as of this moment, this page will probably not work in IE because, for now, it's an XHTML 2(!) page that is converted client-side to an XHTML 1 document. Given the target audience of this writing, I thought this to be not too much of a problem.


Well, unfortunately, I have to add Apple Safari 2.0.3 to the list of browsers the page does not work with. In Safari, the page just comes up blank.

Works great in Camino 1.0.1 and Firefox 1.5.0.3 though.

The article is really easy to read and the color-coded/pretty-printed source code listings with snippets of Ruby and Javascript code in them are really easy on the eyes.

I think this article will be high on my list of things to read when I am doing some AJAX/JSON programming in Ruby On Rails.

Technorati Tags:
, , , ,


Thursday, May 04, 2006

Ruby On Rails Framework Adds AJAX Tools In Major Update @ SYS-CON AUSTRALIA

AjaxWorld News Desk @ SYS-CON AUSTRALIA has just now reported on the Ruby On Rails 1.1 release that came out last month.

They mention some of the best new features added in the 1.1 release, including: RJS, ActiveRecord enancement, and - naturally - the improved ability to do AJAX-style programming.

Javalon and Rubitilicus

Though I know a lot of computer languages, I do not really learn new ones on a whim anymore. There has to be a good reason to pick up a new one these days. Especially, if it is a relatively complicated one like Ruby - with very different syntactical idioms than others I have used.

A language like Java really is competing for the same jobs, contracts, programmers, and book market as Ruby. So, while the languages are not really all that similar to each other - they will be showing up at the same contests, and get to know each other really well.

Ruby and Java are like two very different organisms.

Both are roughly the same size. Both have claws, sharp teeth, webbed feet, 2 eyes that see things well close up and far away and spot movement easily. Both run on 4 legs, with webbed toes, and can swim if they have to.

They are both social creatures and usually hunt and live in packs. They communicate with each other, mark their trails, and also mark their territory.

One is a reptile. A cool, thoughtful, cautious, character.

The other is a mammal. It has a faster metabolism, and it burns more energy, especially when it seems to be at rest. It can cover more ground in less time than the other.

While they have some superficial differences and similarities, they also have one other thing in common. They both hunt the same prey. They live in the same ecological niche, despite their dissimilar ancestory and completely different taxonomy.

One way that computer languages have distinguished themselves from each other for the past decade goes beyond grammar things like syntax. What is almost as important on a day-to-day basis as that to a programmer is the standard library.

The Java standard library has a great GUI API - almost a framework, really. Swing GUI programs can run unchanged on lots of different platforms. They can adopt the native look and feel of the platform, use one of the built-in ones that comes with Java, or a company IT department or application programmer can define their own.

Yet J2SE does not come with any web APIs in its core library. You have to pick those up separately, with a web container like Tomcat, or a J2EE container like JBoss.

Then you get things like servlets, JSP (sort of like ASP), JSTL (a template language with a simple expression-evaluator and some standard tags), etc.
Or, you can write your own - the basics are not hard.

Still, web support is not included in every Java environment.

Ruby does not have a standard desktop GUI. Yet it does support web programming very well - right out of the box. It comes with CGI support, a templating tool (erb), and its own web server called WEBrick.

The core libraries of both languges come with XML support.

The support for XML in Ruby, through REXML, is more high level than that of Java (though lacking in validation support). Ruby also comes with support for the super-popular RSS standard. Java does not come with RSS support.

Java supports code reuse beyond standard OOP techniques using templates. Templates can be typesafe and are basically parameterized class types.

Java supports iteractors too, through another upgrade introduced in J5SE: the improved for statement.

Ruby supports code reuse beyond OOP through: mixins (via its include statement), and blocks. It also has a lot of direct support for functional programming and iterating through collections.

The technologies in both languages can cut down on source code bloat.

As is typical of most other things in these languages, Java makes it possible to write safer code with more pre-execution checking available. Ruby offers little such built-in safety. Yet a programmer has to write less code to get reuse - sometimes far less code.

Yes, unit tests will catch a lot of errors if you write them. However, nobody tries to get 100% coverage with their unit tests, let alone achieves that. Excellent unit testing frameworks are available for programs in both languages too, so as a point of comparison - unit tests are moot.

If you feel like doing far less typing, chances are, Ruby will fit your bill.

If you do not mind typing in a lot more code, as long as you get a lot of compiler-time checking, then Java is probably more to your ilking.

Another concern is Integrated Development environments. Clearly it matters as much, if not more so, than the contents of the standard library. After all, you can always look for things not in the core libraries in some third party libraries.

Java has Eclipse and NetBeans as its flagship IDEs. These IDEs are both widely accepted and on the cutting edge of technology. They are both really powerful.

Until recently, the Ruby community did not have a really solid IDE. However, RadRails is fast becoming that IDE.

Ironically, RadRails is based on the open source Eclipse IDE. So, basically, the leading Ruby IDE is written in Java.

All irony aside, that IDE is pretty good for writing/debugging/testing Ruby applications.

RadRails is not done yet, though. It still has a way to go before it reaches version 1.0 and has supported all the features that it eventually should. However, it has already received a major software development tool award.

By next year sometime, RadRails will probably be as good a Ruby On Rails and Ruby IDE as Eclipse is for Java. And it will probably have better support for Ruby-based web development than Eclipse offers for Java-based web development.

Ruby vs. the World - a quick glance

There are lots of things in Ruby I recognize from other languages.

Some of them seem borrowed directly from LISP.

lamda

clearly, the LISP lambda functions, also found in Python, borrowed from Lambda Calculus

blocks

very similar to LISP prog function



The way every Ruby function returns a value, the value of its last statement, and the return statement is not required - this comes directly from LISP.

The Ruby send method is similar to SmallTalk.

Look at how rival languages are faring today.

  • SmallTalk seems to have kind of lost the following it had in the 80s and 90s - despite the availibility of some very decent free implementations today.
  • LISP has never become a mainstream language and never will.
  • Python is popular, and simulaneously, growing in popularity and power almost every year. However, not as fast as Ruby. Nonetheless, it does have some major wins under its belt: Yahoo and Google have written a number of services in Python. The Django and Zope frameworks are really popular and are proven successes - witness things like the Plone CMS and at least one super-cool Web 2.0 blog.
  • Pascal is dead. With the demise of Borland's languages - Delphi, the last bastian of Pascal - has lost its patron.
  • C seems to have been relagated to being an OS and embedded systems programming language. Its attractiveness as an application programming language has seriously waned.
  • C++ still used as a first-tier programming language on MS-Windows, but will likely be devoured on that platform by its proprietary Microsoft cousin, C#
  • Visual Basic seems destined to be never more or less than it is now: a popular MS-Windows only proprietary language for the MS-Windows platform whose environment and grammar change every few years to suit the OS marketing agenda of its maker
  • Java seems to have subsumed the cross-platform custom IT application market. It looks like it will be embracing all the scripting languages in JDK 1.6, which is already in beta. Ruby and Java fight on the same battlefields but with dramatically different tactics. Very similar goals are being solved with each: interactive websites, online databases, custom IT applications, etc. Both are very object-oriented. Java is a powerful, yet very conservative language. It puts its stock in proven, safe principles - not syntax tricks. Ruby is different. It completely lacks most of the guardrails Java has built-in. Its skeleton is far less rigid. It favors using syntax tricks to make programs more expressive, readable and terse. At the same time, it allows programmers to make big mistakes which are caught late - something anathema to fundamental Java philosophies.


Some languages - like Python - are very similar to Ruby in terms of their characteristics and runtime environments.

Other languages - like Java - are very different to Ruby. Both, in terms of how much help they give programmers at runtime (and vice-versa!) and in terms of their langage grammar.

Python, Ruby, and Java are pretty relevant options to a lot of the same computing projects. They are all object-oriented and they are all very portable. Programs written in them tend to be portable as well.

The other languagss seem to be solving different problems, existing in difference niches.

So, while there are myriad programming languages out there, most are not relevant to solving the same big problems as these three are.

somewhere near or far from beginning - and far, far from ending

Last year I began a journey which I hope will turn me into an expert Ruby programmer.

Since then I have worked on some interesting programs: a text-based Role Playing Game (RPG), a yet-unfinished chess program, and a recently-started expression parser-and-evaluator.

I know a lot of computer languages. So many that it would be annoying to list them all here. Check my sidebar. I will list a bunch of them there.

I was kind of a language geek for a long time. Plus, I am in my third decade in the programming field.

So the number of programming, web document, and writing-tool languages I learned by impulse or compulsion is pretty high.

Ruby is one of the former. Nobody is forcing me to learn it. No one is even helping me to learn it. At least not formally.

As I learn new things related to Ruby programming, I will post some of the more interesting ones here.

I have a few quotes from the Dune books about beginnings. They sound kind of profound. They make a good close to my first post on this blog.

A beginning is the time for taking the most delicate care that the balances are correct. This every sister of the Bene Gesserit knows.
- from Manual of Muad'Dib by the Princess Irulan(source: Wikipedia)


Some actions have an end but no beginning; some begin but do not end. It all depends upon where the observer is standing.
- Leto Atreides

Related pages and news

Add this blog to my Technorati Favorites!
Click here to join ruby_programming_group
Click to join ruby_programming_group