Python or Ruby for learning to program?
August 31, 2006 6:52 PM   Subscribe

Python or Ruby? Help me decide!

So, I'm aware that there are previous similar questions. However, I'm pretty sure I've narrowed it down to two - I just can't choose which!

I'd basically like to learn how to program, and in a way using best practices - I've heard object-oriented programming is good, for example, so would like to learn what it is and how to best program in that way. I've got a bit of experience with PHP, but have mostly forgotten it all by now (last time used? 6 months ago), and was never particularly proficient in the first place. Plus I've heard it's very difficult to write good code with PHP.

I'd mainly use whichever language on the web, although if it can do cool things with my computer (either my Mac (OSX) or PC), that would be a bonus. But learning good programming practices, writing clean code etc is my main priority. I'm not looking to learn a framework, I'd rather learn how to program and how to work with the language before doing so.

So, which one is best for me? And any recommended books for someone who will basically be an absolute beginner? Or is there a better language for what I want to do?
posted by djgh to Computers & Internet (45 answers total) 25 users marked this as a favorite
 
Ruby is trendier. I think you would be better off learning with Java as it's more straight forward, as well as being more "formal". You're right that PHP does suck.

One very strange thing about python is that "white space matters" Different levels of nesting are demarcated by different levels of indentation, rather then braces. This is vastly different from almost every other programming language, and as someone who's programmed in at least 15 different languages the idea bugs the hell out of me. And ruby is definitely trendier. People seem to love the Rails thing for web design.

One thing that sucks about Ruby is that it's character handling is all fucked up. Remember how metafilter used to have trouble handling foreign characters? That was a problem with some of the underlying code, rather then just "working" matt had to do some crazy hack to fix it: or upgrade the JDBC driver, I don't remember. If you're not worried about internationalization it won't be a problem for you.

But don't get stuck in a rut of doing things only in one programming language. You should actually learn both if they both interest you.
posted by delmoi at 7:01 PM on August 31, 2006


If your main goal is to write clean code, Python wins by a nose. Ruby still has some ugliness left over from Perl. Python was written from a mostly clean slate. Python also has a feature whose main benefit is cleanliness (indentation instead of command terminators).

Now, you can write clean code in both. Both are fine languages. It's just that Python's syntax is ever so slightly cleaner. There's less line noise.

But also note that you're presenting a false dilemma.

Both languages are run-time, message-typed OO languages. There's a whole class of languages (C++, C#, Java, etc) that are compile-time, subtyped OO languages. Some might argue that the code in the latter is cleaner than code in the former, in some ways. (But that said, stay away from C++ as a first language. C# probably beats Java 5.0 for cleaniness, but both have acquired some cruft recently.)

Also, maybe you should be picking the language based on what you want to do with it. Cleanliness shouldn't be the only factor in deciding. There are many interesting jobs in Ruby nowadays, but Python is more established. Java and C# lead to a different class of projects than the other two.
posted by maschnitz at 7:03 PM on August 31, 2006


Response by poster: I'd mainly want to do stuff online - i.e a handmade CMS, or other such things. I can't see myself wanting to make a program to run on an OS just yet.
posted by djgh at 7:06 PM on August 31, 2006


Oh, OK. That's reasonable. I'd probably recommend Ruby, then, all things considered.

Ruby's got a great starter MVC framework in Rails. (A pity about the O/R mapping, though.)

The only caution I'd have with Rails is that a lot of things happen "magically". As a beginner, it's important to ask yourself: "Well, how exactly did that magic thing work? What language mechanisms did that use?" You really have to stay on top of Ruby, the language, while you're using Rails, if you start from scratch like that.
posted by maschnitz at 7:13 PM on August 31, 2006


I first learned Python back when it was on version 1.4. I knew several other languages at that time and found Python to be grand fun. If I was at that same point in my life today, I would probably choose to learn Ruby instead. Its object-only architecture, advanced object capabilities (closures, etc.), beautiful syntax, and refinements over some bothersome issues in Python would win me over. This comparison from the Ruby website offers some other (obviously biased) arguments in favor of Ruby.

That said, there is nothing stopping you from learning both and seeing which best fits your style of thinking.
posted by pheideaux at 7:16 PM on August 31, 2006


"Plus I've heard it's very difficult to write good code with PHP."

Amen to that, brother.
posted by pheideaux at 7:17 PM on August 31, 2006


Response by poster: Yeah, like I said, I'm more after learning the language and how to program than a framework (I know Python has Django, but if I choose Python I'm not going to dive into Django straight away).

Thanks for the advice so far - keep it coming! Also, any recommended resources for absolute beginners for the languages?
posted by djgh at 7:18 PM on August 31, 2006


Both are really great languages, and Ruby is more fun to program, but when it comes to extensive libraries and (especially) performance, Python wins.
posted by evariste at 7:19 PM on August 31, 2006


djgh-I'm lazy so you're gonna have to Google these, but you'll find them easily.

Why's (Poignant) Guide to Ruby (free online)
Programming Ruby (this is referred to as "The Pickaxe Book") ($)

Dive Into Python by Mark Pilgrim (free online)
How To Think Like A Computer Scientist With Python (free online)
Learning Python ($)
posted by evariste at 7:21 PM on August 31, 2006


So totally Ruby.
posted by Zed_Lopez at 7:22 PM on August 31, 2006


I'd mainly want to do stuff online - i.e a handmade CMS, or other such things. I can't see myself wanting to make a program to run on an OS just yet.

Both languages are a great choice for this, honestly. With Ruby, you're basically going to do Ruby on Rails, and the documentation there is excellent.

With Python, you're going to use Django or Turbogears. Django has the better documentation right now, but Kevin Dangoor (Turbogears guy) promises that with the impending release of 1.0 and his book, the Turbogears docs will improve dramatically. However, Django is totally self-contained, while Turbogears is a "best of breed" collection of other Python projects, with glue. It uses Mochikit/JSON for Ajax stuff, SQLObject for object-relation mapping (this is the magic that turns your objects into database rows) with SQLAlchemy as a second-class, soon to be first-class citizen, Kid for templating, CherryPy for the webserver, and so forth. Not that there's anything wrong with that, but I'd be nervous about all these dependencies and it's a bit overwhelming for a newbie. I recommend you try out both Django and Turbogears, and suspect you'll go Django. Jeff Croft has a nice intro to Django for non-programmers that'll give you an idea of what it's all about.
posted by evariste at 7:28 PM on August 31, 2006 [1 favorite]


The languages are both clean and fun to use; Ruby is probably a teeny bit more cleanly designed (none of that goofy "self" business, no multiple inheritance), but Python's syntax is a bit cleaner and encourages good coding practices (I love docstrings). But the languages themselves are really a crapshoot; both rock. As such, I'd reccomend Python because of its much stronger libraries. Any particular library is much more likely to have Python bindings than Ruby ones, and Python's will be more mature (e.g. PyGTK goes beyond the plain C GTK api to integrate tightly with Python features like iterators).

For web dev, Ruby has the advantage of having the entire community focused on one framework, while Python, despite virtually everyone's wishes, remains fragmented. But that's partially a consequence of Python's rich library situation, which has made it ridiculously easy to create new dev frameworks. Django and Turbogears are both very good (stay the fuck away from Zope, even version 3). If you're looking to learn a language, not a framework, Python's the way to go.
posted by gsteff at 7:57 PM on August 31, 2006


I recently asked a moderately similar question. I ended up choosing python because its library support was more extensive; XML, numerical methods, etc. What I needed was in Python.

That said, I feel warm feelings towards Ruby because it's so cute. Why the Lucky Stiff! So cute.
posted by metaculpa at 7:58 PM on August 31, 2006


I would recommend you learn both, but Python first, if only so that you develop the cleanliness habits before rushing headlong into the hideously fugly mess that is Ruby.

