From: Mike Kasick Date: 2008-05-29T02:47:25+09:00 Subject: Re: Should I Learn Ruby as a First Language? On Wed, May 28, 2008 at 09:45:00PM +0900, MRH wrote: > Throughout my research into this question, I have seen that the more > credible sources recommend either Python or Ruby, and I am personally > leaning quite heavily toward Ruby, yet I would very much like to read the > thoughts of the group on this question. I usually lump beginner programmers into one of two categories, (i) those who want to become expert programmers for purposes of education, profession, or hobby, and (ii) those who are interested in learning how to program sufficiently enough to make work in their primary careers easier, but don't necessarilly have a specific interest in programming itself. If you're of the former category, I would say it doesn't really matter what lanaguage you learn first since you will inevitably learn multiple languages anyways. Remember that a master programmer is not someone who expertly understands the minutiae of any single language, but rather is someone who is proficient in many languages. This is largely due to the fact that all programming languages seek to achieve that same high-level goal--enable programmers to use a machine to perform computation--and yet each language achieves this goal in a different and nuanced way. It's the understanding of these nuances, and why they exist, that paints the overall picture. That said, there are a lot of languages out there that are complicated or even cumbersome because they attempt to be sufficiently general as to allow any "style" of programming without enforcing too strict of rules as to what code should look like. Perhaps the best example of this phenomenon is C++, and to a lesser extent Perl. I express caution in learning these languages as first languages, since, as a novice programmer you don't really have an intuition for what code should look like, and the language doesn't really help guide you in learning either. Ruby is guilty of a similar phenomenon which, in this context, goes by the name of "expressiveness". While Ruby is certainly my favorite language, I know that part of my appreciation for this expressiveness comes from over a decade of experience in other languages and being able to place Ruby in the context of this experience. In other words, I'm not really sure if Ruby is the best, or even a good language for beginners because I'm not sure how difficult it is to learn without the benefit of experience. On the other hand, plenty of people have learned Ruby as their first language and have gone on to recommend it to others, so it's certainly possible, and probably not a bad choice either. That said, keep in mind that Ruby is a bit unique compared to other popular languages. For example, the idiom of using internal iterators and blocks as looping constructions (e.g., Enumerable#each) is unlike the usual approach of using a for loop and/or external iterator as you would use in C, C++, Java, or Python. While I think Ruby's approach is better, it is not the norm in other languages. Another example is Ruby's idiom of automatic allocation and deallocation of resources by passing them to code blocks (e.g., File#open). In other languages, one typically has to explicitly deallocate the resource (close the file) and the code for writing this safely is not intuitive. This brings up another advantage/disadvantage of learning Ruby first: code safetyness. One example of this is the resource allocation/deallocation idiom I mentioned above that ensures that resources are always properly cleaned up when the program is finished with their use. Another is that most methods raise an exception upon encountering an error, forcing a program to abort is an unexpected error happens. Exceptions are good, and they're prominent in other languages (Java and Python) and behave, more or less in the same way. Unfortunately some popular languages implement exceptions (C++ and Perl) but don't use them universally in library functions, and other languages (C) don't implement them at all. In these languages, you must (or at least should) check return values of any function you call to make sure that the desired action performed successfully. Often times people forget to do this, and the result is code that continues on ignoring error conditions, usually blowing up somewhere else where it's difficult to debug. So, while I regard these features as advantages of Ruby, they are, in some sense a disadvantage when you attempt to learn a different language that doesn't take care of these issues for you, as you must be diligent in taking care of them yourself and it's not something you're used to. Anyways, the crux of my advice is this: Any language that you're enthralled by, and can't get enough of, is a good (first) language to learn. On the other hand, any language that you find bewildering, confusing, or just plain unfun to learn is probably not a good first language candidate. If you find youself becoming disinterested after spending a week or two learning whatever language you choose, skip it and move on to something else. It may take a while to find the language that fits, but trial and error is better than giving up on programming entirely--especially when the language that clicks with you is right around the corner. Briefly getting back to the other category of beginner programmers, those that are not particularly interested in programming itself but recognize that some proficiency is beneficial for getting their work done--if you're only going to learn one language and you're not sure which, both Python and Ruby are reasonable choices. The argument is that since you're only going to learn one language, you might as well learn one that's useful enough to enable you to accomplish a wide variety of tasks, and one that's popular enough that there are many libraries, tutorials, and resources available for helping you get the job done. Python might be a bit superior with regard to popularity, at least in the English speaking community. At one time Perl was much more so, but I wouldn't consider any beneift in greater popularity of Perl to be worth the pain of having to deal with it's obtuseness.