Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby Mistakes
=============
* Using blocks for looping and callbacks
* break/next/return semantics in blocks extremely bizzare
* And they have different behavior in procs vs. lambdas
* Why on earth does defined? return a string?
* throw/catch. Why!
* Inline rescue, no ability to specify what exception (and by extension, "catch
anything" behavior common in community)
* Mutable objects have a hash method and can go in Hashes. Why!!!
* Extremely complex grammar, makes barrier to entry for implementation much
higher
* Special case of flip-flop and regexp in an if statement (only if it appears
syntactically though!)
* Setting `$=` to something truthy causes all string operations to become
case-insensitive. This and other magic globals from perl are mind blowing.
* Keywords that silently override methods by the same name (defined?, on
Rubinius block_given?)
* `f {}`. Tell me what the parsing of that is.
* proc, lambda, block, method, unbound method, functions. None of which have a
clear relationship. set_trace_func exists, even though you can't pass
functions around.
* Bizzare magic::
def f
Proc.new
end
f { |x| 3 }
How does ``Proc.new`` know where the block came from?
* Ruby's module system makes namespacing optional (and off by default).
* Regexp with named matches decompose into local variables. Dear lord why.
* Encoding system is beyond broken
* Scopes: constants, class vars, instance vars, methods, locals. wtf.
* Constants aren't constant. Truth in naming.
* Thread locals are really fiber locals.
* You can change the encoding of a string. Just jesus christ wow.
@haileys
Copy link

haileys commented Jan 17, 2013

@alex: Ah so you're a Python person?

Let's talk about __iadd__ and friends 😉. Then we can discuss other things in a passive aggressive manner.

@luikore
Copy link

luikore commented Jan 17, 2013

I just found myself love mistakes...

@skandhas
Copy link

skandhas commented Jan 17, 2013

@Hanmac
Copy link

Hanmac commented Jan 17, 2013

some 1.9 points:
$= does not work on newer ruby anymore
block variables are now realy block variables and do not overwrite the local variables anymore

@berdario
Copy link

berdario commented Jan 17, 2013

@charliesome

though I don't like __iadd__, there's nothing wrong with special methods/protocols

I guess that you dislike the underscores, but that's just part of the language: it's syntax and convention

It's no more of a burden than parentheses in lisp, or begin end in ruby...

I loathed parentheses until I dabbled more with lisp, and I dislike begin end, but I'm sure that I'd get used to them if I used ruby (or pascal, or ada) more

@apeiros
Copy link

apeiros commented Jan 17, 2013

@lucian1900
You don't want mutable hash keys? Then just. don't. use. mutable objects as hash keys. Nobody forces you to.
And again, you can also freeze your hash keys if you want.
And experience disagrees strongly with your "extremely error prone". Reality shows that mutable hash keys are rarely ever the reason for a bug.

@nathanl
Copy link

nathanl commented Jan 17, 2013

* break/next/return semantics in blocks extremely bizzare
* And they have different behavior in procs vs. lambdas

Yehuda's article here might be helpful for understanding this:

http://yehudakatz.com/2012/01/10/javascript-needs-blocks/

@nathanl
Copy link

nathanl commented Jan 17, 2013

Constants aren't constant. Truth in naming.

This is really a philosophy difference. Ruby lets you do whatever you want. You can redefine constants, access private methods, and modify core classes. All "restrictions" are advisory; the programmer is given both great power and great responsibility.

@why-el
Copy link

why-el commented Jan 17, 2013

@nathanl Yep, came here to say just that. The almost anarchic style of Ruby is why I love the language. So much respect and autonomy for the user.

@berdario
Copy link

berdario commented Jan 17, 2013

My 2 cents as a ruby newb:

This gist indeed is written in a confrontational style, but since it's "secret"... I wouldn't really complain about that: I'd guess that it simply wasn't meant to be distributed as is.

I like the information contained in it btw, while some things are indeed just a matter of taste/philosophy:

Like the unconstantness of constants: in python it's the same, but python doesn't advertise any sort of constants

So one could say: "if you cannot guarantee it, just don't put it in the syntax!" or "we're consenting adults, if you modify what should stay constant, be aware of the consequences"... both views are fine imho

Other things are plainly broken, and the fact that they're being dealt with in newer releases is both a demonstration of it and a blessing for present and future ruby developers :)

(like Hanmac said: $= and block variables, and possibly encoding from what I read about ruby2.0)

Hashing mutables seem like a defect, but still... if the class we're talking about is mostly similar to java "beans" and methods don't meddle with the state, so that you can guarantee that the state won't change on its own... it's sorta sensible to allow it

The issue is probably that purists say that you cannot really prove that it behaves like that (even if ruby wasn't dynamic, it's probably undecidable), and so you shouldn't allow it... while rubysts feel that having concise code and being pragmatic is worth the risk

Then, "Encoding system is beyond broken" isn't really helping: ranting is fine, but you should at least point out exactly what isn't working

As a newbie, I don't get the deal with throw/catch, I assume that it's just another raise/rescue like explained here ?
But with the fact that by convention it's used for flow control instead of error handling?

If so: that's a classic TMTOWTDI vs TSBOOWTDI choice... I'm with the latter, but I understand the idea

one last thing:

@apeiros

Extremely complex grammar: yes, ruby's focus is the user of ruby. get over it. If you want to implement a language that is easy on implementers, go assembly.

That misses the point imho: for a language that's easy on implementers and is still powerful you should think about lisp

In fact for many of those powerful features, it shouldn't be really needed to have a complicated grammar...

It's not something that shows day-to-day, but I think we all agree that a complicated grammar (and worse a context-dependant like C++ or Perl I guess) is a bad thing... and obviously you can build great things out of bad things, but that doesn't excuse it :)

