5 ms·
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
by raganwald 18y 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.
Instead, Python finds another way, like powerful list comprehensions that can be used wherever Ruby would use blocks and maps.
So I would say you can learn some very interesting things from either language, and there's a good chance they will be different interesting things.
- aconbere 18y agoMatz might say that, but doing functional things in Ruby is a pain in the arse as well. Blocks, Lambdas, Procs, and Methods, all which are slightly different and require transformative functions to move one into the other. That's about as far from an s-expression as you can get. That being said, having the easy ability to create lambdas or blocks is hugely benefitial. sighs and I wish python would hop on board there, but I don't think it ever will.
- raganwald 18y agoI dig: http://weblog.raganwald.com/2008/06/what-does-do-when-used-as-unary.html http://weblog.raganwald.com/2008/06/what-does-do-when-used-a...
- aconbere 18y agoYeah... sobs it's a nice band-aid, but an inelegant solution. I would much rather that they all just be Proc or all some other mythical procedure class of the future. I figure that would break the whole ruby method call chain, though I don't see any reason why blocks couldn't just become straight syntactic sugar for lambda (I would love that)
- raganwald 18y agoA little off-topic, and I apologise to everyone for our exercise in bikeshedding, but... :-) The problem is that Ruby blocks were designed to imitate the behaviour of C-like blocks, while lambdas are true closures. (Don't get me started on why procs are just like lambdas only different). The difference between a block and a lambda is most clearly seen by asking what the return keyword does in a block vs. what it does in a lambda. So in Ruby you can write something like: def which_answer_is_correct(*answers) answers.each_with_index do |answer, index| return index + 1 if answer.to_s == '42' end return 'none of the above' end which_answer_is_correct('black','white',42,:symbolic_logic) => 3 If blocks were syntactic sugar for lambdas, this method would always return 'none of the above'. Of course, there is another, very elegant way to write this method that doesn't rely on the return keyword or the semantics of blocks, and one can easily argue that this would be an improvement.
- aconbere 18y ago(though my intention was not to derail the conversation. This is a niggling difference between ruby and python that irks me :-D) Right I would be arguing as the latter. My problem is that these small niggling differences between all the different types of callable items (including what I think is simply disgusting use of a special form "yield") confuses the whole mess. I'm glad that all these different ways to use callables exists. That's "A good thing" in my opinion. But I can't help but feel that their quirks and differences couldn't be consolidated into a single experience.
- eru 18y agoFor functional programming what Python really misses is not a decent lambda. You can get by without. But properly optimized tail recursion.
- nostrademons 18y agoYou don't really need full tail-call optimization as long as your map/filter/reduce is optimized. Nearly everything can be expressed as combinations of those. Actually, if you have generalized folds (folds over all data types, not just lists), all recursion can be expressed in terms of a fold. That's the point of a fold function: it captures the recursion pattern over a data type, letting you parameterize just the specific operation that replaces the constructor. In practice, I found that the mutability of basic structures was more of a problem. By default, your subscripting/attribute assignment all mutate the original object instead of creating new ones. When I did FP in Python, I did a few decorators to hide this, but it still felt like an ugly kludge that was fighting the language.
- eru 18y agoYes, that's a problem, too. E.g. dictonaries would need to be replaced by something persistent like balanced trees.