Programming Languages

To tell your computer how to do something, you must use a programming language. A programming language is similar to a human language in that it’s made up of basic elements (such as nouns and verbs) and ways to combine those elements to create meaning (sentences, paragraphs, and novels). There are many languages to choose from (C, Java, Ruby, Perl...), and some have a larger set of those basic elements than others. Ruby has a fine set and is one of the easiest to learn (as well as being elegant and forgiving and the name of my daughter, and so forth), so we’ll use that one.

Perhaps the best reason for using Ruby is that Ruby programs tend to be short. For example, here’s a small program in Java:

public​ ​class​ HelloWorld {
public​ ​static​ ​void​ main(​String​ ​[]​args) {
System​.out.println(​"Hello World"​);
}
}

And here’s the same program in Ruby:

puts ​'Hello World'

This program, as you might guess from the Ruby version, just writes Hello World to your screen. It’s not nearly as obvious from looking at the Java version.

How about this comparison: I’ll write a program to do nothing! Nothing at all! In Ruby, you don’t need to write anything at all; a completely blank program will work just fine.

In Java, though, you need all this:

public​ ​class​ DoNothing {
public​ ​static​ ​void​ main(​String​​[]​ args) {
}
}

You need all that just to do nothing, just to say, “Hey, I am a Java program, and I don’t do anything!” So, that’s why we’ll use Ruby. (My first program was not in Ruby, which is another reason why it was so painful.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.5.125