peace

@mosesrenegade
Copy link

mosesrenegade commented Jan 17, 2013

Answer to all the whys: ruby has some beautiful flexibility. Now I'm off to watch cat videos.

@jlouis
Copy link

jlouis commented Jan 17, 2013

Those are not so much mistakes. They may be really odd design decisions with hard-to-grasp semantics. They may be problematic because they make it hard to write efficient interpreters and/or compilers. They may be a problem to compiler implementors to the point where it is almost impossible to get the language right. But I do not think they are outright mistakes.

That said, what makes Ruby so appealing to others certainly does not appeal to me. It is not an aesthetic language to me, but to others it seems to be. I think this can be compared to a discussion about paintings: if you don't like the impressionistic style, then you don't like it.

And the compiler thing is real. If constants are not constants, then the compiler cannot propagate constant values and hence performance will suffer. And this is just one example of such.

@lucian1900
Copy link

lucian1900 commented Jan 17, 2013

@apeiros You can never be certain that the the hash key you pass to a function won't be mutated. Thus, the default of only allowing immutable (or at least frozen) keys is much less dangerous. Hash could even freeze the keys on the way in itself.

@kevinsjoberg
Copy link

kevinsjoberg commented Jan 17, 2013

I see a fair about of people already argued by the majority of things in the list, so I'll just leave it there. I will make an addition to the statement about inline rescue though.

Inline rescue, no ability to specify what exception (and by extension, "catch
anything" behavior common in community)

@avdi talks about inline rescue in episode 22 of Ruby Tapas. Inline rescue might come handy if you want to evaluate the exception and act upon it. This can be done by making use of the $! variable.

@mdesantis
Copy link

mdesantis commented Jan 17, 2013

Inline rescue, no ability to specify what exception (and by extension, "catch anything" behavior common in community)

This is the worst IMHO; the others are not so bad (the one of the Regexp with named matches is bad, but is not so common), and some are just "not bugs but features" (f.e. the fact that you can change the encoding of a string).

@cogweh
Copy link

cogweh commented Jan 17, 2013

Python guy complaining that Ruby isn't Python. It shouldn't be "Ruby Mistakes". It should be "Things about Ruby I don't understand because it doesn't work the same way as in a language I'm used to".

@Nek
Copy link

Nek commented Jan 17, 2013

@cogweh If it should be "Things about Ruby I don't understand..." than could you be so kind to share a part of your genuine experience with ruby and explain those things to us, python/javascript/lisp/whatever guys.

@cacciatc
Copy link

cacciatc commented Jan 17, 2013

A corresponding Python Mistakes gist :)
https://gist.github.com/4558963

@drbig
Copy link

drbig commented Jan 17, 2013

This reminds me of the blub paradox...

@cogweh
Copy link

cogweh commented Jan 18, 2013

@Nek selective context "...because it doesn't work the same way as in a language I'm used to" This is basically frivolous bickering about the language which we shouldn't be having. The OP is clearly trying to point out what he perceives as flaws in a language without much basis. It's the same thing as saying "that car is red so it must be horrible."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment