TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Why Python over Ruby?

87 点作者 costan将近 16 年前
I would like to understand why Python is so much more popular than Ruby. Much of the software I've seen supports Python for scripting (e.g. Miro, OpenMoko, XBMC/Boxee), and people don't seem to care so much for Ruby. At the same time, people agree that Ruby is great for writing DSLs.<p>I don't want a flame war or religious arguments. I would like to understand what made Python win in this space. Thanks so much for commenting!

41 条评论

zach将近 16 年前
Ruby has clever syntax. Python has pure syntax.<p>Ruby has method aliases. Python does not allow a string to capitalize itself.<p>Ruby uses Ruby methods within Ruby classes to extend Ruby. Python has decorators so you can write functions that return functions that return functions to create a new function.<p>Ruby has strict object-oriented encapsulation. Python is laid-back about objects, because you probably know what's going on inside them anyway.<p>Ruby lets you leave off parentheses so you don't miss objects having attributes too much. Python will let you mix tabs and spaces for indentation, but passive-aggressively mess up your scoping as punishment.<p>Ruby has seven kinds of closures. Python has one, in the unlikely case a list comprehension won't do.<p>Ruby's C implementation is a mess of support for language-level flexibility. Python's C implementation is so clean you get the unsettling thought that you could probably write Python using C macros.<p>Ruby supports metaprogramming for cases when programmers find it more descriptive. Python supports metaprogramming for cases when programmers find it necessary.<p>Ruby is expressive. Python is direct.<p>Ruby is English. Python is Esperanto.<p>Ruby is verse. Python is prose.<p>Ruby is beautiful. Python is useful.<p>I like Python, but coming to it after using Ruby for seven years, well, I think it's like dog people and cat people. You can like having one species around, but you're always thinking -- why they can't be more like the other?
评论 #683365 未加载
评论 #683064 未加载
评论 #682374 未加载
评论 #682466 未加载
paulgb将近 16 年前
Ruby is slightly newer and wasn't particularly popular in the United States until it was popularized by Rails.<p>Python became popular with Linux and open source developers before Ruby did, and has had slightly more time to develop a nice set of libraries to do just about anything.
评论 #682393 未加载
knowtheory将近 16 年前
What's clear to me reading the comments in this thread, is that there are a lot of people who like Python, and don't understand what people appreciate in Ruby.<p>None of these are reasons why people choose Python over Ruby. Or why Python has become more popular. It is worth noting that Python was also mentioned a lot as a teaching tool when its popularity began ramping up, and some universities have replaced Java and Scheme with Python as an introductory language.<p>Python really is not appreciably better than Ruby, in my experience. Nor will i claim that Ruby is appreciably better than Python. I personally use Ruby in daily life, and used to use Python prior to discovering Ruby. Both languages support some really weird warts, inconsistencies, and baggage that they retain for the sake of backwards compatibility.<p>Instead they really do provide different philosophies on life. To claim that Ruby is a tangled soup of options and syntactic sugar is to miss the point really. Nor is Ruby is not trying to be all things to all people. Matz cares about one thing, and that's the ability to let programmers get work done with as few cognitive hurdles sourced from the programming language itself. Does that mean you have options? Yes. Does that mean that it would be better to only have one way to do everything? Not necessarily.
评论 #682672 未加载
tdavis将近 16 年前
Python is far more mature, isn't a strange ad-hoc combination of other languages, has a third-party library to do anything and everything (which is probably also reasonably mature), and doesn't have a community rife with arrogant children.<p>I'm generalizing to some extent, of course, but these are the things that I and other developers I know associate with Ruby (including many who's startups are built on it). I imagine as the language and community grow and mature they will shed these associations and hopefully create a language worth taking seriously. They haven't done that yet (strictly in my opinion).
评论 #682283 未加载
评论 #682616 未加载
评论 #682342 未加载
评论 #683191 未加载
评论 #682258 未加载
CyberFonic将近 16 年前
For me it's very simple !<p>I can READ other people's Python code with greater ease than Ruby, Java, C#, C++ or even C. At the end of the day, the quicker I can assimilate library code the quicker I can use it well and the quicker the module gets completed and fully tested. Of course, with Google and Eric Raymond raving about it, the confidence factor increased further.
评论 #682348 未加载
Bjoern将近 16 年前
Why language X is better of Y makes no sense. Every language has its benefits and downsides. Python has been slighly longer around and has a bigger user community which resulted in more available library code. Ruby and Python is pretty much interchangable in the sense of features as they often steal from each other and vice versa.<p>Ruby<p>- follows TIMTOWTDI<p>- Mutable strings etc.<p>- has a greater emphasis on code generation ("meta")<p>- VM's are much slower than Python (there is no Psycho etc.)<p>- emphasizes code clearity and readabiliy (human cycles are more important)<p>- Libraries are much less mature<p>- ...<p>The lists of differences could go on forever. A comparsion and "why" is difficult. I think they are too similar and the people are too polarized.<p>A language is a tool to solve a particular problem. In the case of Python you have higher momentum of the community and the switch from C/C++/Java to Python is often easier than to Ruby. (Wild statement of me with tests from a sample set of 2 test subjects ;) )<p>Probably the best characterization I can come up with is. Python is already on this "Enterprise" trip where companies use it a lot and so forth. Ruby has some interesting companies pushing it (Twitter etc.) but is not compeletely there yet, it still has more "hacker" and "monkeypatch" feeling. Oh wait, we call that "ninjapatching" in Ruby ;)
评论 #682361 未加载
评论 #682302 未加载
评论 #682379 未加载
bdr将近 16 年前
I prefer the design of Python over Ruby. I'd be hard pressed to explain why -- something vague about Python being straightforward yet graceful -- but that aesthetic preference is enough to sway me.
评论 #682395 未加载
ghshephard将近 16 年前
Speaking purely for myself, the only reason I switched from Perl to Python is I had a great deal of difficulty understanding the perl code (because I'm a poor perl scripter) I wrote after a day or so. That, and the language construct HashOfArrays and ArrayOfHashes is exceedingly difficult to do in perl without referencing a manual. The only (Edit: Alternative scripting) language really out there with mindshare in 2001 was Python. I was able to read my python code. I never had to look at a manual to implement complex data structures. As a bonus, I can type "help(command) or dir(command) within the python CLI. I've never really had the need to switch to another environment. Ruby might actually be 10x better and faster for my typical tasks than python for all I know.
GeneralMaximus将近 16 年前
From the Python website:<p>"Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language."<p>When I first saw this, I went "Google? Whoa. I gotta check this out" :)
评论 #682883 未加载
评论 #682720 未加载
评论 #682602 未加载
bcl将近 16 年前
I haven't really looked at Ruby that hard, but from my perspective as a reformed Perl user I found Python's syntax to be very clean and well organized. On the surface ruby looks more Perl-like to me, more clutter, not as easy to read as Python.<p>Having found Python, I really don't feel a pressing need to learn another scripting language. Instead I'm working on Objective C.
评论 #682204 未加载
评论 #682376 未加载
xenophanes将近 16 年前
Python is older, and gained popularity before ruby. That's why it's more established outside of the web development frameworks space.
评论 #682252 未加载
ntoshev将近 16 年前
Personally I like generators, generator expressions and list comprehensions much more than the Ruby equivalents (chaining each/filter/etc). Python is cleaner overall, and if you want metaprogramming you can still do a lot of it. Also Python has better libraries and runs on App Engine.
评论 #682386 未加载
davidw将近 16 年前
Python got popular earlier - it was already gaining significant converts in the early part of this millennium, and the later years of the last one. Ruby only really took off when Rails started to get popular. But it has <i>really</i> taken off, in a way that I think sometimes makes the Python guys (who have been slowly and steadily gaining ground) a bit jealous.<p>They're both good languages with good communities though. Each has a few advantages and disadvantages, but they're similar enough that if you know one you should probably stick with it and be happy, and pick something farther from the tree as your next language (Erlang or Scala, say).
评论 #682830 未加载
lisperforlife将近 16 年前
I believe it is more of a personal choice than anything else. That said, here are the reasons I like Python more than Ruby.<p>* Namespaces - Ruby has namespaces but when you are reading some code it is very hard to figure out what got mixed into what. This may be more predominant in the Rails world than others. You can exactly know where each one of the classes and methods came from unless you are doing a 'from x import <i>'<p></i> Clean code - I know that with most editors today, you can have clean code. But python's insistence on indentation makes the code appear clean and very readable. This was an excellent design decision.<p>* Method and class invocations need () - This view is very subjective. While ruby's method invocation style gives rise to a lot of DSLs, python's style of invocation means that there are no silly Proc objects. If you need to pass a function to another function just send its name. I am not saying that one way is better than the other but I like python's explicitness here.<p>* OpenStruct by default - This is one of the best design decisions ever. Python uses a very fast implementation of dict for its objects. That means you almost get a javascript kind of object without the clunkiness of javascript.<p>I am biased a little bit towards python as I learnt python first. I do love Ruby's DSLs but I have a heart for Clojure too, in this regard. And I am actually quite happy that Jython 2.5 has come out. I am a little disappointed that Jim jumped over to the IronPython and left Jython hanging. But thanks to him, Python is there on all the major platforms.
yan将近 16 年前
For me personally, it boils down to me liking the library more, the syntax more and the common programming styles. Ruby is very hard to follow me due to the (imho) overuse of meta-programming and using language constructs that obscure the actual meaning of the program. Patching objects and being overly clever with language features makes ruby code harder to read.<p>It's also, to me personally, a lot faster to whip something up in Python than in Ruby, even when I knew them at about the same level.
评论 #682159 未加载
blasdel将近 16 年前
I wish Ruby were good, but it's so fucked:<p><pre><code> Matz's decision-making process He tries to make Ruby be all things to all people Lots of confusing sugar and overloading baked in I much prefer Guido's hard pragmatism The pointless panoply of function types: Methods, Blocks, Procs, Lambdas All intertwined and yielding into one another. I love that in Python there is only one: Objects with a __call__ method, defined metacircularly. The culture of adding/overloading methods on base classes Many gems do this en masse, and there are a lot of low-quality gems Seriously, Ruby might have a ton of new gems for everything, but they are almost universally awful. A culture of sharing any code that *could* be a module, no matter how trivial, leads to immature crap being widely used because it was there already, with a mess of forks to clean up afterwards. At least most of them are test-infected... Python does come with a few stinkers, mostly ancient syscall wrappers. Especially disastrous because it's unscoped, and infects the whole process For a language with four scoping sigils it sure fucks up scope a lot The syntax practically begs you to do it, anything else would look shitty The Matz Ruby Implementation The opposite of turtles-all-the-way-down (Smalltalk crushed beneath Perl) It actively punishes you for taking advantage of Ruby's strengths The standard library is written almost entirely in C It doesn't use Ruby message dispatch to call other C code. That means that if you overload a built-in, other built-ins won't use it Anything fiddly that's not written in C will be dog slow</code></pre>
评论 #686763 未加载
tel将近 16 年前
I like Ruby (culturally) more than Python.<p>Python has NumPy/SciPy/and friends, so I use Python.<p>This, I feel, is a strong point for most who are using a scripting language to do scientific work.
评论 #682530 未加载
eznet将近 16 年前
For me, it was the 'magic'. Ruby seemed to have a lot of 'magic' working behind the scenes - which confused the hell out of me when I tried to figure out how something worked a particular way. Python on the other hand has far less magic and more transparency - magic replaced with a transparent box showcasing the logic... Just made it easier for me to wrap my mind around...
dylanz将近 16 年前
One is not better than the other, and neither have "won".
drawkbox将近 16 年前
In Python you dont' have to type 'end', just kidding although for some reason it reminds me of VB for this reason. I wish it didn't but it does. Why have an end be anymore than 1 character on a serious note, that is lots of keystrokes extra not needed.<p>But more seriously Python is a growth like Javascript. It has grown and adapted to every change it has been required because it has a very rapid iteration time and is great for wrappers to core C. It is clean and maintainable.<p>For this it has made huge inroads to system administration, game development, tool plugins, web development, command tasks and everything else. I have yet to have one instance where there weren't numerous libraries for every task. Even if you don't want to use a third party library there are many examples of how to do it.<p>Python is really at it's core many things. It is a functional language, it is an OO language and it can be procedural. It can wrap intense lower level libraries or port in a C extension for speed. The same code you wrote for your desktop api, can be used in a desktop app, a service, website, a web service, a tool plugin, at the command line or any way you need it.<p>It can float like a butterfly and sting like a bee.<p>Like Javascript, Python is based on a core few types, lists and dictionaries (objects). All the languages that seem to permeate like viruses have this basic computer science fundamental. It just is as simple and clean as you can get. Ruby also has this but it came a bit later.<p>And finally, it is named after the great Monty Python.
评论 #683020 未加载
评论 #682484 未加载
bruceh将近 16 年前
I've worked with a lot of languages. Python, C++, Scheme (and CLISP), Java, C#, Perl, Ruby, etc. Every language I've used besides Ruby, I feel that I have to fight the language to actually implement my idea. The fact that programmers want flexibility should be obvious by the contortions present in C++ with boost, particularly the lambda libraries. People are so desperate for flexibility that they use template metaprogramming. This general impulse points to programmers wanting better abstraction capabilities. C# and Python have higher order functions and many other virtues, too. Ultimately, for me I could do anything I wanted to in Ruby without fighting the language. I'm sure there are people that have the same personal connection with Python. When I want the very flexible abstraction--I use Ruby. There are things that out of practicality I use Python and other languages for. Awhile ago I was experimenting with fractal terrain generation. The implementation is procedural, and all using Ruby does is greatly limit the performance of the program--so I implemented it in C++. I use Python for Bioinformatics research because of the excellence of Numpy.
plaes将近 16 年前
Python has IMHO better support for GUI toolkits - Tk support in main library, PyGTK+, PyQt. And two more words about library - import antigravity :).<p>And strong company backing: Google has have hired some of the core Python developers, and some of its infrastructure is written in it... Flumotion with its streaming media (although codec stuff is mostly gstreamer, but most of the networking stuff is in Python)<p>And the final straw - Python just seems to be a bit more beginner friendly...
评论 #682388 未加载
woid将近 16 年前
I have been using Python for about year for Google App Engine projects. I have been using Ruby for about two years for various personal open-source projects. I like both languages, but I prefer Ruby over Python.<p>I hate Python's neglect (by Zed Shaw): <a href="http://www.zedshaw.com/blog/2009-05-29.html" rel="nofollow">http://www.zedshaw.com/blog/2009-05-29.html</a><p>Ruby seems to be so much more "symmetric", Python feels like a hack on top of dictionary to me.
评论 #684649 未加载
Wheat将近 16 年前
Any popularity in Python over Ruby stems largely from the fact that Python came first.<p>I've heard Python developer's working on a Ruby on Rails application that the problem with Ruby is that approximately equivalent to Python in terms of productivity. They wanted to use Python, but pragmatically you can't make the case to management to switch from one language to the other if the other language is more or less the same. But most of the time this effect works the other way around, where Python was established before Ruby.<p>I was doing Perl in 1999, and looked at switching to Ruby or Python. Python was still quite small back then, but you had web frameworks (Zope, Twisted), albeit the incarnations back then are clunky by today's standards, but Python was establishing itself as a clean, readable, dynamic language. Ruby on the other hand had no web frameworks, and almost no documentation in English - the only reason I was considering it was because I was working with a Japanese localization team and they thought Ruby was quite hot.<p>The debate over which dynamic or scripting language to use was always between Perl and Python back then. Perl was the incumbent and Python the challenger, Ruby rarely factored into the picture. It wasn't until Rails started to become useable and gain attention in 2004 and 2005 that Ruby interest started to really blossom. And so Python was well established for many uses: scientific computing, ad-hoc data processing, network programming. If you're a development manager of an application that you want to make scriptable, you would have made the decision to already go with Python, there just isn't any compelling reason to switch to Ruby beyond the sake of switching.<p>Another example is IronPython versus IronRuby: work started on IronPython in 2003, work started on IronRuby in 2007. IronPython is at version 2.0, while IronRuby is at version 0.5, and this is reflected in the polish of these language implementations. A .Net developer might decide that they prefer the idiosyncracies of Ruby over Python's idiosyncracies, but if they had to start a large project in today, they'd most likely choose IronPython since there is much less risk of the project bumping up against the rough edges of IronPython versus IronRuby.
sethg将近 16 年前
Just my personal story, but perhaps extrapolating from it will help answer your question.<p>At my job I use Python because, well, at some point before I arrived one of the senior developers went on a jihad against Perl. :-)<p>I've read stuff about Ruby and while some things about the language intrigue me, it seems that any application you can build with Ruby can also be built with Python. If I'm going to learn another programming language in my Copious Free Time, I want to learn something <i>really different</i> from what I already know, not something that has pretty much the same features with different syntax and libraries. So Python wins by inertia.
me_again将近 16 年前
Most of the discussion seems to ignore the "in this space" (scripting existing software packages) part of your question.<p>I submit that Python is more popular in this space because:<p>- many end users will be users of the package first, and programmers very much second. In this case a very gentle learning curve is more important than ultimate expressivity for hackers.<p>- In the same vein, it superficially looks more like BASIC than Ruby does<p>- The C API may be simpler to use than the Ruby interpreter, though never having used Ruby's C API that's speculation on my part. Never understimate implementor laziness as a technical driver.
mannicken将近 16 年前
I chose Ruby mainly because of all the syntactic tricks and weirdness but despite slowness.<p>You might choose Python for exactly the same reason; e.g., I wouldn't use Ruby on teams with &#62;2 developers, especially in Google. Python is more straightforward but at a (small) price of freedom.<p>Example: you can rapidly prototype in Ruby using blocks and extend basic classes (even integer) using monkeypatching. I was fascinated by this, yet I wouldn't monkeypatch when working with other people so that advantage goes out of the window.
ianb将近 16 年前
I think it's mostly about maturity, of the runtime, of the language, and of the community.<p>For example, Ruby has backward incompatibility issues in minor releases that would never be permitted in Python. They had to jump to Python 3 for even fairly small things that wouldn't be accepted in the 2.x line. Even subtle incompatibilities between Python versions are taken seriously, and there's a documented process for deprecation that involves multiple releases and means when a feature is deprecated it'll probably still be available for years. There's cruft in the language as a result, but for people using Python seriously this is more than worth it.<p>I think the Python-Dev community is also more mature. Changes get serious review. Though there's not a formal "core", strong objections from certain people are enough to bring a new feature back to zero and require a restart (not because those people have special weight, but because they are respected and everyone kind of understands there's a benefit to listening to crotchedy naysayers if they are smart crotchedy naysayers).<p>The community is large enough that there's a lot of domain knowledge. Python is better at getting a canonical and complete solution to a domain problem than Ruby. WSGI discussions for instance involved some people with a very intimate knowledge of HTTP. People work hard to get 95% solutions instead of 80% solutions. In part because Python has been around a long time, and there's already at least an 80% solution for whatever problem you are looking at, and if you are going to throw your hat in the ring you ought to be ready to try harder. I think the more aesthetic tendencies of the Ruby community work against it here, as people are more likely to rewrite for aesthetic rather than functional reasons. (OTOH, when Python settled early on some 80% solutions, it's caused a lot of difficulties because it's been hard to overcome inertia to introduce a better solution, while it's hard to get really good adoption of the 80% solution; pydoc would be an example.)<p>Then there's simple maturity. The VM is more stable; it may not be a great VM, but it is predictable. There's lots of tools for writing extensions. There's code for dealing with large data sets, for dealing with images, for accessing system libraries, etc. For any one problem Ruby might work fine, but for the problems you don't yet know you'll have to solve it's less likely you'll hit a blocker with Python.
评论 #683961 未加载
mahmud将近 16 年前
They're both equally Greenspuned to usefulness.
JeremyChase将近 16 年前
One major problem with Ruby has been that the performance as been <i>much</i> slower than Python. This is no longer true with Ruby 1.9. I happen to have done a benchmark using a recursive Fibonacci algorithm yesterday, results: <a href="http://pastie.org/528717" rel="nofollow">http://pastie.org/528717</a> source: <a href="http://pastie.org/528720" rel="nofollow">http://pastie.org/528720</a><p>I wouldn't say Ruby has lost just yet.
评论 #682263 未加载
评论 #682144 未加载
mikewoodhouse将近 16 年前
When you say "win", are you meaning in the sense of "there can only be one"?<p>Why limit the discussion to Python and Ruby? Why not include PHP, say? Why have Python and Ruby "lost" to PHP? What about C++, Java and C#?<p>Heck, VB is still more "popular" than either: <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" rel="nofollow">http://www.tiobe.com/index.php/content/paperinfo/tpci/index....</a>
评论 #686367 未加载
nailer将近 16 年前
Having used Python a while, unnecessarily marking out statements a second time for the computer using brackets is a waste of time, and ugly. I use older faster languages and put up with this, but don't see the point of doing so with Ruby.<p>Nearly all of the installers and packaging formats and management tools in Linux have Python APIs.<p>Edited as I wasn't clear the first time round: I love Python's wide variety string methods, and the emphasis people put on these rather than using RegExs all the time (sorry, I have more Perl and less of a Ruby background). Looking further it seems there's Ruby equivalents of most of my frequently used methods.<p>I love etrees in the standard library. People who use regexs for dealing with tree structured data are mental. Again, perhaps a Roby fan might enlighten me if there's a similar data structure in Ruby, I wouldn't be surprised.
评论 #682264 未加载
al3将近 16 年前
Using edge cases in the syntax to construct an API with unusual calling conventions is not "writing a DSL." Unless you build a compiler/translator for it, it is not a "DSL," it is plain-old Ruby, happily accepted by any conforming Ruby implementation--nothing more.<p>After their pretentiousness, their arrogance, and their vociferous obnoxiousness, I find their misuse of this once-widely understood term to be their most annoying attribute. It seems like not a day goes by without some eager Ruby programmer hacking together yet another block-based API that kind of, sort of looks like Smalltalk if you squint enough, uploading it to GitHub or some similar site, and then slapping the "DSL" label on it, because Ruby, apparently, is just too cool and powerful a language to have mere "libraries" or "APIs."
评论 #682381 未加载
评论 #682480 未加载
jlees将近 16 年前
Both have their uses. I was a Perl hacker so Python was the obvious choice for me - but I would use Ruby for specific projects, for example if I desperately wanted a one-off app that primarily depended on a stable Ruby library where no Python one existed.
评论 #683217 未加载
cmars232将近 16 年前
Ruby feels like all the misery of Perl mashed into Smalltalk. Which is a shame, because I hear such good things about Smalltalk.
Bogdanp将近 16 年前
<a href="http://xkcd.com/353/" rel="nofollow">http://xkcd.com/353/</a> I need no other reason.
brueno2009将近 16 年前
python is easy to learn like php and ruby have sometimes strange looking syntax like perl for newbies. A good programmer doesn't have this problem and will love the goodies and syntactic sugar from ruby.
评论 #682288 未加载
chl将近 16 年前
NumPy.
dolzenko将近 16 年前
Google SketchUp is scripted in Ruby
ilyak将近 16 年前
For embedding and scripting, I'd take python too. It'a s known value here, and I've heard ruby isn't so much.<p>When NOT talking about embedding or scripting, I'll probably take ruby.
c00p3r将近 16 年前
1. Get latest OpenSolaris. 2. Install latest SunStudio 3. download latest source of Python (3.1) and Ruby (1.9.1). 4. Try to build them with CC=/opt/SUNWspro/bin/cc" CFLAGS="-m64" 5. See the results. Run make test for ruby.
评论 #682538 未加载
评论 #684020 未加载
评论 #683978 未加载