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.
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.
As to why I learnt it: it looked fun, and I was right, Ruby brings me pleasure!
> 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.
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.
It's difficult to elaborate on something that is a matter of taste, but some of us need our code blocks visually bookended.
Ruby and its ecosystem revolves around your happiness and productivity. Isn't that great?
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.
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.
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.
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.
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.
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?
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.
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.
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.
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...
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.
http://www.indeed.com/jobtrends?q=perl%2C+python%2C+ruby%2C+...
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.
Metaprogramming is also great (others have commented about that)
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.