The Ruby Programming Language
Many of the most succesfull startups of the recent years have beeen developed with Ruby and Ruby on Rails. Let's see together why
Introduction
Ruby is a computer programing language first appeared on the scene 29 years ago (on December 21, 1995). It is an interpreted, high-level, general-purpose, dynamically typed, object-oriented, reflective, imperative, functional and procedural programming language with automatic memory management whose main purpose was to create an object-oriented scripting language with a strong emphasize on programmer productiveness, enjoyment and happiness while working with the language, being ruby philosophy all projected to put human needings on top of machine constraints. As Yukihiro "Matz" Matsumoto, the creator of the language, put it in his own words: "... we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They [the machines] are the slaves."
Ruby design as been influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp and its strong popularity further increased with the first release in 2005 of Ruby on Rails, an open source server-side web application framework providing default management of a database, a web service, and web pages whose effectiveness, coupled with easines and speednes of development, has gained great adoption and has also inspired many other web frameworks design in other languages like Django in Python, Laravel in PHP, Phoenix in Elixir, and Sails.js in Node.js.
First glance at the code
Example: The classic "Hello world" program written in Ruby:
Main features of Ruby
Technical features
Dynamically typed
In Ruby everything is an object, including what in other languages are usually primitives like numbers or booleans. The language has the following primary data types: String, Fixnum, Integer, Numeric, Float, NilClass, Hash, Symbol, Array, Range.
Object-oriented
Ruby is an object-oriented language and every variables in Ruby is a reference to an object. Functions are always methods of some class and if no class is specified the function becomes a method of the Object class and is available to every other object too. Ruby asupports inheritance with dynamic dispatch, mixins and singleton methods. While Ruby does not support multiple inheritance, classes can import modules as mixins. Ruby supports metaprogramming and reflection.
Memory management
Memory management in Ruby is automatic. In the first versions Ruby used a mark and sweep (M&S) algorithm for it's garbage collector while more recently an incremental garbage collector with short pause times has been introduced.
Concurrent
Ruby offers multi-threading constructs and support, but both the original Ruby MRI interpreter as well as the current YARV bytecode interpreter make it effectively impossible to run Ruby code in multiple threads at the same time because they use a global lock that prevents the parallel execution of more than a single Ruby source code at a time. To get true and parallel multi-threading execution of Ruby it's necessary to use other implementations like JRuby, IronRuby or Rubinius.
Ruby libraries/ecosystem
Ruby has an assorted set of libraries and frameworks freely available for the development of server-side web-applications as well as for mobile app development for Android devices and iPhone and iPad. Specific Ruby implementations like JRuby for the Java Virtual Machine, or IronRuby for the .NET Framework can also access libraries and frameworks from those ecosystems.
Performance
Being an interpreted language Ruby execution performance is aligned to other interpreted languages such as PHP and Python, meaning that Ruby programs run slower than C/C++ or even Java ones. Anyway Ruby applications can also run on the Java Virtual Machine thanks to the JRuby implementation, on .NET Framework thanks to IronRuby or with Rubinius, a well-known fast Ruby implementation.
Run-time support
Ruby is an interpreted language. Ruby programs can run on the reference interpreter which is available for Windows, Mac OS X and Linux systems or on Java Virtual Machine and .NET platform.
Other features
Free and open source
The Ruby programming language is free and open source, however its license has been approved by the Free Software Foundation and is GPL-compatible but has not ben approved by the Open Source Initiative.
Notable softwares/platforms/products written in Ruby
- Airbnb has been written in Ruby
- Kickstarter has been developed in Ruby
- GitHub, the most popular repository hosting service for code developers of the world, has been developed in Ruby
- ASKfm also has been developed in Ruby
Best books for learning Ruby
For beginners
Intro To Ruby Programming: Beginners Guide Series | |
Learning Ruby has never been this fast and easy, or fun! Written for the absolute beginner, you don't need any programming experience to dive in and get started with this book. Follow along as John teaches you to set up a development environment and write your first program. You'll learn about... (continue on Amazon) |
For experienced programmers
Metaprogramming Ruby 2: Program Like the Ruby Pros (Facets of Ruby) | |
Write powerful Ruby code that is easy to maintain and change Once the domain of expert Rubyists, metaprogramming is now accessible to programmers of all levels. Metaprogramming Ruby explains metaprogramming in... (continue on Amazon) |
Conclusion
Ruby is a scripting language and has a dynamic type system. As usual these kind of languages are not really ideal for big and complex software development. Still one can argue that with so many successful startups using them for the development of their platforms maybe it's not that bad if a language has a dynamic type system. Well, expert programmers know very well how things become when a project grows, the team expands and the used language has a dynamic type system, and they really don't like it. On the other front, both expert and novice programmers also know very well that more than a type system a language is worth its frameworks and ecosystem, and for sure Ruby has a lot to offer and even to teach on this regard.