So, my advisor and I agreed that the Ruby metaprogramming route seemed like it may be the most promising. As such, I'm trying to learn Ruby now - when I remember. >_<. Here are my initial thoughts on this much-loved language.
The first thing I have to say is this: I don't like inferred typing. I never used it in Haskell unless I had to, and it always made me feel uncomfortable in Erlang - though the single assignment made it livable. Then there's also the added quirk that variables don't need to be declared at all before they're used (though this is only really relevant to global/instance variables). Not having to declare what my instance variables (or their types) are before I can just start using them makes me feel unsafe. One of the few things that I _like_ about .h (or .hpp if you prefer) files in C++ is that I can immediately get a summary of what my class does without having to look at any implementation. I can't know what a given instance variable in Ruby is supposed to be until I see it in the context of the code unless I have documentation somewhere on it. If it's something that's not going to have an accessor, I may not even have any knowledge of it until it sees use in some function!
I also don't like the lack of statement-end delimiters. I'm used to my semi-colons, periods, or whatever else. Not having them makes me feel uncomfortable. In languages where you have a statement ending delimiter, you can _always_ tell where a given statement ends. In languages like Ruby or Python where single line statements are assumed, there are exceptions that you need to pay attention for if a statement wraps to multiple lines. With Python, at least, the line wrapping symbol is fairly noticeable. In Ruby, it's just a period. That's easy to miss, and it makes it potentially easy to misread code. I'm certain that proper style would avoid this issue, but it still makes me feel funny when I'm coding (and not in the pleasant way).
There are some things that I really like about Ruby. Much the same as Python, Ruby tries to incorporate some really handy things usually associated with functional programming. Things like folding and mapping across collections. I really like having these...but trying to use them in an OO context is just weird. I'm fairly certain I've got the "inject" syntax under control after forcing myself to use it a bit, but it's just not as intuitive as, say, a Haskell fold.
There are other things that I like about Ruby, too. While I don't think it reads like "natural" language, there are a few constructs that make it more readable (assuming you're not trying to read it like C style code, the way most of us are trained to <_<). Guard statements, for instance, are something that I really like having. I know that some people don't like them (having the condition come at the end of the statement hides some of the operability from immediate view); but I think it's a fairly elegant syntax that makes single line conditionals much more legible.
I also like the strongly OO nature of it. There were things that I _really liked_ about Smalltalk that the Squeak implementation overwhelmed leaving me not appreciating the language overmuch. Lots of these things are present in Ruby.
Mostly, I need to find a good way to learn exactly what it is I need to learn in Ruby before I can go on to learning about metaprogramming and get to work on the meat of this project.
Sunday, February 22, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment