News for hackers. Stuff that matters.
Re:Ask HN: What does Ruby have that Python doesn't? by gaius on Friday August 22, 2008 @09:48AM (#283668)
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.
Re:Ask HN: What does Ruby have that Python doesn't? by DocSavage on Friday August 22, 2008 @01:00PM (#283882)
From my observation, the ruby community is heavily skewed by the recent influx of Rails programmers, which is web dev and younger. Old-school ruby folks (the guys who were ruby gurus when Rails was still an infant) have different characteristics: older, less confrontational, veteran programmers, Matz-like. A generalization for sure but my impression.

The python community has done significant development in science/math so they have stronger libraries in those fields. Python has had an influx of Railsy people due to Django and might get a shot in the arm from Google App Engine.

From a language perspective, I like the wealth of libraries for python. I like that many reference/experimental applications on web stuff is in python. The whitespace issue for me has disappeared and I'm actually leaning toward liking it more than ruby's block delimiters. The template/erb issue can be diffused by looking at HAML. (That's a cool way of incorporating pythonic indentation to templates.) Unicode is solid in python.

Ruby is a better choice if you like to reshape the language into something that could potentially look un-Ruby. It's possible I haven't gotten far enough into python yet, but I can see why metaprogramming and DSLs are more prevalent in ruby than python, and it's not just "one way" culture. (Ruby's optional parentheses for method calls is an example of a language feature that fosters DSL use.)

Re:Ask HN: What does Ruby have that Python doesn't? by aristus on Friday August 22, 2008 @01:15PM (#283899)
I have to agree. Ruby has incredible flexibility, but how it's been used by "the kids" in things like Rails (and especially Rails extensions) makes my skin crawl.

This also bugs me to no end: nil.to_i == 0, 0 evals true, but nil evals false.

Python's lack for me is anonymous functions. It's cumbersome to set up 40 slightly different named functions and a hash table (or some "factory pattern" thing) to do the same job as 3-4 lines of Ruby. Symbols are nice too.

But for my personal work I choose Python for the libraries, cleanliness, and performance.

Re:Ask HN: What does Ruby have that Python doesn't? by DocSavage on Friday August 22, 2008 @01:53PM (#283966)
What are you doing that can't be done with python's lambda functions?
Re:Ask HN: What does Ruby have that Python doesn't? by raganwald on Friday August 22, 2008 @04:31PM (#284153)
What are you doing with Python that can't be done with FORTRAN?
Re:Ask HN: What does Ruby have that Python doesn't? by DocSavage on Friday August 22, 2008 @04:37PM (#284168)
Running on Google's App Engine :)

Seriously, though, I'm not arguing python's anonymous functions are just as good as ruby's. I'm curious about his particular situation where "3-4 lines of Ruby" is all it takes.

Re:Ask HN: What does Ruby have that Python doesn't? by eru on Saturday August 23, 2008 @06:35PM (#284857)
You could run FORTRAN on a virtual machine on Python.
Re:Ask HN: What does Ruby have that Python doesn't? by aristus on Friday August 22, 2008 @02:41PM (#284031)
Anything that is not a simple expression. assignment, if..else, etc.
Re:Ask HN: What does Ruby have that Python doesn't? by kashif on Friday August 22, 2008 @04:28PM (#284148)
Then use a function with some introspection and pass it some parameters.
Re:Ask HN: What does Ruby have that Python doesn't? by cturner on Friday August 22, 2008 @06:56PM (#284288)
You can but you shouldn't need to. Sometimes I want to do something like:

    dict['item'] = def _(var1, var2):
        fn_var = 1
        do_some_magic(fn_var, var1, var2)
There's no good reason why I should instead have to do:

    def fn(var1, var2):
        blah
    dict['item'] = fn
.. or write a decorator.

I'm frequently tempted to write a python-like scheme syntax to sit in my python programs so I can just do this stuff and to hell with the excuses used to prevent my first code block from above from working.

Re:Ask HN: What does Ruby have that Python doesn't? by LogicHoleFlaw on Saturday August 23, 2008 @03:21PM (#284775)
It's been a while since I wrote any Python but... here's a shot in Lua.

Lua:

  function dict.item (var1, var2)
    local fn_var = 1
    do_some_magic(fn_var, var1, var2)
  end

  -- note that:
    function dict.item (arg) return arg end
  -- is syntax sugar for:
    dict.item = function (arg) return arg end

  -- for an implicit "self" parameter use a : in your declaration and invocations:
    function dict:item (arg) return self(arg) end
  -- is sugar for
    dict.item = function (self, arg) return self(arg) end
You can in fact call functions with the implicit (via :) self parameter with any desired "self" by using the "." rather than ":" invocation syntax and providing an explicit self. ":" is purely sugar which is optional in all cases.

  function table:swap()
    local swapped = {}
    for k, v in pairs(self) do
      swapped[v] = k
    end
    return swapped
  end

  -- assume "Table()" returns a table which routes "method_missing" calls
  -- (which is actually the __index metamethod in Lua)
  -- to `table`
  t = Table { a = "foo", b = "bar" }
  a = t:swap()
  b = table.swap(t)

  -- a and b are both equal to:
  -- { foo = "a", "bar" = b }
One neat thing about Lua is that the user can define basically arbitrary semantics for inheritance, mixins, and all sorts of meta stuff very simply. And you can define them on a per-object basis. It's very powerful. The drawback is that you have to implement these things yourself (unless you use a 3rd-party lib which provides some common patterns like you'd see in Python or Ruby).
Re:Ask HN: What does Ruby have that Python doesn't? by cturner on Thursday August 28, 2008 @02:45AM (#288931)
Thanks for that. I've looked at io a bit, which is similar to lua, and been very impressed by stuff like this. Also that you can effectively reflect against function definitions in order to create modified versions at a later time.
Re:Ask HN: What does Ruby have that Python doesn't? by olefoo on Friday August 22, 2008 @08:37PM (#284367)
Another factor that pushes python forward among people for whom programming is a means not an end is that it is a primary scripting language for Ubuntu and is heavily used in the Red hat descended distros as well...

On some level choice of programming language is irrelevant, since any specified functionality can be written in any turing complete language. Arguments about programming language are arguments about style rather than substance.

I suspect that the python vs. ruby debate is like arguing about whether keyboards or guitar are superior musical instruments. They both have their place and the world would be sadder and smaller place if either one went missing.

Re:Ask HN: What does Ruby have that Python doesn't? by OneSeventeen on Friday August 22, 2008 @10:59AM (#283743)
I agree that this is the big decision point. I'm a Ruby guy and I've looked at Python several times and it never really stuck (I could work on a project that use Python, it just wouldn't be as fun as a project using Ruby to me). I could complain about various technical details, but if I'm entirely honest it would just be minute, meaningless, bitchy detail nitpicks.
Re:Ask HN: What does Ruby have that Python doesn't? by cstejerean on Friday August 22, 2008 @10:45AM (#283720)
"Python types tend to be older and not employed as developers, but write code as part of their main jobs."

I'm curious, how did you arrive at that conclusion?

Re:Ask HN: What does Ruby have that Python doesn't? by gaius on Friday August 22, 2008 @10:55AM (#283736)
Mainly through direct observation. Among my own circle of friends, it's surprising how neatly we (well, those of us who use either language) divide into those categories. But you can see the pattern in job ads, discussions on mailing lists and in the domain-specific libraries for each language too. As many people got into Python through NumPy as a MATLAB alternative as got into Ruby via Rails, I'll bet.

Like I say, this isn't a good thing or a bad thing, it's just interesting.

Re:Ask HN: What does Ruby have that Python doesn't? by rw on Friday August 22, 2008 @11:00AM (#283746)
Your comment made me realize that the phrase direct observation sounds so much better than anecdotal evidence.
Re:Ask HN: What does Ruby have that Python doesn't? by gaius on Friday August 22, 2008 @11:09AM (#283758)
You'll notice I did say my experience :-) I'm not trying to "win" an argument here, which would require "evidence", just pointing out that there are more important things in language selection than the features/characteristics/quirks of the language itself, especially given there's not much to call between Ruby and Python.

But, y'know, you could try quantifying it if you like, by looking at the libraries available for each language, and looking at how many jobs are "Ruby" as their main skill and how many are "10 years of whatever + Python".

Re:Ask HN: What does Ruby have that Python doesn't? by cstejerean on Friday August 22, 2008 @02:35PM (#284021)
Certainly not a bad or good thing, it was just interesting to me because I've never noticed the same trend from interacting with the Python community in Chicago and at PyCon.