Settings

Theme

Can anyone explain why Ruby is so popular?

16 points by xkcdfanboy 13 years ago · 45 comments · 1 min read


It seems to me like a hybrid of python with perl. It does a ton of things and from what I've heard, it's slow as molasses because of all of the metaprogramming syntax that's built in. RubyMotion allows you to build iOS apps in Ruby. It doesn't seem like other languages get the attention that ruby does. It feels like a scripting language but gets the attention of a compiled one, I don't get it. Is it becoming the first programming language that some people learn? It's actually about the only language I don't know (and I know x86 asm, C, PHP, ObjC++, Python, Perl, C#, you name it.) Thanks in advance.

mjhea0 13 years ago

Ruby is popular because of Rails. If you're not going to use Rails, I don't see much reason to learn Ruby as in my opinion Python is easier to learn and is applicable to so much more than Ruby.

That said, I agree that the syntax did feel like a hybrid of Python and Perl (with a bit of crack mixed in) - but once I started playing around with it, I really started to appreciate the syntax.

  • caw 13 years ago

    >syntax did feel like a hybrid of Python and Perl (with a bit of crack mixed in)

    My personal feeling is that it's mostly Smalltalk and Perl, and less Python, though technically wikipedia says it inherits from Python as well. I've coded Perl and Smalltalk though, but not ever really Python. Maybe if you look at it that way there's less crack mixed in.

  • rman666 13 years ago

    Why do you say Python is applicable to so much more than Ruby? I don't see how this can possibly be true since they are both powerful scripting languages.

    • lost-theory 13 years ago

      They are both powerful scripting languages, but I think the ruby community suffers from a monoculture around rails & web development. Python also has a strong emphasis on web development (django, flask, pyramid), but there are also large communities of people doing scientific / numeric computing (scipy, numpy), bioinformatics (biopython), games (pygame, pyglet), networking (twisted), education (MIT's 6.00 course), embedded stuff / robotics, etc.

    • rkda 13 years ago

      It depends on your field, I guess. Scientific computing for example uses a lot of Python. Ditto for the geospatial field where both the proprietary packages and the open source ones use Python. Sometimes, it's not the language's power that matters but the field of application and the existing libraries and community.

    • bigd 13 years ago

      Python is much more complete when it comes to math and science.

  • jgoldschrafe 13 years ago

    Rails is a big part of Ruby's popularity, but let's not forget the impact of Chef and Puppet as well.

spoiler 13 years ago

I love Ruby's syntax. I tries Python, but I didn't like it as much as Ruby, what putt me off about python is the meaningful indentation (although I do not mind that in CoffeeScript). Also, Ruby itself is not slow, but CRuby (MRI, YARV, whatever you call it) is slow; Rubinius ("rbx") is a wonderful (and my personal favourite) alternative for MRI. In fact, I use rbx and EventMachine for a fun app that has a growing number of users! However, when I found some things were too slow in Ruby I just wrote a C extension (yes, yes, I know it's a bit of a controversy).

As to why I learnt it: it looked fun, and I was right, Ruby brings me pleasure!

  • csense 13 years ago

    You should give Python another chance. Here's why:

    > meaningful indentation

    Indentation in other languages has meaning too. If you have Java code, for example, that looks like this:

       public static boolean isIncreasing(int a[])
       {
          boolean result = true;
          for(int i=1;i<a.length;i++)
             if (a[i-1] <= a[i])
                continue;
             else
                System.out.println("a is not monotonically increasing");
                result = false;
          return result;
       }
    
    Can you spot the bug? The topic we're discussing is a huge hint as to what the bug is, but if the only clue you have is bad behavior in a longer program it can be much harder to spot. When skimming the code, the visual cue of the indentation is so strong that it's very easy for your brain to see what the programmer clearly intended to write rather than what's actually there. (The diagnosis of the above bug might be even hairier if the bug was introduced by inserting a "safe" print statement to help you debug an unrelated problem!)

    Forcing your code's visual cues and behavior to match defeats an entire class of bugs. And even if you start out hating it, ultimately it's like the required semicolons in C/C++/Java: It's an annoyance at first, but after a while it becomes so automatic that you no longer stop to think about it.

    • gordaco 13 years ago

      Sorry, but the "bug" is that someone doesn't know well the language's syntax and/or has spent too much time with braceless languages and tries to put as less braces as possible because of their personal preferences, resulting in a wrong block structure.

      Maybe I'm just different than you, but I immediately notice the missing braces. Actually, the visual cues I look for (even when skimming the code) are the braces, not the indentation; especially, the missing closing brace at the end of the block alerts me. The indentation is a plus, an added redundancy.

      Moral of the story: not everyone reads code the same way.

  • read 13 years ago

    Can you elaborate on what put you off Python's indentation?

    • throwit1979 13 years ago

      Not the OP, but meaningful whitespace is an abomination unto the world.

      It's difficult to elaborate on something that is a matter of taste, but some of us need our code blocks visually bookended.

    • spoiler 13 years ago

      When reading Python at anything over 3 levels of indentation I had to use a ruler to know what level I am currently in. Or similar, when there was multiple lines between two blocks or commands This was before I started using sublime text and I was very new to programming, also never tried Python in ST, to be fair! I mostly missed that visual cue where the block ends, I suppose.

Skoofoo 13 years ago

"I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language." -Matz

Ruby and its ecosystem revolves around your happiness and productivity. Isn't that great?

  • dylangs1030 13 years ago

    I think most languages set out to achieve this. It's not a real answer.

    For the record, Ruby is a great language, but a better argument for it would be syntactical analysis or talking about features.

    If Guido had this awesome quote about his goals for Python, it wouldn't make Python a cool language automatically.

adrianlmm 13 years ago

I personally love the syntax, and in my own experience is not that slow, I use it with Sinatra and my productivity is huge.

I'm also a C# and Delphi developer. I learned Ruby cause I had the need the learn an scripting language, and the reason to not learn python was that it looks like it is stock for ever in the 2.7 version, so I chose Ruby and I'm very pleased with my decision.

  • rman666 13 years ago

    +1for Sinatra!

  • xkcdfanboyOP 13 years ago

    It's interesting that the two responses on here (yours included) so far mention that it was learned for scripting. The main reason I made the initial post is because I see it being used for much more than just scripting, ie. rails and ruby motion. It seems somewhat naive to use a scripting language in leui of a real language when coding something industrial. So I still am at a loss... Thank you for your comment, yeah it does seem a lot more powerful than Python. I am not a fan of python's requirement of object methods requiring the self arg, dastardly!

    • zachlatta 13 years ago

      Scripting languages are "real" languages. Also, RubyMotion projects are compiled down to machine code, not interpreted.

    • csense 13 years ago

      > python's requirement of object methods requiring the self arg

      I originally hated it too, but it's grown on me. I've come to the conclusion that it's good to have that explicit signal that something is a member variable rather than a local. And I've started adding explicit "this." to member variables in all my Java programs.

    • dpritchett 13 years ago

      Rails helps minimize time to market. Any sizeable Rails app that gets market traction is likely to have its hotspots revisited and broken out into services. The services need not use Ruby at all.

      Edit: Ruby itself is just a language. If you're not building web apps or server scripts there's no particular reason to prefer it.

    • websitescenes 13 years ago

      You can make iPhone apps with anything you want. You can even use plain html5 and js. There are many, many options to utilize your preferred language in app development. It's definitely not just Ruby.

jneen 13 years ago

Metaprogramming syntax isn't built in to ruby. Instead, it's really internally consistent and lets you leave out a few tokens, which means it's really easy to write libraries with beautiful interfaces.

The built-in features usually try to solve the general case, rather than focusing on specific use-cases. For example, in python you have iterators, which make it easy to have a block of code that is run multiple times with different bindings. In Ruby, you have block syntax, which solves the more general problem of "let me pass this anonymous block of code to this function", and they built iterators on top of that.

csense 13 years ago

I'm interested in the answers to these questions:

1. What does Rails do that Django doesn't? (Feel free to substitute any other Web framework for Django if you think it'll help your answer be more illustrative.)

2. Why hasn't the Python community seen whatever Ruby's doing and copied whatever makes Ruby popular? Are there any Python/Ruby experts reading this who are willing to port or reimplement the good parts of Ruby in Python?

3. Are there any other reasons to prefer Ruby over Python besides Rails? For example, do Gems do things that are impossible with Pip?

  • chc 13 years ago

    > 1. What does Rails do that Django doesn't?

    The answer is, basically, "Have a larger ecosystem without being Java." There are a few things each has by default that the other doesn't, but by and large I don't think people pick Rails because it has 8 million features and Django only has 7.95 million.

    > 2. Why hasn't the Python community seen whatever Ruby's doing and copied whatever makes Ruby popular? Are there any Python/Ruby experts reading this who are willing to port or reimplement the good parts of Ruby in Python?

    Just about anything worthwhile already has an equivalent. The reason Ruby is popular is not really about features. Ruby is popular because Ruby managed to capture people's imagination. When the new generation of webdev was first coming around in the mid-2000s, Ruby had a huge burst of enthusiasm. Everybody was enamored with Ruby on Rails, and Ruby itself had lots of fanatical evangelists like Why who were eager to teach people. Python, ironically, was hampered by the fact that it was more mature and thus it was harder to get people excited about it. Additionally, Rails was the killer app for Ruby, while Python took a relatively long time to put out a comparable product. I don't remember if Django existed, but there certainly wasn't the situation you have today where Django is basically the "Python Rails" and they're seen as being on roughly equal footing. Instead, Pythonistas were all talking about how you should take Twisted and twelve other libraries and you just write all this glue code and then it's sort of like Rails if you squint really hard — and nobody really found that exciting either.

    This isn't to say that Ruby doesn't have actual benefits to recommend it. Rails is a very nice, mature environment for web development, and Ruby as a whole has a very nice ecosystem these days. But the reason it got where it is is because Ruby won people over eight years ago, and it's gotten where it is today from that momentum. It isn't that Ruby is miles ahead and Python is simply inferior, but that Ruby just got a head start in that field and inertia matters a lot.

    > 3. Are there any other reasons to prefer Ruby over Python besides Rails? For example, do Gems do things that are impossible with Pip?

    The culture of the two languages is sort of different. Python invariably loves explicitness. Ruby isn't as crazy infatuated with "magic" as it used to be, but it's still much more acceptable over there to do weird tricks that let you write code the way you want to (e.g. "this magically executes in a context with functions that aren't available elsewhere") instead of the old-fashioned way. A lot of people prefer the latter, so they like Ruby. A lot of other people hate that kind of code, and they will be much happier using Python.

    • csense 13 years ago

      > Python took a relatively long time to put out a comparable product. I don't remember if Django existed, but there certainly wasn't the situation you have today where Django is basically the "Python Rails" and they're seen as being on roughly equal footing. Instead, Pythonistas were all talking about how you should take Twisted and twelve other libraries and you just write all this glue code and then it's sort of like Rails if you squint really hard — and nobody really found that exciting either.

      This is the most informative part of your comment. I came to Python around version 2.6, and Django was already pretty near its modern form. I also first started hearing about Rails at that time, so my perception was "Python has always had Django, and Rails is a new thing." If Rails is older than Django, that explains much.

      > Python invariably loves explicitness

      Before I used Python, Java and C were my main languages. I was amazed at how short programs became in Python. For this reason, saying "Python loves explicitness" strikes me as strange, since it gets rid of braces, semicolons, variable declarations, the 'new' operator...

      > A lot of other people hate that kind of code, and they will be much happier using Python.

      This is totally me. I've ranted elsewhere in this thread about Ruby's syntax. Maybe some clever person will write a Python-to-Ruby translator someday so you can use Rails without having to deal with Ruby syntax.

      > inertia matters a lot

      I'm just a little surprised the momentum isn't swinging back to Python. Since IMHO Ruby's syntax makes the language...very undesirable, and if I was forced to use it to take advantage of tools that only exist in Ruby-land, I'd be looking to switch back to Python as soon as the tools were ported -- and even devote effort to helping with ports.

      Everybody was excited about Perl in the beginning, but very few people still code in Perl these days. I think Ruby suffers from similar problems and will eventually be eaten by Python.

      • chc 13 years ago

        > Before I used Python, Java and C were my main languages. I was amazed at how short programs became in Python. For this reason, saying "Python loves explicitness" strikes me as strange, since it gets rid of braces, semicolons, variable declarations, the 'new' operator...

        I think you have confused "explicitness" with "verbosity." Indentation is no less explicit than braces.

        > I'm just a little surprised the momentum isn't swinging back to Python. Since IMHO Ruby's syntax makes the language...very undesirable

        That is very much a YMMV sort of thing. A lot of people actually like the Ruby syntax because they find the greater flexibility and ability to define pseudo-DSLs to be pleasant.

      • Mithaldu 13 years ago

        > very few people still code in Perl these days

        Please try to separate your beliefs from facts.

        http://www.indeed.com/jobtrends?q=perl%2C+python%2C+ruby%2C+...

  • spoiler 13 years ago

    I don't know about the first question, but:

    2) Because Python would become Ruby, or at least Pubython, then. What attracts most people to Ruby is its humanist syntax, not sure what Pythons guiding philosophy behind the syntax is, but I tried both and ruby was just a lot better.

    3) There is loads of little things that are just personal preference for me, but the choice of language always boils down to personal preference one way or the other! Never really tried Pip, so I can't answer.

    • csense 13 years ago

      > Pythons guiding philosophy behind the syntax

      Python's syntax philosophy in a nutshell: The more your program looks like line noise, the harder it is to read. Operators should be simple and minimal, operations like list comprehension should match existing usage in English, mathematics, or C.

      > ruby was just a lot better

      Here's a Ruby snippet. I don't want to pick on this particular project [1], rather, I've found that this is typical of Ruby code:

        state_machine :state, initial: :active do
          after_transition any => :blocked do |user, transition|
            # Remove user from all projects and
            user.users_projects.find_each do |membership|
              return false unless membership.destroy
            end
          end
      
      Wow. There are colons, absolute value bars, implications, and who-knows-what-else flying everywhere! It gets worse, elsewhere in the same file there are messy lines like this one with single-arrow implications, question marks and ampersands [2]:

        scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : scoped }
      
      Simple, intuitive syntax? From where I sit, the syntax of Ruby is worse than C++, and approaches Perl levels of awfulness.

      In most languages, I can at least sort-of grok what's going on from the context when I see unfamiliar operators, but not so in Ruby.

      [1] https://github.com/gitlabhq/gitlabhq/blob/4caaea824cf51670d1...

      [2] https://github.com/gitlabhq/gitlabhq/blob/4caaea824cf51670d1...

      • chc 13 years ago

        "Implications"? Is that a weird word for a block or what?

        • groue 13 years ago

          He/she means that `=>` looks like a mathematical implication, just like `|...|` looks like absolute value bars.

  • haney 13 years ago

    For #1 everything I've seen points to rails and Django having a nearly 1 to 1 correspondence. It's just preference for the most part.

    • squidsoup 13 years ago

      It really doesn't - Rails comes with a lot of things that Django does not by default. Off the top of my head, Django does not come with database migrations, environment based configuration or an asset pipeline. You can add those things to Django, but you need to either use a 3rd party library or roll it yourself. I believe Django database migrations are coming, based on South, but if they'll land in 1.6 I don't know.

tudorconstantin 13 years ago

I am a perl dev for almost 3 years and i learned it at my job after i tried ruby and python.

For more than a year i felt i should have chosen ruby because of how intuitive it feels: you read the code always from left to right, whereas in perl you often either go from right to left or from the center of the line outward. Besides that, fuby also has that principle of less surprise.

However, after I got accustomed with perl, i started to love its expressiveness and flexibility. And now, I almost got to love the "there's more than one way to do it" mantra. Regarding Python, I see it more close to Perl from a readingness perspective, but with much less flexibility embedded.

  • lsiebert 13 years ago

    I know perl (among others) which I really like, but I feel like I have to learn python or ruby to be competitive.

    • Mithaldu 13 years ago
      • lsiebert 13 years ago

        Maybe so, but the who's hiring page from May has zero mentions of perl, and quite a few of python and ruby. If there is a good internship for a perl hacker in the Bay Area, I haven't seen it.

        I got to meet Larry Wall, (was nice enough to come and talk to my class) and even he seems to have had trouble finding work during his career.

        Actually, from your comment history, you seem like a perl aficionado. Maybe you could email me and let me know where I should be looking. I'd email you, but you have no contact info supplied.

meerita 13 years ago

As designer who's learning to code, I find Ruby code more easy to learn and read. Other programs are too, let's say, cryptic syntax. And for the projects I am working for I don't need to work with another programming language.

If you let me chose, I would go all the way with Erlang or Go, but it's hard to learn for a non-coder.

ksherlock 13 years ago

When I gave up on perl, I considered other scripting languages and it turned out that ruby was the best match for my programming style. I think ruby users and ruby on rails give it a bad name, though :)

nayefc 13 years ago

Ruby is just beautiful. I learnt Python and Ruby last year, and even though they're both really good, I find Ruby's syntax hard to resist.

Metaprogramming is also great (others have commented about that)

chrisgw 13 years ago

I learned Ruby because of Rails.

If I need a scripting language, I prefer Ruby because I know it the best now. I'm pretty good at Python, but feel more comfortable in Ruby because I use it more often.

wgla 13 years ago

One word: Rails.

websitescenes 13 years ago

Thanks for what? Sounds like your opinion is made up. Still trying to figure out if this is a question. I like Ruby about as much as PHP; I think it's more about what you build on the language or what framework you use.

  • websitescenes 13 years ago

    Lol, I put in my true opinion and constantly get down voted. Seems like people would rather debate nonsensical things than face the truth. The original post deserved the response it got from me and I will continue to call it how I see it. If you want a real discussion then ask a real question. You didn't even say what you are trying to do. Web apps? Desktop programs? The op is trying to compare languages that are not even in the same domains. I like all the languages you listed and think they have their place. Not sure why you are comparing them to Ruby though.. I like Ruby mostly because of Rails but have been playing with laravel. PHP is faster sometimes but so is Ruby if you know how to program. Down vote me again haters. I'm starting to get off on it.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection