TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What does Ruby have that Python doesn't?

66 pointsby globalrevover 16 years ago
About 6 months ago I decided to learn either Python or Ruby because I wanted a language to write webapps and simple computergames fast.<p>I kind of tried both for a while and Python gave the better impression in every way, readability, ease of use, libraries, documentation, expressiveness etc.<p>But there are so many really enthusiastic posts about Ruby and while Python has a lot of users and is very popular and successful I rarely see anyone rave about it. But maybe that just means it has gotten mainstream.<p>But anyway I like the Python philosophy that there should preferrably be one obvious way to do things. While similar in most ways, there the languages differ.<p>So, what do you Rubyists like so much about Ruby? Especially what do you think Pythion lacks?

27 comments

tptacekover 16 years ago
What the hell, they're only karma points:<p>I lived with Python for 4 years before I lost an argument at my own company and had my project moved to Ruby. I've since moved in with Ruby and haven't looked back.<p>* Everything in Python feels like a symbol table hack. Private methods? We have those! Just exploit this bug in the class symbol table lookup code!<p>* First-class symbols. There may be little difference under the hood between a Ruby interned string and a Python string atom, but there's definitely a difference syntactically. This is a difference that is hard to articulate, but if you've written much C, it's like having every "enum" you could ever want predefined for you, and completely eliminates "magic numbers".<p>* Blocks and lambdas. I've read GvR's take on this. I know he thinks a named function is just as good --- maybe even better! --- than an anonymous function. I had nested named functions/functors in C++ and Java. Even Tcl "uplevel" is better than Python's castrated lambda.<p>* Method definitions in Ruby don't need to accept a "self" argument. Again: all of Python feels like a symbol table hack to me.<p>* Ruby has first-class Regexps. Python has an "re" library. You know what else has an "re" library? C.<p>* I haven't found an expression that is better written as a list comprehension than as a map/reduce/select expression.<p>There are painful things about Ruby:<p>* The FFI is immature. Outside of Common Lisp, Python ctypes may be the best FFI out there.<p>* I never got Python to crash on me (at least, not where it was Python's fault). I crash Ruby once a week.<p>* Ruby is palpably slower than everything. If performance matters to you and you don't know C, you may be better off in Python.<p>* The community is led by the nose by Rails developers, which can at times feel like a worst-of-all-worlds grab bag of methodology programmers, web designers, and dabblers.
评论 #283967 未加载
评论 #283992 未加载
评论 #284125 未加载
评论 #284556 未加载
评论 #284150 未加载
评论 #284181 未加载
评论 #284597 未加载
评论 #284604 未加载
评论 #288752 未加载
评论 #284896 未加载
评论 #291164 未加载
评论 #283965 未加载
davidwover 16 years ago
I don't think Python lacks much, if anything. It's a very fine language, with a great community. Over the years though, I just lost interest in it, and have come to prefer Ruby after having rediscovered it because of Rails. It's pretty much a matter of taste: I like the syntax and convenience more.<p>One (fairly minor) real world case where the syntax makes a difference is in web templates: you can use Ruby pretty much straight up to do templating, but Python requires more hoops and hacking, due in part to the whitespace issue. I like the fact that Ruby is flexible enough to be used as-is for templates as well as other code. BTW, it also needs to be said that that is the <i>only</i> place I've ever noticed the whitespace issue being any kind of problem: it's not the big deal that some python detractors make it out to be.<p>In short: if you're happy with Python...great! Keep using it, you made a good choice. If you want to learn another language, pick something a bit further from it... say, Erlang, Tcl, Java, or C, depending on what your needs are.
评论 #283676 未加载
评论 #285382 未加载
raganwaldover 16 years ago
They're both impressive, modern languages. What I find interesting when comparing Python to Ruby is how much Python isn't like Lisp. Matz has said outright that he considers Ruby to be "MatzLisp" and it shows, whereas Guido has absolutely no problem chucking Lispy things overboard--like multi-line anonymous functions--if they do not fit the rest of the language.<p>Instead, Python finds another way, like powerful list comprehensions that can be used wherever Ruby would use blocks and maps.<p>So I would say you can learn some very interesting things from either language, and there's a good chance they will be <i>different</i> interesting things.
评论 #283783 未加载
评论 #284863 未加载
ritover 16 years ago
I've always taken the approach of learning both and deciding for myself. If you're interested in true proficiency and building something for yourself, go with whatever rings most true to you.<p>I liked Ruby, but found that Python clicked better for me. That, and call me crazy - but I prefer quiet competence to foaming at the mouth zealotry. There are plenty of people who rave about Python - but they've been doing it for a lot longer than the Ruby people (simply age of language).<p>Ruby also has gotten lots of people hooked via Rails, and that seems to be where most of the evangelism is coming from.<p>(edit: commented to clarify my meaning below, in another comment: <a href="http://news.ycombinator.com/item?id=283771" rel="nofollow">http://news.ycombinator.com/item?id=283771</a>)
评论 #283665 未加载
评论 #283662 未加载
simonwover 16 years ago
Two good things and one bad thing. The good things are multi-line lambdas (which Ruby calls blocks) and loose syntax rules, which I found weird at first but is the secret behind all of that DSL stuff.<p>The bad thing is the cultural tendency of the Ruby community towards monkey patching, which in my opinion trades long term maintainability for short term convenience.
评论 #283748 未加载
评论 #283778 未加载
iamniravover 16 years ago
I like how this conversation has gone on for so long, but on the whole, everyone's still polite and detailed in their responses. :-) <i>warm fuzzy feeling</i>
subwindowover 16 years ago
It isn't so much about language features, as both languages are roughly equivalent in that sense.<p>It is about how the language makes you <i>feel</i>. If you're going to be spending &#62;5 hours a day writing in some language, it is of great importance how that language makes you feel when you write it. Simply said, writing Ruby makes me happier than I've ever been while writing code.<p>Python is to German as Ruby is to French. You can get roughly the same message across equally well in both languages, but French just sounds so much better.
评论 #284022 未加载
评论 #283754 未加载
评论 #283798 未加载
评论 #283897 未加载
评论 #283779 未加载
评论 #284866 未加载
iamelgringoover 16 years ago
<i>About 6 months ago I decided to learn either Python or Ruby because I wanted a language to write webapps and simple computergames fast.</i><p>If you're after writing simple computer games fast, then you might have a look at Pygame: <a href="http://www.pygame.org/news.html" rel="nofollow">http://www.pygame.org/news.html</a><p>There are also a number of visual effects companies (ILM, Dreamworks) that use Python as their system scripting language. I don't know if it's because of that community, but I find a number of graphics/games libraries in Python: <a href="http://www.vrplumber.com/py3d.py" rel="nofollow">http://www.vrplumber.com/py3d.py</a> and <a href="http://vpython.org/" rel="nofollow">http://vpython.org/</a><p>Blender the open source 3D modeling program used Python as it's scripting language last I checked: <a href="http://www.blender.org/" rel="nofollow">http://www.blender.org/</a><p>I don't know if Ruby has libraries like that or not. I've only used Ruby to mess around with Rails.
pauljonasover 16 years ago
For me, the question isn't so much what Ruby has that Python lacks, but the extra Python bits I find annoying and/or tedious:<p>* having to declare "self" in every method argument — reading code, it just clutters up the screen/page<p>* the big use of of double underscores for special methods (i.e., __init__, __str__, __getattr__, etc...) — IMV, it's gooberish...<p>* no switch/case statement<p>In defense of Python over Ruby:<p>* I prefer the whitespace over the Pascal-ish begin/end, especially for real life code solutions<p>* the Ruby shorthand syntax IMV at times obfuscates code clarity - is it a method or variable I am looking at?<p>That said, I'd much rather code in either Ruby or Python than in Java or C...
gtaniover 16 years ago
Well, they're both foundational languages, pretty much, not in the sense of this blog, i.e. most instructional language<p><a href="http://mvanier.livejournal.com/998.html" rel="nofollow">http://mvanier.livejournal.com/998.html</a><p>but in the sense of can you put up a significant web app in 2 or 3 days, do lots of companies use it (along with C, java, C#, javascript).<p>r vs. p can't be reduced to 15 bullet points, but one of the best things i remember is Alex Martelli in 2003, so he was talking about ruby 1.6 and python 2.3, i believe, but still valid<p><a href="http://groups.google.com/group/comp.lang.python/msg/28422d707512283" rel="nofollow">http://groups.google.com/group/comp.lang.python/msg/28422d70...</a><p>and here's the last thread from May.<p><a href="http://news.ycombinator.com/item?id=157269" rel="nofollow">http://news.ycombinator.com/item?id=157269</a><p>There's the other killer apps: Python: twisted, zope, SQLalchemy, mercurial. Ruby: rake, capistrano, rspec, adhearsion, merb, puppet, metasploit. I'm sure python has a bunch more, but i've been living in rails-land.
waldrewsover 16 years ago
Though I'm pro-Python on maintainability grounds, there's one Lispish feature Ruby has that I wish were available in Python, that's not even in the Py3000 spec: continuations. The Ruby community doesn't seem to be too enthusiastic about using them though. We're just beginning to see continuation-based web framework experiments on Ruby, in the spirit of Seaside in Smalltalk.<p>The continuation-based web frameworks make state management on the server transparent; but they have a scalability problem since state can't move between servers or even be taken out of memory on the same server.<p>Now once somebody makes serializable continuations practical - certainly a hard problem - it would be a jolt to web development on at least the same that Rails has been.
评论 #284132 未加载
评论 #284424 未加载
eznetover 16 years ago
I think that a lot of the popularity of Ruby came not so much from Ruby itself, but Rails. I think that with the emerging popularity of Django, you are likely to begin noticing a similar influx of Python enthusiasm...
评论 #283871 未加载
abdelazerover 16 years ago
After leaving Ruby (non-Rails) for Python this year, I've mostly noticed the difference in the obsession about testing. The Ruby crew is very into TDD (and now BDD)–that isn't to say that Python folks don't test (or do TDD/BDD), but simply that the tools available in Python aren't quite as polished. Ruby's RSpec, RCov, Flog, Autotest, &#38; Heckle are all quite wonderful. I do like Nose, but get annoyed by lack of friendly code coverage tools in Python.
Alcidesover 16 years ago
Rails. but you have Django which is better ;)<p>Seriously, I envy ruby's blocks and being able to redefine a class later in your code (monkeypatching-easy-syntax).<p>Oh, and Shoes :)
评论 #283681 未加载
评论 #283669 未加载
demallienover 16 years ago
There really isn't a huge difference between the two. For what it's worth, I personally prefer Ruby because it has better support on the Mac - Apple use ruby a fair bit themselves. For example, the command line tool gen_bridge_metadata (supplied by Appleto make it possible to access system frameworks written in C from scripting languages) is itself a ruby script. I notice that on Linux it's the reverse - python seems to be the preferred scripting language.<p>But don't take my comments as saying only ruby is supported on the Mac, or only python on Linux - in reality it's only a light preference one way or the other.
评论 #283755 未加载
maxkleinover 16 years ago
The languages are similar enough that it does not really matter. Just pick any, but make sure you balance it out by also knowing a low level language or a functional language.<p>Remember this: Every language you learn is a big investment in time and energy, and I don't think many people can be really proficient in more than 2 or 3 languages. Some can, but not most.<p>So, choose wisely, because you will likely be using that language for a long time to come. I personally prefer python because it's more widespread and right now, you have more available to you when you know it than with ruby.
评论 #283705 未加载
评论 #283768 未加载
olavkover 16 years ago
I prefer Python, but I am somewhat envious of Ruby blocks. Also I like the idea that method calls are messages.
评论 #283699 未加载
jonhohleover 16 years ago
this is never really brought up, but objects in ruby fully encapsulate their instance and class variables. the only way to get at them from the outside is by sending an object a message asking for them (like Smalltalk or Objective-C). what appears to be setting a property on an object, is really calling a method: `foo.bar = 5` isn't directly setting the property, its calling a method named `#bar=`<p>in my opinion, this is powerful and elegant.<p>that being said, i have little experience with python, but what i've seen never wowed me. it seems like it has a well written collection of libraries, but that seems to come from the community more than the language. correct me if i'm wrong.
评论 #283870 未加载
DougBTXover 16 years ago
_why
tokipinover 16 years ago
personally i don't like the 'one way' mantra that Python is designed by, because it seems to imply a couple things. 1, the language is probably not as flexible and powerful as it could be. and 2, the design goal is similar in nature to that of production languages, eg Java which forces object orientation. the intentions are good... to allow the construction of readable, maintainable software by normal humans, and Python is at least not as retarded about it as Java, but i have found that languages which constrict aren't for me<p>so to me Python seems more of a team production dynamic language than one where i can get into flow and crank shit out
评论 #284061 未加载
thisisnotmynameover 16 years ago
The lack of built-in regular expressions is a pain point for me.
petercooperover 16 years ago
Consistency in class definitions (that is, not two "types" of class). Python's packaging is less consistent. Oh, and far better community sites.
Zakover 16 years ago
First class symbols are the big one, I think. Of course, we all know about Python's brain-damaged function literals.
jrsimsover 16 years ago
I really like Python, but it doesn't have an equivalent to CPAN or RubyGems.<p>I'm actually quite puzzled by this.
评论 #283744 未加载
评论 #283722 未加载
gaiusover 16 years ago
My experience is that the languages are similar in terms of features, but the communities are very different and there isn't much overlap between them. Ruby types tend to be younger, focussed on the web, probably employed as full-time developers. Python types tend to be older and not employed as developers, but write code as part of their main jobs. Python people often have experienced a nightmare of unmaintainable Perl, that is why there is the insistence on there being one right way to do everything (which is the exact opposite of what Perl people believe). Ruby people (being younger and hence less experienced) haven't, which is why they talk about expressiveness and do things like monkey-patching. Neither group is "smarter" and neither language is "better". The choice is a choice of what community you want to join, not a technical one.
评论 #283882 未加载
评论 #283743 未加载
评论 #283720 未加载
mromanover 16 years ago
I would love to read pg's thoughts on this question.<p>Actually, I would love to read more of pg's thoughts on Ruby, what I have read of his thoughts on it has been brief yet highly positive.
pdubroyover 16 years ago
Hype? ;-)