Oneta' N. Bunn
March 20,2001
Programming Language
Dr. Crawford

RUBY

A Programming Language

A brief history of Ruby

Ruby was born on February 24, 1993. Matz had been talking with some colleagues about the possibility of object-oriented scripting languages (as opposed to programming languages that offer OO support.) Matz was not a lover of the language Perl. "It had the smell of a toy language. It still does," says Matz. Python was another language that fell the high standard of Matz. Eventhough it is a language of OO, he felt that the object features had to be added on. Matz says, "as a language maniac and OO fan for 15 years, really wanted a genuine, easy-to-use, object-oriented scripting language." So in the mean time he created "Ruby." (Stodte, Feb,2000.) Ruby has grown so much since February of 1993, there has been mailing list established, Web pages formed and designed, and a community. The mailing list has played a great part in getting this language together. The oldest Ruby list has 14,789 messages to date. Believe it are not most of the scripters and developers for Ruby has come from Python and Perl. Basing the language on Perl, it was written in C. Ruby is in fact a streamline version of Perl.

Sample Program

#! /user/local/bin/ruby
require "socket"

ARGV.push "" if ARGV.size == 0

ARGV.each{|adr|

name, dom = adr.split("@")

if dom

remote=TCPsocket.oppen(dom,'finger')
print "[#{dom}] \n"
begin
remote << if name then "#{name} \n" else "\n" end
while remote.gets
# you should use read instead of gets
# to defend the buffer from overflow.
print
end
ensure
remote.close
end

Ruby: a new language

Introducing the latest open source gem from Japan

Ruby has been in the process of gaining popularity over the past few years. Especially in Japan, where the language was born at and conceived. Ruby is highly portable and easily customized but it primarily draws users because of its purity and readability.

Ruby by definition is an object-oriented language. It literally treats every data structure as an object, and offers only single inheritance with its methods in order to reduce confusion and encourage simple, straightforward codes. Ruby's interface to objects are completely defined, and will allow for extensive code alteration in implementing the methods.

Language profile

Ruby is known as a scripting language. This language is weakly typed and interpreted, but surpasses even Perl in its handling of complex data stuctures and information. Therefore, Ruby is not strictly a glue language. Only languages that are strongly typed, can and are able to handle arbitrarily complex data structures, and able to work independently of other programs on their own compilers are high-level system languages. Like Perl, Ruby has shown and proven to be an exception to this artificial distinction, because it too falls between being interpreted and compiled, and its functions allow for the capability of being able to handle more complex data structures and not as many strict scripting languages. Example Tcl.

Ruby is mainly an language that is interpreted. Meaning that Ruby avoids all of the various problems and annoyances usually associated with compilers and compiled programs and languages. "Because it is object-oriented, Ruby is highly reliable and can write small programs that are reusable and easily modified. Ruby includes all the basic OO features (such as classes, methods, etc.) that other object-oriented languages offer; inheritance, polymorphism, singleton method, and mix-in are all implemented in Ruby. But, unlike other languages offering these OO features, Ruby is a pure object-oriented language."(Stodte, Feb,2000). Fundamentally, Ruby is also a extensible language. By that you can either compile source code for extensions and integrate them into your local system, or download precompiled extensions from the home page and other various sites. To avoid building your own extensions, use the Latter option.

Language properties

Running speed

Ruby can load extension libraries dynamically as long as your OS is capable. It can link its libraries to application programs as they are run or loaded immediately. You don't have to wait for compilation to complete. Ruby can share library codes between several tasks that are run simultaneously, which increases the run speed significantly. With this it minimizes the size of each program, if a program doesn't need to contain the entire library, or copies of the routines they use individually. Since Ruby can load extensions libraries dynamically makes up for the loss of speed normally associated with an interpreted language.

Learnability

Learnability is one of Ruby's main cheif attractions. Ruby has an overloading feature (polymorphism), that makes the operators easily defined and are syntax sugar for the methods. To represent operators with different argument types Ruby uses single symbols. An typical example of the feature in OO languages is the use of "-" for both monadic operators, like negation, and dyadic operators, example is subtraction. Also, they use "+" for addition of both floating-point numbers and integers.(Stodte, Feb,2000)

Ruby's syntax is widely known for its simplicity, because it makes code that is user-friendly and readable on the one hand, and also it features a highly powerful grammar and semantics on the other hand. To use as an example, Perl requires the use of the semicolon at the end of virtually all statements; by contrast Ruby anicipants the end of all statements without such a prompt.

How does Ruby differ from other OO Languages?

Ruby differs in pure object orientation, inheritance, and closures.

Pure object orientation

Ruby has some major advantages over languages such as Python and Perl because Ruby is a complete and pure- but open- OO scripting language. All data are treated as objects without exception. As an example, Ruby treats an integer, which is automatically converted, as an instance of class Fixnum or Bignum, depending on its size. One other language has this feature, Smalltalk, but Ruby is less comprehensive and powerful. Without taking in account, integers in Ruby are used without internal representation being considered.

Inheritance

Ruby features only single inheritance, in order to avoid complexity and messy syntax. In Ruby sub-classes can only be derived from one parent. This is in opposition to multiple inheritance features that allow sub-classes to be derived from multiple parent classes, they are not derived from one another.(Stodte, Feb,2000) However, Ruby understand modules like collection of method, and any other class can import any module by receiving it free.

Closures and the iterator

The scope is specified by simple naming conventions rather than by variable declarations. The region within which represents a function or procedure is also known as scope. "Var" is a way of specifing a local variable, "@var" specifies a region variable, and "$var" specifies a global variable. "Self" variables are unnecessary to use in instance member. With present variable bindings instead of unnamed functions is used with the closure process.

How does Ruby compare to Perl and Python?

There is a rumor out the Ruby is "better Perl than Perl." Not looking at the fact that it owes most of its design to Perl. Starting from $_the short cuts to extended regular expressions. Remembering that Ruby is a complete OO language and Perl is not. A OO language features occasionally attach clumsily and ineffectively to straight Perl. Because Ruby is a OO language it does not have this problem. Prefixes are used to specify variable scope (Perl specifies by data type) and much less punctuation is used in Ruby. Because of this Ruby script is less cryptic than Perl, and its syntax is more learnable, and so easier to modify.

The Ruby Community

The people that use Ruby comes from all parts of the world and from all walks of life. This includes students and professors, researchers in speech recognition and natural language processing, software developers both in the commercial and open source community, specialists in parallel computing, ASIC designers, Debian developers, and network administrators. There are many reasons why Ruby attracts many different users. Some are won over by how easy it is top possibly code Gtk+ applications. Some others like the simplicity, powerful string manipulation and purity of design as an OO language. Perl is not being used as much because it doesn't handle complicated data structures well. Also, because it doesn't handle multi-dimensional arrays effectively and it is difficult to read.

Referernce

Stodte, Maya. Ruby: a new language. IBM: developerWorks: Linux library, Feb. 2000