From: zverok.offline@... Date: 2019-07-08T10:13:59+00:00 Subject: [ruby-core:93614] [Ruby master Feature#15991] Allow questionmarks in variable names Issue #15991 has been updated by zverok (Victor Shepelev). If this proposal will not cause some serious conflicts, it seems to be also useful for those cases: ```ruby class Task def initiailize(name, ready) @name, @ready = name, ready end attr_reader :name def ready? @ready end end ``` Could (ideally) became class Task def initiailize(name, ready?) @name, @ready? = name, ready? end attr_reader :name, :ready? end ``` Generally, it will be a step towards identifiers uniformity (because "extract local variable to method" and vice versa is pretty usual refactorings, and for boolean methods `foo?` is a common and linter-enforced convention, but for boolean locals it is impossible to use). ---------------------------------------- Feature #15991: Allow questionmarks in variable names https://bugs.ruby-lang.org/issues/15991#change-79213 * Author: aquaj (J�r�mie Bonal) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hi, I thought such an issue would've already been discussed but no number of searches allowed me to find a similar request. Feel free to close if I missed a previous refusal. From time to time, especially when trying to clear up complex conditional logic, I find myself wishing I could add `?` to variable names, since I got used to it while naming methods. For example, currently: ``` if (node? && terminal?) || (halting && (value == halting)) # ... end ``` becomes ``` last_node = self.node? && self.terminal? halt_on_node = halting && (value == halting) if last_node || halt_on_node # ... end ``` `halt_on_node` is clear enough, but `last_node` feels like it would contain a node, instead of expressing its actual purpose ("is the node the last one?"). Right now a developer would have two options as I see them: 1 - extract the conditional to a method `def last_node?` which can be a bit much if it's the only place this code is called. 2 - rename the variable something like `is_last_node`, which feels a bit silly since we're in ruby and used to seeing `?`s for predicates. Trying to assign to a questionmarked variable (`a? = true`) raises a `SyntaxError`. IMHO, it would make for more coherent design to allow it, just like we do in method names. I was afraid that `variable?` would be already parsed as beginning a ternary expression (`variable?1:3`) but this isn't parsed either, the only thing it's used for is for method calls (`a?5 <==> a?(5)`), so this change wouldn't disrupt any current behavior, the expression would just be looked up like any other call instead of only looking up methods. The only thing I can see with this is that it might raise the issue of allowing `!`s in variable names too, which I'm not sure makes a lot of sense (unlike `?` which denotes "booleanness", a trait shared by variables and methods alike, I can't see how a variable would be "dangerous"). -- https://bugs.ruby-lang.org/ Unsubscribe: