Deciding on taking up a programming language comes with many different considerations. Languages have many differences beyond just their syntax. Languages can be compiled or interpreted, with strong or weak typing, and availability of object-oriented programming options. In this article, we will focus on the Ruby programming language and some of the features you may consider when reviewing it for your next project.
- Special Features of The Ruby Programming Language
- Interpreted Language
- Object-Oriented Programming (OOP) Support
- Dynamic Typing
- Many Different Implemenations
Special Features of The Ruby Programming Language
In this article, you will learn some of the special features of the Ruby language as compared to features of other languages, so you can get better understanding of Ruby and decide if it is a language you would like to have in your development toolkit. But note, some of these features may have overlap with other interpreted languages like Python. However, the best way to get a feel for what makes Ruby special is to get your hands in the code and try it out.
There is an ongoing debate among developers about the performance and benefits of compiled versus interpreted languages. Ruby is interpreted language, which means the code you write is interpreted by a program (Ruby itself, as an exectutable file) to give you results.
One of the clear benefits of interpreted languages is that they are widely supported. Just about every computer on the market has a copy of the Ruby exectuable (the file that interprets Ruby code). Or if not, Ruby can be easily installed. This makes support for Ruby apps virtually universal. And, the programs can be easily self-contained, even running on different versions within the same workstation. So if you’re developing a program in Ruby version 2.5 and one in version 2.7, you can easily keep them separated or change versions of the fly using the Ruby Version Manager.
The general rule about interpreted programs is that they are fast to produce because you can start coding and seeing results right away without having to worry about setting up a compiler. On the flip side, however, compiled programs tend to run faster in action. This, again, depends largely on the size and complexity of the program. (You may never notice any serious lag in performance.)
Compiling a program has the additional benefit of obfuscating the source code, which is preferable for some proprietary programs that do not want to have their code available to the general public for copying. However, if you plan on making your Ruby code open source then this is no problem for you.
Object-Oriented Programming (OOP) Support
Ruby comes with built-in support for object-oriented programming, as opposed to procedural programming. While procedural programming starts from the beginning and works down through a series of instructions, object-oriented programming provides opportunities to have code set aside that will only run based on certain contexts. However, the choice between both styles depends on the programmer. Just because Ruby support object-oriented programming doesn’t mean you have to use it. If you prefer a procedural, functional, or other style of coding, you are free to use that.
No, this does not mean that Ruby will type itself for you. It means that if you set a type of data for a particular variable you can later change that data type. You may be familiar with how languages like C and Java require that, for example, an integer needs to be declared as such. And if the variable assignment must change at a different point in the program it needs to be converted. Dynamic typing, as you have available in Ruby, allows you to seemlessly change the type of data in any given variable.
Many Different Implemenations
The classic Ruby you know is written in C, so you can extend it — if you know C. But there are other implementations of Ruby, such as JRuby, which is written in Java. So if you know Java, you can use JRuby to extend your work in Ruby. This kind of flexibility makes Ruby an attractive option for programmers who already work in other languages.