top | item 44282914

(no title)

Hnus | 8 months ago

You don't miss things like enums, exhaustive switch or any other basic language features? How about `method_missing` its such a crazy idea to me that something like this exists, I know why it exists but I am like why, why such bloat and complexity.

discuss

order

RangerScience|8 months ago

Ruby inheritance is a list of class names. When you call a function on an object, Ruby goes up that list, looking for the first one that defines that function.

If it doesn't find any class defining that function, it calls `method_missing` (and again, goes up the list). The Ruby base object class defines `method_missing`, so if no-other classes in the ineritance list do, you get that one (which then throws the usual error).

IMO, there is zero bloat or complexity added by this; it's super simple language bootstrapping (allowing more of Ruby to be written in Ruby, vs the c interpreter).

What do you see as the bloat and complexity added by this?

PapaPalpatine|8 months ago

No, I honestly don’t. I can emulate an Enum without having an Enum type. I rely less on a compiler and more on myself with automated tests.

andrekandre|8 months ago

  >  rely less on a compiler and more on myself with automated tests
jme, but i think this is a muscle that a lot of people don't have developed if they came from a language/toolset/ide that does automatic type checking and autocomplete reliably etc

adhamsalama|8 months ago

Part of the problem is when you have to rely on someone else.

rubyfan|8 months ago

Can you elaborate on why you think method_missing is bloat?

Hnus|8 months ago

As another commenter said,

> it’s about your taste and philosophy.

Personally, method_missing goes against both of mine. It makes programs harder to reason about, more difficult to debug, and nearly impossible to `grep`. That said, I understand that this kind of flexibility is what some people like. I just don’t.