From: "Eregon (Benoit Daloze)" Date: 2022-07-30T11:32:33+00:00 Subject: [ruby-core:109382] [Ruby master Feature#18930] Officially deprecate class variables Issue #18930 has been updated by Eregon (Benoit Daloze). @Dan0042 It seems likely you might not know well their semantics then and how much a trap they are. Using @byroot's example from https://bugs.ruby-lang.org/issues/14541#note-25: ```ruby class A @@foo = 1 def self.foo @@foo end end class B < A @@foo = 2 # actually writes in A end p A.foo # => 2, but should be 1 ``` And if one does not write to them then constants are a much better choice. Could someone point to a gem using class variables where it is not fairly easy to replace them with instance variables? Or even better, a gem where the semantics shown above are actually desirable? I believe nobody wants these semantics (it's buggy behavior, if one wants that they might as well use an instance variable on a given class+accessors or a global variable), hence class variables should be discouraged or deprecated as they are just likely to cause bugs and are not necessary (plus, they look like a Perl mess of sigils). Because fixing their semantics is deemed too incompatible (#14541), then deprecation seems the only way to avoid people running into these buggy class variables. ---------------------------------------- Feature #18930: Officially deprecate class variables https://bugs.ruby-lang.org/issues/18930#change-98532 * 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: