Online Book Reader

Home Category

Beyond Java - Bruce Tate [53]

By Root 673 0
like Ruby, that idea makes sense.

What I don't like


Smalltalk is not seen as a credible alternative. It just wasn't ever approachable enough. Smalltalk would have been a natural successor to C++ if Java hadn't come around first, but it was always too expensive, or too alien, or too obscure.

No Silver Bullet


You may have noticed that no language has all the characteristics we're seeking. That's not surprising. If one did, we'd be using it by now. Still, you can see that these languages do establish real strength in important areas. In the chapters to come, I'll take a deeper look at Ruby. Since it's not enough just to have a better language, we'll then investigate some potential killer apps.

* * *

[*] Dave Thomas, Programming Ruby (Dallas: Pragmatic Bookshelf, 2005).

[†] http://blog.ianbicking.org/why-web-programming-matters-most.html.

Chapter 6. Ruby in the Rough


I stood on the bank of the Watauga River, looking at the 16-foot, Class V monster known as State Line Falls. It had five boulders in the current with four chutes running through them. Three of the slots were all but impassable, especially at this water level. The fourth was violent and intense. And yet, the approach was pretty easy, and I thought I could hit the line. Run this monster, or walk it. I had to choose.

Over the years, I've experienced a few moments like that one. Sometimes, I'd put my kayak on my shoulder and walk around. Other times, I decided that the line was good and my skills were up to the challenge, so I made the run. But this time, I simply stood, indecisive, with the wind and the spray from the falls washing over me.

I'm looking at a similar situation now. I do think that Java's leadership run, at least for applications, might be drawing to an end. But the stakes are unbelievably high should I decide to move. How can I know if the timing is right? Can I pick the right language? What do I risk?

I don't want this book to be an exhaustive review of programming languages. I'd like to point out one language and two frameworks (one in Ruby and one in Smalltalk) that have something special to offer. In this chapter, I introduce one possible alternative language, Ruby. I want to show you that some languages can improve on Java, but that doesn't mean that Ruby will succeed, or that it's the best possible alternative. The best that I can do, for now, is to show you one possible alternative, so you can see if the case makes sense.

About Ruby


Ruby is a dynamic, fully object-oriented language that's usually grouped with scripting languages. The scripting term, for languages like Ruby, Smalltalk, and Python, is a little too limited, so I'll use the term applications language . If you've used nothing but compiled languages like Java and C, get ready to have some fun. Ruby will turn you loose. I suggest that you install it (just go to http://ruby-lang.org ), and type along. It comes with a primitive IDE, but the command line works well. Fire up a Ruby shell by typing irb. You'll get a shell prompt:

irb(main):001:0>

Ruby Is Fully OO


From here, you can evaluate Ruby statements. You'll frequently use irb to answer those tiny questions that come up often in programming. In Ruby, everything is an object, and if you type one alone, Ruby will return that object. Type 4 and press Enter:

irb(main):001:0> 4

=> 4

Unlike Java, numbers are objects , not primitives. For example, you can do this:

irb(main):008:0> 4.4765.round

=> 4

Even nil is a class, standing for nothing:

irb(main):009:0> nil.class

=> NilClass

You don't have to worry about primitives or wrappers at all. More importantly, you don't have to deal with those cases in an API. Ruby's reflection, persistence engines, and XML frameworks are all much simpler, because you don't have to deal with all the edge cases related to primitives and arrays of primitives.

Typing


Try to do an assignment without a declaration:

irb(main):011:0> n=1

=> 1

irb(main):012:0> n.class

=> Fixnum

So n has an object of type Fixnum. You didn't declare n at all.

Return Main Page Previous Page Next Page

®Online Book Reader