evariste's links:

Dive Into Python
How to Think Like a Computer Scientist: Learning with Python
posted by nightchrome at 8:03 PM on August 31, 2006


I have an impression that you'll be able to work with a wider variety of web hosts if you work in Python; that the software needed to run Ruby code is less widely installed. I'd love to know if this is wrong.

Also: wouldn't "trendiness" be a reason to _avoid_ a language?
posted by amtho at 8:03 PM on August 31, 2006


Response by poster: gsteff (or anyone else) - can you explain the following please? (Remember, little programming experience):
Ruby is probably a teeny bit more cleanly designed (none of that goofy "self" business, no multiple inheritance), but Python's syntax is a bit cleaner and encourages good coding practices (I love docstrings)
Thank you!

And thank you to everyone who's replying, and giving links and whatnot. All of your input is really helpful.
posted by djgh at 8:40 PM on August 31, 2006


Response by poster: evariste, nightchrome - thanks for the reading suggestions/linkage. And nightchrome, can you exlain more the "hideously fugly mess"? I'm (obviously) unfamiliar with both languages.

amtho - I'm afraid I won't be able to help with the hosts question, I'm already with Dreamhost (...a subject for a whole different thread). Fingers crossed if I do put anything up I guess...
posted by djgh at 8:48 PM on August 31, 2006


djgh: I am quite biased, admittedly, but I personally find Ruby to look ugly due to its inheritance from Perl of the habit of over-using punctuation marks everywhere. As well, Python tends to resemble pseudo-code as much as possible, such that it parses mostly like English and is fairly easy to follow as a result. Ruby has a number of "features" which, while probably more efficient or flexible, make it far less intuitive to follow.
posted by nightchrome at 9:02 PM on August 31, 2006


As others have said: it's not either-or. Real programmers pick up new tools as needed, using whatever's best for the job at hand.

That said, for the beginner, I recommend Python. The syntax is simple and straightforward. Your experience with this language will easily transfer to other languages. You can start with simple, useful scripts and graduate quickly into object-oriented development.

It's a real language, used every day by professionals just like me. It's free. It's cross-platform. It has a lot of support and a lot of additional packages that make it easy to do interesting things.

There's no reason not to learn Ruby or C# or whatever floats your boat. But I recommend Python because it's easy to get started with and easy to do interesting, productive things with it.
posted by SPrintF at 9:15 PM on August 31, 2006


Sorry about that, djgh.

First, "self". Without trying to explain object-oriented programming in its entirety, in Python, methods get defined with one more argument than they're actually called with. The extra argument is the object the method is attached to, and by convention is always called "self." In most object-oriented languages, a special keyword is reserved for the current object (in Ruby, you use the "@" character), so that you don't have to explicitly name it in every single function definition, but in Python, you have to include it every time, which means that your functions end up being defined with one more argument than they're actually called with. This isn't a big deal at all... after a few hours, you'll forget that it ever felt weird, but it seems odd at first.

Python also supports multiple-inheritance, which Ruby doesn't. Multiple-inheritance is generally considered a Bad Thing, but no one forces you to use it, and in practice, almost no one does.

Docstrings are the bees knees. They're a way to add documentation for the various pieces of your code in the code itself. Not in comments according to some conventions, as many languages suggest, but actually wired into your code itself, you that you can lookup the instructions for how to use other people's code as you're using it. This is incredibly helpful for automatically generating documentation for code that you write, for encouraging people to write documentation, and for making it easy to explore unfamiliar libraries. Its probably my favorite feature of Python.
posted by gsteff at 9:33 PM on August 31, 2006 [1 favorite]


Perhaps instead of a procedural language, you might try a functional langauge?
posted by five fresh fish at 9:42 PM on August 31, 2006


Ruby is/can be functional (to a point).
people.find_all { |person| person.age > 10 }.sort_by { |person| person.age }

posted by wackybrit at 10:13 PM on August 31, 2006


As long as you can live with the indenting as syntax then use Python.

Ruby isn't much better. It's main feature at the moment appears to be it's flavour of the year.

Python is clean and well documented. It's a nice language.

Just FYI, Python is used considerably more than Ruby. I've been looking at job sites (in AU) and there are Python jobs, Ruby jobs are pretty much non-existent. Java is by far the most popular language in this regard BTW.
posted by sien at 10:31 PM on August 31, 2006


note: this is near and dear to my heart, and this response is long =).

There is some FUD here about Ruby and "line noise ugliness". There are some hold overs from Perl that Matz (the creator of Ruby) threw in there to ease the transition for Perl programmers. However, they are _strongly_ discouraged for all but the simplest throwaway scripts - you won't see any "$>" or "$_" noise in 99% of Ruby libraries or Rails applications. If you post that kind of stuff to ruby-talk, you will be gently advised to more OO alternatives. Variables are denoted with @ for instance and @@ for class, but when you grok the Ruby object model you'll see why that is.

Ruby is only superficially related to Perl - Matz has stated that he drew his inspiration from many languages, but Smalltalk and Lisp in particular.

For claims that Python encourages good programming habits over Ruby: "you can program fortran in any language". The habits you develop are more a matter of how you learn a language, your discipline, and who mentors you, especially when you are dealing with languages so similar as Ruby and Python.

When people say they dislike the excessive "self" in Python, they mean the fact that you have to declare a parameter for all methods w/i an object to refer to the enclosing object instance.
class Foo
    def process(self, bar, baz, boo)
        self.do_stuff # self gets passed in automatically, but we had to declare it as a parameter
    end
versus Ruby, where self is implicit at all times.
class Foo
    def process(bar, baz, boo)
      self.do_stuff # calls self on this instance of Foo, available implicitly
    end
I dislike the self thing, because it means I repeat myself a ton and it seems something the intrepeter should be able to figure out on its own. I'm sure if I worked in Python everyday it would eventually disappear, just like @'s in Ruby.

Ruby and Python are very close in features, and if you love programming you eventually learn both. That said, here's my argument for Ruby:
  • the code is beautiful and very human - examples:
    
    # Time extensions available in Rails via ActiveSupport, but you can do it yourself due to open classes
    20.years.from_now
    Time.now + 2.days + 10.hours + 15.minutes
    
    # blocks, aka closures
    (1..10).each { |num| puts num * 2 }  # prints "2 4 6 8 "... etc
    
    # find all managers from the employees collection
    managers = employees.select { |employee| employee.manager? }  
    
    # validating data in Rails
    class FrontPagePost < ActiveRecord::Base
    	validates_uniqueness_of :title
    	validates_prescence_of :title, :link, :link_text
    	validates_length_of :content, :minimum => 0, :maximum => 500
    end

  • The community is fantastic - we have characters like why, Matz is active on the mailing list, and people are helpful and friendly to newbies.

  • it follows the "Princple of Least Surprise" - many times the first thing you try just works, without having to hunt through docs or mess with syntax

  • Its extremely powerful and flexible - pretty much anything you want to do you _can_ do. Add a method to built in strings? Open up a class at runtime and modify it? Include blocks of methods into many different classes? Add methods to a single instance of an object (not its class)? All easily done.

With all this in mind, I think the best thing to do is try each of them for a few days and go from there. Here are some Ruby resources to try it out: No matter what you decide on, if you can get paid to do either for a living you are better off most programmers. Starting with either language is much better then starting with something like Java, C, or (shudder) C++. Have fun!
posted by rsanheim at 10:32 PM on August 31, 2006


amtho: Deploying rails app is getting better 8211; you can now use a place like Rails Playground that make it drop dead simple. I use dreamhost right now for a little Rails-based wiki, it was easy enough to get going.

SPrintF: Both are 8220;real8221; languages, so not sure what how stating that for python helps either way. People get paid to do ruby, too, like me (admittedly, there are less paid ruby guys then paid python 8211; though ruby is growing fast)

gstef: "@", as in "@first_name", denotes an instance variable in Ruby, not self. 8220;self8221; is self in Ruby. Also, Ruby has modules, which are give 90% of the benefit of multiple inheritance w/o the crazy complex corner cases.

five fresh fish: both of these are OO languages at heart, not procedural. Both can also handle some functional idioms.
posted by rsanheim at 10:40 PM on August 31, 2006


Forgot about a book that is perfect for the OP: Learn to Program by Chris Pine. Has a free edition online, with an expanded edition in print.
posted by rsanheim at 10:42 PM on August 31, 2006 [1 favorite]


I too am biased, but I don't find Ruby's punctuation excessive; it certainly doesn't follow from the Perl tradition of using it "everywhere". Most of my code probably has about as much as your average chunk of Python, perhaps with more @'s and ||'s and fewer __'s, :'s and endlessly repeated "self"'s.

I will admit, however, that my first impression was similar to nightchrome's; largely because of the initial wtf factor of seeing things like "foo.method {|e| [block of code] }" mixed in with one tutorial writer's unfortunate affinity for Perl-style $'/$_/$$ variables.

Personally, I'd suggest you try both; maybe start with Python for a week or two to get back into the feel of basic programming, then giving Ruby a try. The similarities should let you get into it quickly and improve your confidence with the basics, and the differences like Ruby's greater emphasis on closures will help broaden your understanding whichever you decide to make your primary.

<aside>gsteff: @ doesn't refer to the current object in Ruby; self does, just like Python. However, self.foo = bar calls the method self.foo=(), it doesn't reference the foo attribute, which is where @ comes in -- so you know you're poking directly at an important variable without going through an accessor method. Similarly with $ and @@; @@foo is a class variable, but @@ isn't the same as self.class
posted by Freaky at 11:14 PM on August 31, 2006


I'd mainly use whichever language on the web, although if it can do cool things with my computer (either my Mac (OSX) or PC), that would be a bonus.

Start here. Any decision should be made from this point: what do you want to do with it? Between the two choices, I would go with Python, because it has a larger library that you'll be able to start using out of the box, and because the code is (sadly, forcefully) cleaner to read. Code write-ability isn't nearly as important as code readability when you're trying to learn. That said, Java is a better choice than either of them, but it sounds like you have already made up your mind on your choices.
posted by Civil_Disobedient at 11:53 PM on August 31, 2006


The other bonus with python is that once you get used to it, you can branch out into PyObjC (not a different language, just bindings to Objective C) which lets you program Mac OS X program directly in python. Last time I looked, there was full (and decent) support for python executables in XCode.
posted by Mr Stickfigure at 1:14 AM on September 1, 2006


You can also branch into wxPython, which is Python bindings for wxWidgets, a cross-platform UI library. As Python itself is also cross-platform, this means that from one codebase you can create graphical applications that run on Mac, Linux and Windows, and look native in each of them. wxPython is really, seriously great.

There's also a wxRuby, but I don't know if it's anywhere nearly as mature as wxPython. In any case, there is a wxPython book (Rappin and Dunn), and there is not a wxRuby book, so wxPython wins on those grounds.
posted by evariste at 1:39 AM on September 1, 2006


