6 ms·
My Mixed Feelings about Ruby
- sabat 18y agoTo my eyes, Ruby as a language looked a lot like an internal IT app that is built as an aggregation of features. There might be a wonderful, coherent design in the implementation that I can’t see, but the interface I use seems like a bunch on one-off features that don’t play well together. Huh? Is this guy talking about Perl? Is he talking about the same Ruby I know? His criticisms don't make any sense. Ruby is well-organized and well thought-out. It's not without its flaws, but it has far fewer than Java or Perl. Hell, Ruby makes Perl look like Java. (If he hates Ruby this much, I'd hate to imagine what he'd think of the gigantic featuritis-striken kludge called Java or J2EE.)
- emmett 18y agoRaganwald is one of the most prominent Ruby programmers I know of, so I would say it's unlikely he hates Ruby. And he has a point. While Ruby is certainly more coherent than Java, it's clearly less coherent than io or Lisp or smalltalk.
- raganwald 18y agoRuby is well-organized and well thought-out. O RLY? Just kidding. I think Ruby is well thought-out. Just for a chuckle, what does this snippet of code do? p = Proc.new { return :to_sender }; p.call What about this one? l = lambda { return :to_sender }; l.call Why and how do they differ? And given that they differ in behaviour, what do you think this should return? False, right? c.class == l.class As for my criticisms, my main point has to do with Ruby not being implemented in terms of itself. Almost everything else that troubles me can be traced back to that issue. http://weblog.raganwald.com/2006/11/significance-of-meta-circular_22.html http://weblog.raganwald.com/2006/11/significance-of-meta-cir... http://weblog.raganwald.com/2007/12/why-rubinius-matters-to-rubys-future.html http://weblog.raganwald.com/2007/12/why-rubinius-matters-to-... http://weblog.raganwald.com/2008/02/turtles-all-way-down-please.html http://weblog.raganwald.com/2008/02/turtles-all-way-down-ple... p.s. Please remember that the post was not titled "What's wrong with Ruby," it was titled "My Mixed Feelings about Ruby." So it can well be that I have a viewpoint which does not reflect how intelligent people feel about t he language.
- fendale 18y agoirb(main):002:0> p = Proc.new { return :to_sender } => #<Proc:0x0035a050@(irb):2> irb(main):003:0> p.call LocalJumpError: unexpected return from (irb):2 from (irb):3 from :0 irb(main):007:0> l = lambda { return :to_sender } => #<Proc:0x0033b86c@(irb):7> irb(main):008:0> l.call => :to_sender I had no idea it would do that - is a 'return' statement illegal in a Proc?
- raganwald 18y agoA return statement is not illegal, however it returns from the method call where it was defined... if that method call is still valid. So this works: def valid_method_call pp = Proc.new { return :to_method_caller } pp.call end valid_method_call But this does not: ll = lambda { pp = Proc.new { return :to_lambda_caller } pp.call } ll.call If you do something like save the proc for later, you are in trouble: def temporary_method_call Proc.new { return :where_shall_i_return? } end pp = temporary_method_call pp.call Because the method call where the proc was defined no longer exists. So Ruby closes over local variable bindings, saving them for later, but not over control flow. If it did, the return keyword would end up acting like a continuation.
- ezmobius 18y agonow try this on for size. I'm sure you know how this works: > def a > yield > end => nil > a { 42 } => 42 But did you know this? > def b > Proc.new.call > end => nil > b { 42 } => 42 Proc.new without any arguments works the same as yield. tripped me out when I found this the other day.
- Andys 18y agoIts nice that we can choose how we want return to behave in a block. It doesnt make any sense that the two ways be called "lambda" and "Proc.new". Maybe you have to be Japanese to understand it?
- gommm 18y ago
- mechanical_fish 18y agoAlas, one of the downsides of living in beautiful surroundings for a long time is that you adapt to them. And then you can spot the flaws. This is a good thing for humanity in general -- criticism will help Ruby's successors to be better languages, just as criticism of Perl helped make Ruby better -- but it's occasionally painful for the individual humans who have been trained to see the holes in the carpet.
- gunderson 18y agoThis is a good point. Whether the successor is Ruby 2.0, Ruby 2.2 or some yet to be invented language, the warts that Ruby has now ought to be discussed and understood if we want the successor to be better. I personally think that Matz had some great ideas that make expressing one's self in Ruby very natural (whether you like an oo style or a functional style, a meta style, etc.) There are some oddities like the Proc vs lambda return semantics differences, but those can easily be cleaned up. So one should differentiate between "Ruby the idea" and "Ruby the legacy codebase", as the latter is not always going to live up to all of the ideals of the former.
- tokipin 18y agoi haven't used ruby excessively, but one example i found just by looking at it a bit is that blocks are redundant with lambdas to me it seems the language is trying to promote higher-level programming by making what is perhaps a common usage of first-class functions more explicit. but i can't say this is necessarily the best choice another thing is lambdas are poorly-implemented, requiring the .call thing (perhaps due to the parens-less function calls.) this matters to me because i use a lot of first-class function stuff for personal coding i use Lua, which to me feels more powerful than Ruby (from the perspective of abstractive power,) yet is much more streamlined
- raganwald 18y agoblocks are redundant with lambdas Except the semantics of the return keyword are corrupted if you get rid of blocks and procs while keeping lambdas. Makes me think return isn't worth the bother, but then again lots of people would hate a language without a return keyword.
- gunderson 18y agoI wouldn't say corrupted, just different. I imagine there are many cases in which the different semantics are used intentionally. This is really not a huge issue, b/c anyone who has worked with Ruby enough knows about it. It's mainly that the difference doesn't really make logical sense -- why would a "proc" behave differently from a "lambda"? Also note that: lamba { foo } means exactly the same as proc { foo } which is different than: Proc.new { foo } This sort of smells, but it wouldn't if there were a new keyword to represent the way Proc.new behaves... then everyone would flex their Ruby muscles by writing confusing hacks that utilized the behavior of StrongReturnProc.new ... :)
- raganwald 18y agoit wouldn't if there were a new keyword to represent the way Proc.new behaves My understanding is that there is a very good chance that Ruby 1.9 (when it stabilizes) will change the proc keyword to have Proc.new semantics instead of lambda semantics, for exactly the reason your give.
- Darmani 18y agoBlocks may not be able to genuinely accept blocks in Ruby, but I was able to get something pretty close: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/293232 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...
- petuniapredator 18y agoGood article raganwald. I'm just learning RoR and I guess my biggest hangup is the prodigious use of colons. I admire your ability to "rewrite code for Ruby"... For me it's tough enough to learn one language. There is no way that I would ever attempt anything but a greenfield application with RoR and to finish that I will probably need some help. What attracted me to the language was the impression I got from reviewing descriptive materials from DHH and the 37 signals crew that Ruby has a great deal of elegance when it comes to interacting with databases. And, for me anyways, that's the only kind of elegance I'm really interested in because I think that's where the money is going to be. So far I'm not really good enough with the syntax to say whether it's going to live up to expectations but I haven't really seen anything yet that would cause me to say I've made a mistake in choosing this platform.
- quellhorst 18y agoWho cares? It isn't like you and ruby are getting married. If you have a project that ruby seems like a decent fit, use it. You'll get nowhere are learn nothing without actually doing.