Is Ruby such a good choice?

Let's see the Fibonacci implementation is C#, Ruby and Python.

C#:


Ruby:

Python:


As for me, C#'s Enumerable.Range() is somewhat messy compared to Ruby's and Python's variants.
Ruby's optional parentheses around arguments seem just right, as well as 'return' keyword which now looks spare in C# and Python for me.
Ruby's 40.times expression looks a bit weird, however, we could use more 'normal' loop like
for i in 0..39.
Python's absence of 'end' or '}' is the best thing in the whole language. I'm not joking.
So, I can't judge at the moment whether Ruby or Python code is more expressive or readable.

What about performance, C# wins with 9 secs, followed by Ruby with 1 minute and the Python variant took as much as 2 minute to execute. I must say that I don't bother about performance since in real life applications such numeric calculations encounter very rare and should not be done in dynamic scripting languages like Ruby or Python.

Comments

Popular posts from this blog

Haskell: performance

Regular expressions: Rust vs F# vs Scala

Hash maps: Rust, F#, D, Go, Scala