Python also underlies Zope and Plone (though I've come to the conclusion that these are mainly for pretty large organizations), and is the main scripting langage for that system.

I also happen to find Python just lovely to work in. Of course most of my work is in Perl, but I've worked in other languages (Visual Basic - ugh; Pascal, C, Fortran, whatever) and working in Python just makes me happy; I think it leads to clean beautiful work. And I'm not the sort of person who just gets enthusiastic about whatever's latest.

For learning -- I'd recommend it. My college taught all undergrads Pascal because it was supposed to be a good learning language; I think it may be that Python has a lot of the same qualities.

The mandatory whitespace thing is just another bit of syntax, and replaces {start and end brackets}. It's less clutter to look at and, while confusing spaces with tabs can be a problem, as long as you're aware and consistent (which you should be with any language, since you want your code to read easily), it can be a blessing.
posted by amtho at 3:19 AM on September 1, 2006


Again I say: trendiness seems a reason to _avoid_ a language. Who knows how useful a "trendy" language will be in five or ten years? Yes, you'll probably learn other languages by then, but why not start building expertise in something that will last?
posted by amtho at 3:21 AM on September 1, 2006


Again I say: trendiness seems a reason to _avoid_ a language.

Oh please. You could reasonably argue trendiness is not an advantage. However, I cannot see how trendiness can be percieved as a disadvantage. The more trendy a language is, the more books and libraries are written for it. The more books and libaries available, the easier the language is to use.
posted by malp at 6:19 AM on September 1, 2006


Joel answers.
posted by XiBe at 6:21 AM on September 1, 2006


I dunno any Python, but...

From a learning standpoint, Ruby is very easy to read (this is important, as reading and working through code is to programming what reading through briefs is to the law). Indeed it's scarily English-like in places, or can be, depending on convention. Ruby on Rails is, as pointed out above, magical, and in order to learn programming from it you're going to make a number of jumps back and forth between, e.g., code that looks like config files and embedded-Ruby-in-HTML that looks like PHP and so forth.

The comments that have recommended Java are sensible, actually; its rigidity is illustrative and clear rather than obfuscatory (as with C/C++ in my limited experience).

Ruby's main (dis)advantage is not trendiness - that's a stupid backhand and no advice at all. Its advantages as I understand them are its readability, its thorough object-orientedness, and its vibrant community, especially surrounding RAILS, which is elegant and powerful and growing.
5.times print "Hello"
It should be obvious what that does; less obvious but still cool is that the integer 5 is a full-on object, and 'times' is one of its functions. From a readability/elegance perspective alone that's a win. I'm in no position to talk about computational advantages and so forth, but it makes the writing easier and more fun. And people forget how important those things are. I've never enjoyed coding as much as I've enjoyed coding Ruby. It was like learning Scheme. That's my strongest recommendation. But as for learning, I'm unsure. Ditto the above: try _why's Ruby-online tutorial, play around in irb.
posted by waxbanks at 6:43 AM on September 1, 2006


For a first programming language, you want to learn:

1) a language. Flitting between multiple languages is not going to be helpful. Later on you can expand your knowledge.

2) a language that is a bit forgiving

3) a language that will help you learn and help you learn about other languages.

I think you've picked two good choices. Learning something odd (a functional language?) won't be all that useful in the short term and will be so unlike the majority of other langauges that it might hinder you. While Java is popular for teaching 1st year CS, I'm not convinced it's a good langauge to learn in. In my experience, many of those freshmen know how to program in Java, but don't know how to program.

Python certainly has its peculiarities, but I think they are mostly cosmetic. (People should just get over the whitespace / indentation issue. Are braces any less arbitrary?) It also has a lot of material available, including tutorials and free books, is forgiving and teaches you good habits. Ruby wouldn't be a bad choice (at this point, I think it's here to stay), but the opportunities for learning seem better in Python's direction.
posted by outlier at 6:47 AM on September 1, 2006


Agreed on "trendiness" meaning nothing in the context of this discussion.

Disagree on java, not only because its outside the bounds of this question, but also because I think some of you are forgetting what its like to be truly starting with programming. Which is more obvious:
Java:
class HelloWorld {
   public static void main(String[] args) {
        System.out.println("hello from java!");
   } 
}
Ruby:
class HelloWorld
    def helloWorld
         puts "Hello from Ruby"
    end
end

# or even just:
  puts "hello from ruby, no need for a method or class
I believe Python would be very similiar, where you can just define a top level function in any old file.

I've talked with Java instructors who lament having to teach all those keywords to new programmers. There are at least four or five terms needed to teach in Java to learn hello world. Thats a recipe for frustration, not a fun way to learn programming.

Not to mention all the other inconsistencies in Java: "why do I have int and Integer? Oh, and now it doesn't matter in Java 5? why do I have to say String foo = new String("foo") - can't the computer figure out I just want a String? What the hell are generics?" I did Java for five years, and its fine, but its not a good learning language.

Also, Joel's essay today is dumb. Read Teach Yourself Programming in 10 Years Instead.
posted by rsanheim at 7:38 AM on September 1, 2006


People should just get over the whitespace / indentation issue. Are braces any less arbitrary?

One of Python's claimed design principles is "explicit is better than implicit." And explicit end-blocks are better than implicit end-blocks. They mean that your editor or a tidy program can auto-indent and do the right thing. It means you can cut and paste code from elsewhere, and have your editor indent it appropriately automatically, even if you lost a little whitespace at the beginning.

With Python, your editor can guess, and you have to correct it by hand. Number of times you have to tell your editor where a given block ends in a language with explicit end-blocks: 1. Number of times you have to do it in Python: potentially unlimited, depending on where you're adding code. (Last time I said this in AskMe, people dismissively said that Python editors' auto-indenting "just worked". It just doesn't, not for any value of "work" that applies to a language with explicit end-blocks -- it can't.)

It's a persistent minor pain in the ass that doesn't buy you anything but bragging rights about how little your language resembles C or Perl or Java, and a handful of extra lines of code on a given page or screen.

Python isn't a bad language, and will generally make you want to claw your eyes out less than most languages. But it makes me do work that my editor could and should be doing, and that's a bug.
posted by Zed_Lopez at 9:41 AM on September 1, 2006


Response by poster: Thank you all for your answers! I've not made a choice yet, but I think I'll visit some of those links etc, and print this page out to give it a thorough read. Most of this stuff I had no idea about, so it's all really helpful.
posted by djgh at 10:37 AM on September 1, 2006


I don't think you can really go wrong with either choice, but after having experimented with both on small apps over the last year, I like Ruby more. Or rather, I like Ruby's *syntax* more. It's true that it's more varied, but I find it to be more expressive. Ruby's libraries, while not bad, seem a bit less mature and filled out than Python's. There are a few project domains for which I'd go with Python in a minute just because of some good libraries.

Ruby still has some ugliness left over from Perl.

But also, a good bit of the convenience. I'm finding Ruby to be many of the things I loved about Perl, and few of the things that have driven me bonkers.

"Plus I've heard it's very difficult to write good code with PHP."

I think it's more accurate to say that it's easy to write poor code in PHP, and most of the PHP-related training material and community sites will probably encourage you. It's really not difficult to write good code once you know how to do it, just harder to find stuff that will encourage you to do this in the sea of crap.

Perhaps instead of a procedural language, you might try a functional langauge?

Like Excel. :)
posted by weston at 10:41 AM on September 1, 2006


I use a fair bit of both Ruby and Python myself, and I'd say the differences between them are so small that you'd be fine deciding by just flipping a coin. They're both great languages to get your first taste of programming with.

For my own stuff, I generally prefer Ruby, as it has one particular feature (blocks) that really suits my coding style. Python, however, feels much cleaner and more consistent, both in its syntax (more words and fewer symbols) and conceptually, and has a better set of standard libraries. Personally, I think this would make it slightly better as a first language, but, as I say, either one would be a great choice.

After you learn one of them, don't bother learning the other right away. You'll have no trouble picking it up when you need it, and you'll learn a lot more by going for something that's very different from your first language. C might be a good choice: Python and Ruby are easy to learn because they're so high-level, but C will help you understand more about what's going on inside the machine. Lisp, OCaml, and Eiffel are also good mind-expandy languages.
posted by moss at 11:20 AM on September 1, 2006


I'd just like to quickly address a couple of points made about Java above:

