Hacker News new | past | comments | ask | show | jobs | submit login

Doesn't mention how @@ is evil. @@ are not your usual class variables. @@ should be avoided in most programs.



This guide is specifically about the internals of and "hacking" the Ruby MRI -- it's not about hacking Ruby in general.

Unless there is something specific about the MRI implementation and class variables?


Yep, as Martin Fowler nicely points out in http://martinfowler.com/bliki/ClassInstanceVariable.html

"A class variable is shared across all instances of a class, which includes all subclasses". Can be surprising when using inheritance.


Well, that behavior is not surprising or anything. Many other languages have some kind of concept of a class instance variable (such as Python).


You're right saying that it's the proper behavior for such a semantic. But the problem is, @@ notation can make you forget you're not manipulating something that might be shared and re-assigning an ancestor class variable accidentally, messing up its behavior. And while it's common to check for method overrides, class variable overrides is not something that is checked very frequently.

It is the kind of bug that can be very long to figure out, since when you make this mistake, it's very likely because you forgot to think about this behavior.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: