Funny, some Rubyists are stupider than a piece of wood
This one for example. He proposes a simple way to make Java developers angry, by showing them some code. His example is
File.open('server.cert').readlines[1..-2].join.gsub(/\n/, '')
and throws a challenge:
Anyhoo, all you have to do now is find someone who uses a big stupid language and throw an example like above to their face and tell them to beat it. See if they can write it more elegantly using their language. The beauty of the trick is that there’s no way in this world that’s gonna happen.
My 20min Java version looks like this - more or less identical:
File.open("server.cert").readlines(1, -2).join().gsub("\n", "")
Poor blogger, another fanboy without a clue who confuses languages and API design - in this case method chaining.
Because there’s a very high probability that the other person, yes, the one who’s using a big stupid language, will get so angry and beat you up.
Nope, I just write the code in Java. That’s all.
(Beside that, the oneliner is hard to read, hard to maintain, hard to reuse. Fine if your the sole developer in a project, bad if there are 50 others who need to maintain your code. I’d prefer a CertStripper ;-)
(As a second side node, where is the fluent interface to google collections, I’ve needed one today)
Update: Someone wrote a comment to the linked blog post by copying parts of this post. And because someone asked: No this cannot be done with the JDK, therefor it’s an API problem. You need to write some code on your own to fluently wrap JDK classes. See the mentioned fluent interface link above to see how this can be done to an existing API.
“My language can beat up your language” is a game played by school kids. Adults are busy putting bread on the table, and will gladly reach for whichever language does that best today. If it’s Ruby, fine. If it’s Java, that’s fine, too. And if it’s not Java, but the boss is paying better for Java today, then… well… I like bread on the table. Because it’s a grown-up world out there, full of Turing complete languages that are mostly good enough to do the job, and that all pretty-much suck in varying ways and are pretty-much great in other ways. I do have my preference, as we all do, but that preference doesn’t make my favorite language necessarily better. It makes it comfortable and broken in, like a favorite pair of shoes. It doesn’t give me blisters anymore.
The most important thing about a language and a platform is that you know it well. Because the language that you know very well is mighty and powerful, no matter how much it sucks compared to the much better one you don’t know at all.
Chuck Yeager said, of pilots and planes, “It’s the man, not the machine.” It’s just as true of programmers and languages.
August 28th, 2008