There are at least four or five terms needed to teach in Java to learn hello world.

And each of those four or five things are important, so you should learn about them. No, it's not necessarily "fun", but if you want to know what you're doing (or more importantly, what the computer is doing) you need to be able to understand how it uses resources. Java and C++ are excellent languages for this: they force you to understand how the computer works, instead of Ruby "black box" methods.

Not to mention all the other inconsistencies in Java: "why do I have int and Integer? Oh, and now it doesn't matter in Java 5?

There were a lot of things people complained about, myself included, and the language has grown to accept these criticisms and changed as a result. Why is there int and Integer? Because one is a mutable primitive, the other is an Object. "So what!" you cry. Well, an int is faster and uses less resources. Which may or may not matter to you. An Integer is an object with built-in methods (pretty boring ones, however--mostly conversion to other types). Depending on what you want, you can choose the different types for optimal speed or optimal extendability. You have a choice in the matter.

why do I have to say String foo = new String("foo") - can't the computer figure out I just want a String?

Sure.

String s = "Hello world.";

How hard is that?

What the hell are generics?"

Aww, man, I love generics. Generics allow you to avoid all the type casting ugliness of Java by providing a generic interface. For example:

List custList = getAListOfWhateverDao(some, parameters, here);

This returns a list, but a list of what exactly? Well, regular Java would just say, "a list of Objects" and leave it at that. Well great. But what if I know beforehand that they're going to be a list of Customer objects? Then I could perform public methods on the items of the list!

For instance, let's say my Customer class has a method called showLastFiveTrx() which gives you the last 5 transactions a Customer made. With the list you see above, I get a bunch of random no-name objects back. I'd have to cast them as Customers if I wanted to use that function, and then I run the risk of ClassCastExceptions. Instead, if I knew I was getting back a list of Customers, I could do this:

List<Customer> custList = getAListOfWhateverDao(some, parameters, here);

Now, I can iterate through the list and access the Object's methods directly:

for (Customer c: l) { // Notice the newer, cleaner for loops?
  c.showLastFiveTrx();
  ...
}

No casting required.
posted by Civil_Disobedient at 9:51 PM on September 1, 2006


Ooops, that last bit 'o psuedo-code should be:

for (Customer c: custList) // Notice the newer, cleaner for loops?
  c.showLastFiveTrx();
  ...
}

That'll teach me to change variable names while writing a response.
posted by Civil_Disobedient at 9:54 PM on September 1, 2006


Civil: I wasn't actually asking those questions - I meant those would be likely a questions someone completely new to programming would ask. Like, uh, the original poster?

I worked full time with Java for over five years and did open source in my spare time, so I know more then I want to about Java's quirks. My point is that its a _horrible_ first language because of all those quirks. For an into to programming class, you want to teach the absolute basics. Things like objects, indirection, and message passing. Not method visibility, static vs instance methods, primitive types versus objects, etc. Java has so much cruft bolted on over the years, and its only getting worse, with closures being added on for version 7. They are trying to keep up with C# and more dynamic languages, but Java has ten years of history to constantly fight against.

Re: generics. Generics are fine and good in the simple cases, but are horrible when you look at the edge cases and get really complex. How about this, right from the api for 5.0:
Class Enum<E extends Enum<E>>
Explain that to a first year student. Also worth reading: Generics Considered Harmful. Or go read Bruce Eckel on generics, the author of _Thinking in Java_. His experience with trying to write about generics for 5 is illuminating.

I agree that new programmers should eventually learn what is going on closer to the metal, wrt memory, stack, heap, pointers, etc. I'd argue thats better learned with C then Java, but only after at least a year of a higher level language like Ruby or Python.
posted by rsanheim at 6:56 AM on September 2, 2006


On all points, agreed.
posted by Civil_Disobedient at 10:35 AM on September 2, 2006


« Older Relearning romance   |   What should I expect? Newer »
This thread is closed to new comments.