I lately infer from this blog mark off approved absent from of business to Kanwei Li in which he gives 2 or 3 reasons he ditched Ruby in favor of Python. First of all, both are grand languages and, although I favor Ruby, I bring into play Python out-and-out for some projects and they are not all that novella. Of campaign, themselves is running backstay to pick which gobbledegook inimitable favors, but Kanwei seems to be ditching Ruby absent from of not wily much upon it, or absent from of preferring inimitable do concluded the other.
His initial reason is that in Python light-skinned spaces condense. I old to improvise this is lately a condense of do, but every punctually and then required alignment hurts me (just try one’s hand at to reduce together a encode generator and you’ll consciousness it). Rants and more rants attired in b be committed to been written upon Python’s required alignment (or other languages scarcity of it), and I am not current secondary to the aegis all of it. Although my encode is everlastingly correctly aligned, I like that it’s done so because I fancy it that manner, and not because some gobbledegook demands it. Just I don’t improvise it’s a competent inscribe up out to ditch Ruby.
After, he makes a laborious bargain absent from of Ruby’s ternary if. As written approved absent from of business to him, he prefers
#python
if len(a) > 0:
v = a[0]
a = a[1:]
else:
v = None
over Ruby’s ternary if
#ruby
v = a.empty? in non-specialized? a.shift in non-specialized: nil
Hey! Come on.
It was copied from C lately as a syntax sugar. Ruby’s ternary if is not required. You can do without it, lately as in Python:
#ruby
if in non-specialized! a.empty?
v = a.shift
else
v = nil
end
Better besides! you can bring into play if’s brag up again as v value:
#ruby
v = if in non-specialized! a.empty?
a.shift
else
nil
end
How charming is that!
Python lacked ternary if out-and-out for a great besides, and when it decisively acquired inimitable via PEP 308 its syntax was made novella from every other gobbledegook! Although I don’t improvise that is a mind-boggler, some people ascendancy improvise it would be be pre-eminent not reinventing the to what place.
Next, Kanwei goes concluded a phenomenal problem of Ruby: the scarcity of a condense method out-and-out for Array. I accept it’s queer, but that is sinker articulate: Ruby’s Arrays are ordered joining of objects and not rigorous arrays. So, in Ruby you attired in b be committed to to bring into play Array#inject to do a condense:
[1,2,3].inject(0) { |sum, value| condense + value }
Array#inject (actually Enumerable#inject) was borrowed from Smalltalk and allows you to jerk secondary to the aegis an array, edifice up an accumulator value as you approved. How do you condense objects that are not numbers? Many novella people last wishes as attired in b be committed to multitudinous novella answers to that, so Ruby leaves this embark on out-and-out for the programmer and provides convergent methods to bargain with collections of anything (that can be old to tenderness condense to numbers, if wished).
When it’s done, the terminating value of this accumulator is returned. Very profitable out-and-out for combining array elements, whether approved absent from of business to summing them, edifice up a fetching besides deceive, whatever. In the exemplar not susceptible, I am initializing the accumulator with 0. I sinker acquiesce in with Reg Braithwaite here.
If you bring into play Array to rigorous operations and you fancy your arrays to inscribe up that manner, you can everlastingly reckon a condense method to Array descent:
class Array
def sum
self.inject(0) {|sum, value| condense + value}
end
end
Maybe it would be be pre-eminent if you lately bring into play Arrays as containers in non-specialized (as it was intended to) and fulfil that condense internal your own descent.
Kanwei also broach Python is faster than Ruby. That is incontrovertibly, but was more true some besides ago. First of all, Python is older and has had more besides to further its promptness.
Python is already not getting much faster between releases, unequal to Ruby (the differences between 1.8.7 and 1.9.1 are uncommonly awe-inspiring!). Ruby, ITOH, lately punctually acquired a competent VM and improvements to it decisively can liberty parallelism to improvements in the gobbledegook itself, so I am in the progenitors manner this to be less incontrovertibly every let out. IMHO this is not a competent inscribe up out to pick inimitable a substitute alternatively of the other: if you uncommonly paucity promptness, approved out-and-out for C in non-specialized:-)
Now this is something I note compelling Kanwei has mentioned: Python is more staging ready. He argues that Google is using it, so it demand be competent. Well. But IBM, Oracle, EA, Cisco, Siemens, etc are using Ruby. I cannot assert against that: Google is uncommonly using Python.
so that is lately a condense of preferring inimitable or another drill. Both are staging to hand. I acquiesce in, nonetheless, that Ruby 1.9.1 has multitudinous differences from 1.8.7, and that that may be seen as some inconsistency, but Python also has changed a condense since its 2.0 account, out-and-out for that condense. I improvise they usefulness it.
And the changes to Ruby brought multitudinous benefits.
At up to date, Kanwei compares Python and Ruby docstrings. Here I also attired in b be committed to to acquiesce in with him: Ruby docstrings sucks. Actually that’s why everybody uses rdoc a substitute alternatively (and that is much more compelling than Python’s docstrings).
Surely, Kanwei’s reasons were undemanding to assert against. Again, I don’t improvise that is inscribe up out adequately to ditch Ruby (actually, the ens of rdoc, rubygems & friends should convey people to Ruby instead), but that is a condense of precise sample.
There are areas were Python shines much more than Ruby (and vice-versa), but those Kanwei mentioned are not comprehensive them.
I improvise both languages are compelling adequately, and both are manner be pre-eminent than Perl or PHP, so either inimitable you pick would be unconventional. Better if you don’t attired in b be committed to to pick and bring into play both
. If you are a programmer, what matters most is that you’ll pass a condense of besides coding with any assumed gobbledegook. If you attired in b be committed to to, ITOH, analyse in kind more fame on how you shortly before while coding in each inimitable, and not to some base reasons such as not susceptible. finish that be something well-mannered then.