From: "zverok (Victor Shepelev)" Date: 2022-07-31T16:15:09+00:00 Subject: [ruby-core:109395] [Ruby master Feature#18930] Officially deprecate class variables Issue #18930 has been updated by zverok (Victor Shepelev). (Playing for both sides here, hehe) Actually, I believe that the culprit might be just the name. E.g., we have two camps, basically saying: 1. The behavior of [however it is named] is useful, and it matches my expectations of [this thing], here are usages 2. The behavior of what we call "class variable" doesn't match the expectation of a thing called "class variable," and therefore, it is confusing and hard to use right. (I still remember the confusion I had when I just studied Ruby and understood that classes are objects too and can have their own _instance_ variables, and how those are different from _class variables_, etc.) That being said, as far as I can Google, "static variables," say, in both C++ and Java, are shared with subclasses, but _defining_ the static var with the same name in the sublcass "shadows" the parent's one. In Ruby, the distinction between "whether we are defining it" or "whether we are assigning to the existing thing" is murky for variables, so... While I still believe what I said above (that class vars is not the best tool for any task), I wonder where the concept of "it should not be shared with subclasses, looks surprising/like a bug" comes from? Maybe just because _the name_ implies it, somehow?.. Maybe changing the name to "class shared variables", or "hierarchy variables", or something like that would change the mental model. ---------------------------------------- Feature #18930: Officially deprecate class variables https://bugs.ruby-lang.org/issues/18930#change-98546 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal ---------------------------------------- Ruby's class variables are very confusing, and it seem many people agree they should be avoided (#18927). How about we deprecate them officially? Concretely: * Mention in the documentation that class variables are deprecated and should be avoided/should not be used. * Add a parse-time deprecation warning, now that we only see those with `Warning[:deprecation] = true` it seems reasonable to add. -- https://bugs.ruby-lang.org/ Unsubscribe: