42 points · by vladimir · 17y ago · 56 comments
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 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
Especially disastrous because it's unscoped, and infects the whole process
For a language with four scoping sigils it sure screws up scope a lot
The Matz Ruby Implementation
The opposite of turtles-all-the-way-down (Smalltalk crushed beneath Perl)
It 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 slowFor what it's worth, this has recently become a 'standard' interview question for developers. I predict that people will start game it by having a canned response, thereby rendering it virtually useless---just like all other standard interview questions.
I used to ask interviewees to discuss what they didn't like about their favorite language. If they had a hard time finding stuff to criticize, there was a good chance they didn't really know the language. or were not particularly critical developers.
Granted it's still a terrific question -- expository about the applicant, and easy to banter about to detect bullshit / plagiarism.
Argh. I hate catching typos in my own comments.
"You're in the desert, you see a tortoise lying on its back, struggling, and you're not helping -- why is that?"
'Do you make up these questions? Or do they write 'em down for you?' ~ http://www.imdb.com/title/tt0083658/quotes
You must be able to criticize what you love to be a good programmer.
Yes, it would bait idiots who "don't like C because you can only define variables at the top of a function", or "don't like Java because you have to put classes in different files" -- but that's intentional.
As in 11 not-real languages. Languages that don't exist?
I'm not sure I follow.
I never end up using Perl, the niche it occupies between shell and python is empty for me. I never have a problem with a shell script where I'm wishing for more control structures or builtins. The few times I've written long-running resource-intensive shell scripts (like brute-forcing an MBR partition scheme), reducing the number of forks wouldn't make them more than a few percent faster.
The major ray of light shining down on Ruby is that it is a Perl that people want strongly to write better looking code in. That's a pretty big accomplishment, I think. It seems like a lot of the classic Perl webdev shops are moving to Ruby, and I think that's pretty great.
I don't hate Ruby, I'm just disappointed in it.
Check for the existence of methods before adding them. Don't overwrite existing standard lib methods. If you do overwrite one, alias it, call the alias from your replacement which should add something without noticeably changing the original behavior.
If you write unit tests, it shouldn't be too difficult to detect that a library you depend on has changed the behavior of a standard method in an unacceptable way. I've encountered collisions like this, maybe, a handful of times and each time finding and resolving the problem was not difficult.
I've been writing ruby software for several years now, and there are definitely libraries that annoy me (ahem activesupport), but the utility of having open classes has far outweighed any of the negatives. Let's face it, in any programming ecology there are going to be some awful libraries. Bad programmers don't need open classes to do damage.
In Lisp, extending the built-in functions is trivial, so lots of people built Lisp up into the language to solve their problem in, and Ruby makes it easy to do the same. Rails is extends the language, and some people like it. Even the JSON gem does -- when you do "require 'json'", you give arrays the power to convert themselves to json strings. Ruby lets you convert arrays to Ruby-evallable strings, so it's natural to convert them to JSON-parseable strings.
So, do you do what Java does, in making the String class final? Languages only exist for people who speak them, so you need to gauge the social aspects whenever you choose a language. Perhaps Java means that your bozo coworker won't trample your toes. Perhaps Haskell means that you can import just as much as you want. That's ultimately your call.
There are lots of valid complaints about Ruby 1.8: the syntax can be baroque, the scoping rules have too many gotchas, they're (thinking of) taking out continuations in the next version, the VM is dog-slow. But 200 methods on an object is small fries in comparison.
Seems like the implicit argument is that Root-Object modifications are unmaintainable. But the reality is that assertion really isn't backed up anywhere.
There are lots of valid complaints against Ruby. This is not one of them.
Here, look at RDoc's features (from the RDoc website):
--Generates structured HTML documentation from Ruby source. --Authomatically extracts class, module, method, and attribute definitions. These can be annonated using inline comments. --Analyzes method visibility. --Handles aliasing. --Uses non-intrusive and implicit markup in the comments. --Readers of the original source needn't know that it is marked up at all.
Or to come at this from a slightly different angle, don't Ruby's introspection powers provide a release valve for the problems the author is talking about?
Anyway, this is just another occasion to state the old adage, "With great power comes great responsibility." You don't have to crapify your Ruby projects if you don't want to. If you need to enforce clarity at all times, I see no better alternative than Python (which I think makes it a better candidate for scientific or math-intensive projects, MRI slowness aside [although I am curious about the implications of genetic algorithms + Ruby introspection]).
I do speculate that if you take two programmers of equal skill levels and give one Python and the other Ruby, the Rubyist can gain a productivity advantage over the Pythonista via judicious use of Ruby hackery. But this comes at a cost: it does require more thoughtfulness before execution. Maybe you don't want to think that hard, and that's a totally legitimate and respectable position. In the end, which of the two languages you choose will probably have more to do with personal workflow preferences or project management ideologies.
In the case of Rails, yes, it hacks in a DSL and extends Ruby classes, but Rails relies heavily on conventions and things being put in designated areas. It's therefore hard to get lost in a Rails project unless you really have no respect for the conventions (in which case, it doesn't matter what language or framework you're using).
That is just one example, but I suppose it is more attitude than necessity that makes the difference here...
Python supports both object methods and functions. Ruby only supports object methods. However, Ruby does allow you to define methods outside of an object - these become methods of the Object class. As such, any methods defined like functions become changes to all objects since they inherit from Object.
Python is also very explicit about its namespacing and imports. In Python, you should always be able to know where any name you're using is coming from. In the example from the article, 'to_yaml' is added by requiring rubygems. That isn't so apparent (in the way that 'gem' being added by requiring rubygems would be apparent). Names are reused all the time. Names sometimes aren't related to their package in an apparent way.
With Python, you have three options (one of which Python programmers will flog you for): from package import name, name2 import package from package import * -- should really only be used in an interactive python shell and not in programs
In the first one, you could then call name(something) or name2(something). BUT you can see exactly where those names are coming from -- package. Unlike to_yaml which could come from wherever, it's explicit that it comes from 'package'. In the second one, you can do package.name(something) and the like. Similarly, you can see that it comes from 'package'.
Ruby is really flexible, but I would argue that the author is correct in assessing that the ability to modify all objects implicitly is a bad thing.
Not only isn't this considered a bad idea in the Ruby world, but it's actually a common technique. Use a third-party library, and you may well be re-writing core parts of the language. Sound good? You can't prevent it.
I like parts of Ruby; it's a fun language. But the author is right -- it's not a language for large projects, or projects with more than a few programmers. My alternative to Ruby would allow the fast-and-loose stuff that makes Ruby fun, but also give you a way to make classes immutable and guarantee data-hiding and encapsulation when you need to do real software engineering.
Java's strict hiding has made my life more difficult in a number of situations. Recently, I needed to change the way URLConnection worked. I could have fixed the problem by changing a private attribute, but no no, you can't do that in Java. Instead I had to write 3 additional classes to set everything correctly for me. This is not good software engineering practice, it is a waste of my fucking time. (This was a one-off script, not a large program. Yes, I know, too many hacks and your app falls apart... but with Java you end up with an app that is falling apart AND a shit-ton of useless code to wade through.)
Anyway, if you think Java-style programming is "real programming", that's great. We don't need to work together, so you are free to waste your time however you like.
Here's a random idea: rather than strict locks, perhaps transparency would be a good approach. Load up a third party library, and you get informed that it's fiddling with things, and can then find out what. Maybe it really does need to fiddle with things. Or maybe in a given situation, fiddling with things is the most efficient way of accomplishing something.
You can achieve immutability in ruby: http://scie.nti.st/2008/9/17/making-methods-immutable-in-rub...
You can achieve data-hiding if you really need to in ruby using the same techniques you use in JavaScript.
Obviously, you wouldn't want to enable this feature on a production server. But it might be a useful debugging tool. Worth a try, anyway.
Such a thing would only help in tracking down problems. It wouldn't resolve the larger problems of, e.g., namespace collision. ("Oops, library foo and library bar both tried to define an Object.stupify() method!"), though it might make such issues easier to detect. And it would be quite easy to write perverse programs that would defeat my proposed debugger thingy, or even cause it to melt. ("My program uses singletons to dynamically redefine methods on other singletons.") But you could perhaps mitigate the latter by restricting this tool to monitoring Ruby's built in classes, and/or whatever classes the user specifically chooses to aim it at. Moreover, if a piece of Ruby code did cause the metaprogramming-tracker to dump core, that fact might serve as a valuable code smell of its own.
Yes, the very same thought occurred to me. Set a monkey to catch a monkey!
I didn't suggest it myself, because I've been away from Ruby just long enough that I didn't remember whether one could accomplish this in pure Ruby, or if one would have to ascend up a level and do it in the interpreter.
Don't get into this endless programming languages war.