Ruby Blackjack
“Hm, I should probably learn Ruby.”
I probably first said this about a year and a half ago when Ruby and Ruby on Rails were “in”, the cool new (relatively, anyways, Ruby was written in 1995) language and the easy to use web application framework that went along with it. In the year and a half since then, I’ve glanced at Ruby and Rails, not looking at it close enough to discover more than that it resembled Perl and possibly Python.
Well, as part of an internship interview, I’ve finally gotten a reason to actually sit down, read the Ruby documentation, and understand how this language works. I am almost done writing a command line blackjack implementation in Ruby. Here are my thoughts:
Object-oriented. I really like the way Ruby strongly object oriented – everything is an object, including integers and booleans, which most other languages designate as primitives. This preemptively takes care of the limitations in designating these types as primitives, which often lead to wrapper classes such as Java’s Boolean and Integer.
Open classes. Ruby implements open classes, which allows you to define or redefine the behavior of any class at any time. This way, I can easily implement: a predicate in the String class that checks if a string is empty or nil, a foldr method in the Array class, or anything else that I need. In contrast, in Java, implementing these functions would require creating another StringUtils or ArrayUtils class.
Powerful. I don’t know if powerful is the right word. Overall, I just feel like I would be much more comfortable writing complicated/long programs in Ruby, over Python or Perl. Normally, I would stick to Java or C++ for projects with a larger scope. Ruby is really nice, except for…
End? Syntax complaint. I really prefer using brackets {} to denote a block of code, such as the interior of a loop or a function. Maybe I’m just not used to the language yet, but I feel that it is laid out so that it is difficult to understand and read code by simply scanning through it. The problem is made worse by the fact that with brackets, I can easily use vim or TextMate to find the corresponding bracket, whereas “if … end” doesn’t lend itself quite as well to that kind of searching.
I hate blackjack. What a terrible game. Blackjack is a mishmash of rules and variants that make an elegant implementation of the game difficult. It is a simple, boring game that casinos keep around because it is considered a beginners game, and so is played by novices who pay little to no attention to strategy. Provided a player plays correctly, the game is relatively even, with a house advantage of less than 0.5% for more common variants. Generally, blackjack is just not worth playing. Stick with poker.
In summary, blackjack sucks, Ruby is pretty cool.