Our first big feature is finally ready for a pull request. This week (week 8) we finished our feature, made some more tests for it, refactored it, benchamrked it and fixed all the bugs we found in it. Last week when Matthew answered and said that we need to do the compiling, I thought that we would need to change many parts of our code and that it would take more than a week, but fortunately it turned out to be quite easy. We just needed to call a compile method on the templates that we already had and that was it. So now what is left is to check that there is nothing that we have forgotten and make sure our code works. After that we need to write the documentation/explanation for our feature and then make the pull request. It’s going to be interesting to see what people think. I hope we’ve done everything right.
The topic for this weeks post is the programming language we are working with. In this case, Ruby.
Ruby
Ruby is an dynamic, object-oriented programming language developed by Yukihiro Matsumoto in the mid 90s. Yukihiro wanted a scripting language that was object oriented and easy to use, so he decided to make it and Ruby was born. It has steadily grown in popularity since its release and Ruby is now one of the most used programming languages in the world. The Ruby on Rails framework that we are working on has contributed to the popularity of Ruby a lot. Ruby is influenced by languages such as lisp, perl and smalltalk and supports programming paradigms like functional, reflective and imperative.
Ruby is designed to be simple but powerful and it’s goal is to be a programmer friendly language. It emphasizes productivity and programmer satisfaction, which makes it a well liked language. This approach has its downsides as well of course. The performance of Ruby is not on par with some other languages, so if you need performance, Ruby might not be the best tool for you. But it more than makes up for this with its great features that make programming faster and more enjoyable.
In Ruby everything is an object, even numbers. This makes using it easy, since the same rules apply to everything in Ruby. Another thing that makes Ruby a language that is fun and easy to program in is its simple and intuitive syntax. Here’s a simple program that takes a string from the user and tells how long it is.
puts "Give a string"
string = gets.chomp
puts string.length
Quite simple, isn’t it? Due to everything being an object, you can do things like:
100.times do
something
end
and
"string".downcase.split('r')
If you want, you can even add properties and methods to Ruby’s built in classes.
A feature that makes Ruby stand apart from other similar languages are blocks. Blocks are a feature that Ruby has adopted from functional programming languages. Blocks are essentially chunks of code that can be passed to methods just like parameters. For example, {puts “Hello, world!”} is a simple block.
def method
yield
do.something
end
method {puts "Hello, world!"}
Here a block is passed to the method and in the place of yield, the block is executed. This is the simplest example. Blocks can also be given variables and they can be saved (a saved block is called a proc). Blocks are a great feature that make programming in Ruby more interesting, but also a bit more complex. I don’t think I’ve mastered the use of blocks just yet, as this is the first language I’ve used them in. This is the thing I hope to improve on during this project. They aren’t hard to use, but you just need to get used to them and learn to know when to use them.
Overall Ruby is a fun language to write code in, and I will surely be using it even after this project is over.