15.01.2015 Views

Journal of Research in Innovative Teaching - National University

Journal of Research in Innovative Teaching - National University

Journal of Research in Innovative Teaching - National University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

the scope-by-name feature <strong>of</strong> Ruby enhances code readability. Know<strong>in</strong>g the scope <strong>of</strong> a variable<br />

from its name is a very concise yet <strong>in</strong>formative aspect <strong>of</strong> Ruby (Matsumoto, 2001).<br />

Polymorphism<br />

While there are different def<strong>in</strong>itions <strong>of</strong> polymorphism <strong>in</strong> the literature, Ruby implements a<br />

specific type <strong>of</strong> polymorphism that is not hard to def<strong>in</strong>e, <strong>in</strong>terface polymorphism. Interface<br />

polymorphism exists when objects have methods <strong>of</strong> the same name but are not <strong>in</strong>herit<strong>in</strong>g from<br />

each other. Ruby's version allows methods <strong>of</strong> modules to be mixed <strong>in</strong>to exist<strong>in</strong>g classes. Matz<br />

described this mix<strong>in</strong>g <strong>in</strong> as “a restricted form <strong>of</strong> multiple <strong>in</strong>heritance with implementation<br />

shar<strong>in</strong>g,” and that is discussed <strong>in</strong> more detail <strong>in</strong> the next feature, <strong>in</strong>heritance (Fulton, 2006).<br />

Overload<strong>in</strong>g operators is a specific polymorphism case. Operators like “+” and “*” are<br />

implemented as methods <strong>in</strong> Ruby. Fulton (2006) expla<strong>in</strong>ed how this means that a Ruby<br />

programmer can easily override an operator by redef<strong>in</strong><strong>in</strong>g its method to give it a new mean<strong>in</strong>g <strong>in</strong><br />

a particular context. The ability <strong>of</strong> overrid<strong>in</strong>g operators means that we can now add real estate<br />

properties, subtract <strong>of</strong>fice branches, and divide an apple pie.<br />

Inheritance<br />

Ruby was designed with elim<strong>in</strong>at<strong>in</strong>g confusion <strong>in</strong> m<strong>in</strong>d. It only supports s<strong>in</strong>gle <strong>in</strong>heritance<br />

because multiple <strong>in</strong>heritance can cause class hierarchies to be confus<strong>in</strong>g complex networks. The<br />

aforementioned module mix-<strong>in</strong> feature makes up for the lack <strong>of</strong> multiple <strong>in</strong>heritance <strong>in</strong> Ruby<br />

(Matsumoto, 2000). Inheritance was used <strong>in</strong> the project to reduce redundancy <strong>in</strong> the AST nodes<br />

implementation.<br />

Reflection<br />

A reflective programm<strong>in</strong>g language allows an active environment to query, extend, or modify<br />

objects at runtime. As a dynamic language, Ruby implements reflection, allow<strong>in</strong>g a programmer<br />

to check type, class, and methods <strong>of</strong> objects at runtime. The ObjectSpace Ruby module can<br />

access all and any liv<strong>in</strong>g object at runtime (Fulton, 2006).<br />

Garbage Collection<br />

Scott (2006) affirms that a big portion <strong>of</strong> costly application bugs are caused by programm<strong>in</strong>g<br />

errors <strong>in</strong> memory management. Memory leaks and dangl<strong>in</strong>g po<strong>in</strong>ters are common bugs <strong>in</strong><br />

applications written <strong>in</strong> languages that require manual memory deallocation. Ruby has an<br />

automatic garbage collector (GC) that relieves a programmer from perform<strong>in</strong>g such a task. Just<br />

like mostly anyth<strong>in</strong>g else <strong>in</strong> Ruby, the garbage collector is an object that can be accessed and<br />

managed us<strong>in</strong>g the GC module or the ObjectSpace module (Thomas, Fowler, & Hunt, 2004).<br />

Exception Handl<strong>in</strong>g<br />

Exception handl<strong>in</strong>g is the mechanism that deals with unexpected conditions that may arise <strong>in</strong> an<br />

application at runtime. If a programmer is to deal with such conditions, he or she would <strong>in</strong>vent a<br />

default value, return a status value, or pass a closure to a rout<strong>in</strong>e to handle that condition (Scott,<br />

2006). Luckily, Ruby programmers do not have to choose any <strong>of</strong> the previous possible actions<br />

because Ruby has built-<strong>in</strong> exception handl<strong>in</strong>g. There are many classes <strong>of</strong> exceptions that can be<br />

extended as needed (Fulton, 2006). Catch<strong>in</strong>g an exception <strong>in</strong> Ruby is as simple as us<strong>in</strong>g rescue<br />

and ensure clauses to deal with a certa<strong>in</strong> type <strong>of</strong> exception (Matsumoto, 2001). Exceptions <strong>in</strong><br />

65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!