Issue #15991 has been updated by shevegen (Robert A. Heiler). > I thought such an issue would've already been discussed but > no number of searches allowed me to find a similar request. I think this has been discussed before - I can not point to another issue request for this, though, so perhaps I misremember. I also don't remember why "?" are not allowed as a trailing part for variables. = > IMHO, it would make for more coherent design to allow it, just > like we do in method names. I do not see why this would make the design more "coherent". I understand the flexibility-approach, but I don't see why this would make the design more "coherent" or "consistent" per se. > 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 <=3D=3D> a?(5)), so this change wouldn't disrupt any > current behavior I think this is a backwards-incompatible change so introduction would require more thought. > 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"). I do not see why adding "?" to variable names as such would require to add "!" as well. I often don't fully understand why this is said either. As far as for method names, I like "?", but I dislike "!" quite a = bit. People use/abuse the latter a lot. I have seen code like for optparser that goes about: def foobar # do stuff here end.parse!(ARGV) I don't like that style of code layout. Then again what people prefer is a lot up to an individual preference. zverok wrote: > Could (ideally) became class Task def initiailize(name, ready?) @name, @ready? =3D name, ready? end attr_reader :name, :ready? end I dislike such a "new" style too. :-) By the way, I copy/pasted your example, and you mis-spelled "initialize". Good thing the did-you-mean gem can warn about this ... I have had similar typos too, usually when writing "intialize". ;-) > Generally, it will be a step towards identifiers uniformity You can of course ask what style is the "best" one; or that ruby should allow any arbitrary syntax, for variable names, methods and so forth. Personally I much prefer the current behaviour and am slightly against this proposal - but I am not totally against it either as I understand the rationale (for more flexibility that is; not the part about "coherent" or consistency or something abstract like that). One drawback of this proposal, if implemented, will be that people would no longer know whether: foo? Is a variable; or a method call. Right now they know that it must be a method call. Again, we can see pros/cons either way, but we need to mention cons too. I am pretty sure that this would be a backwards-incompatible change, though, so this probably has as a target point ruby 4.0 or so ... :P Ultimately you only have to convince matz about it, but although I can not pinpoint to older issue requests, I think this has come up before; perhaps on the mailing list or something like that. ---------------------------------------- Feature #15991: Allow questionmarks in variable names https://bugs.ruby-lang.org/issues/15991#change-79216 * Author: aquaj (J=E9r=E9mie Bonal) * Status: Open * Priority: Normal * Assignee: = * Target version: = ---------------------------------------- Hi, I thought such an issue would've already been discussed but no number of se= arches 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 l= ogic, 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 =3D=3D halting)) # ... end ``` becomes ``` last_node =3D self.node? && self.terminal? halt_on_node =3D halting && (value =3D=3D 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 on= e?"). 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 si= lly since we're in ruby and used to seeing `?`s for predicates. = Trying to assign to a questionmarked variable (`a? =3D true`) raises a `Syn= taxError`. IMHO, it would make for more coherent design to allow it, just l= ike we do in method names. I was afraid that `variable?` would be already parsed as beginning a ternar= y expression (`variable?1:3`) but this isn't parsed either, the only thing = it's used for is for method calls (`a?5 <=3D=3D> a?(5)`), so this change wo= uldn'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 allo= wing `!`s in variable names too, which I'm not sure makes a lot of sense (u= nlike `?` which denotes "booleanness", a trait shared by variables and meth= ods alike, I can't see how a variable would be "dangerous"). -- = https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>