Ruby: drop the superiority complex, give us a damn final keyword
Sorry. I know that headline is a little inflammatory, but after reading comments about legitimate complaints against Ruby, it’s needed. Don’t get me wrong - I love Ruby. It’s a huge step up compared to Java, C++, or VB/C#.NET when it comes to expressions. What’s 20 painful lines in J++# is 2 in Ruby, and much easier to read. But it’s time to realize that it’s a language - not a religion. It has bad things about it.
If you’re coming in for an interview, and somehow come across my name (I don’t name companies on my blog), then here’s a heads up. I’m going to ask you what you don’t like about Ruby. Here’s a fantastic answer: their handling of constants, and the built in clone function, both suck and are misleading.
You should not be able to modify a constant value. If you want other developers, or you, to modify it, don’t make it a constant. This is a fundamental dearth in Ruby: the inability to lock down constants. Sure, you get a warning. Sometimes.
One of the comments on Steve Yegge’s blog about this issue? “Ruby is for good programmers who know what they’re doing.” This is ridiculous red herring if I’ve ever seen one, and I’ve seen some huge ones. The problem is, you don’t always know what you’re dealing with, and it can be a reference to a constant, and you shouldn’t have to do any sort of check to modify that. You should get an immediate error.
I’m ranting about this because it cost 2 developers and entire afternoon hunting down yesterday.
Anyways. Sure, nobody’s going to see “oh, they defined PI to 3.14159″ (that’s all I know from memory of Pi) and think “let’s redefine it to 4″ (unless you live in Missouri.) But people could think that changing @var is ok, when they’re in a view and the variable came from a controller. Why would they know that @var is actually a reference to PI, and by adding 1 to it, they’re fucking up the math for ALL 10TH GRADERS, WORLDWIDE?
“Oh, but Terry, you idiot! You can freeze an object!”
Uhuh. Except, say, Hash#merge doesn’t respect freeze. It doesn’t even provoke a warning.
This is retarded. It comes off as an afterthought of the language developers, and as a consequence leaves us multi-developer teams slightly screwed. Constants have meaning, and if they don’t, drop the charade and just treat ALL_CAPS variables as normal. A mindless warning showing up in who-knows-what logs isn’t going to help anybody.
Bottom line, languages need a way to define a const. A great way to write code is to do it in such a manner that people can’t misunderstand or violate your class’s internals. Constants provide a fantastic way to do that. In fact, in Java, atomic consts are even replaced on the first pass of the compiler, meaning there’s NO WAY WHATSOEVER that they get affected. Ruby needs this, and to say otherwise is to admit either a super small (read: “1″) team bias or intellectual dishonesty.
Jimmy said:
Oct 08, 08 at 10:32 pmMeanwhile, in a dark space beneath downtown Chicago, faceless men draped in black robes decide your fate.
terry said:
Oct 09, 08 at 8:48 amDon’t larp on my blog noob.
meezy said:
Oct 09, 08 at 11:30 ampublic static final String WHO_IS_GAY = “terry is gay”;
Hah! Its a constant, you can’t change the fact that you are gay. And its public for all to see.
Three things:
1)I think it makes me the gayest by commenting on a blog post using java code to attempt humor.
2)It is even gayer that I had to describe the humor in it rather than letting the code stand alone as the joke.
3)I’m probably offending homosexuals by using ‘gay’ as a generic replacement for ‘insert derogatory name of choice here’. Not my intention.