From: "austin (Austin Ziegler)" Date: 2022-07-31T00:24:27+00:00 Subject: [ruby-core:109390] [Ruby master Feature#18930] Officially deprecate class variables Issue #18930 has been updated by austin (Austin Ziegler). jeremyevans0 (Jeremy Evans) wrote in #note-10: > austin (Austin Ziegler) wrote in #note-9: > > If we���re going to deprecate them, we need something that effectively replaces them���and class instance variables aren���t it. > The particular approach given may not work (I don't see how it tries to replace class variables), but that doesn't mean you cannot replace class variables with class instance variables. There are a couple approaches, depending on the behavior you want. It doesn���t���as such. This was something I coded up and was *surprised* that it didn���t work the way that I expected, and exploring it resulted in the understanding that I have. The *intent* that I had was very much one where I got the behaviour from a class variable instead of a class instance variable. Both suggestions you made would absolutely work, although if this were something that I exploring further, I���d be doing much more work on it (probably building out a bit of a DSL; for what I���m writing, it���s overkill). zverok (Victor Shepelev) wrote in #note-11: > > but `Rand.dependents` producing `{1=>V1}` and `Timestamp.dependents` producing `{2=>V2,3=>V3,4=>V4}`. > > I can easily imagine it as a _desired_ outcome (e.g., "every non-Vx class is root for its own list of versions, and stores them independently"). Possible, but IMO unlikely. Note that I���m in favour of officially deprecating class variables, but this is *one* scenario where the use of a class variable instead of a class instance variable provides a desirable effect with minimal code compared to replicating the behaviour with class instance variables. I think that all three of the workarounds (`Base.dependents` or either of Jeremy���s) are *less clear* in their intent and that the default behaviour is *unexpected*. Not wrong, but surprising. One of the reasons I still like writing Ruby is there���s very little *ceremony* / boilerplate. For this advanced use, it would be nice to have that remain the case. ---------------------------------------- Feature #18930: Officially deprecate class variables https://bugs.ruby-lang.org/issues/18930#change-98539 * 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: