Issue #12096 has been updated by Robert A. Heiler.


I like the idea to some extent but the syntax strikes me as somewhat
peculiar.


  @'foo?'


In ruby one has to look quite closely to spot some errors on a 
first glance; the did-you-mean-gem helps a bit but I think the
human brain also has to process a lot of syntax. I think my
problem with this here is the @. I myself do not really use @@
but I use @ a lot. But again, my reservation is not about the
idea itself, more the specific syntax suggested.

I would prefer @ to stay simple, without a lot of side effects
or shortcuts.

> And attr_reader :foo? should also be allowed.

Yes, I agree here, but I think :foo? may be easier to see too
than the @foo?. Somewhere else on ruby core, the :foo? notation will
eventually come or has been discussed about, as there were other
proposals and, I believe, no big objection against it (and probably
the parser would not have a problem with it either) - nobu does
not yet have 40 arms so he can not write all the code in a single
day. :)

I think the difference between :foo and :foo? is quite minor. The
difference between :'foo-bar' and @'foo-bar' seems a bit larger.
Or even @:'foo-bar' ... the -> and the &. lonely operator encourage
me to use them for non-serious projects, together with the unicode
snowman ... but I digress. :D

To the comparison given later:

> instance_variable_set("@#{some_expression}", some_value)
> @"#{some_expression}" = some_value

Well, version 2 is shorter, and often, being short and terse is
nice, less code to write, hopefully also easy code that is easy
to understand, and not too ugly.

But in this case, I like being explicit and it may confuse
newcomers in the second variant; for instance, they may have
to spot with their eyes that @"#{some_expression}" is 
different to "#{@some_expression}" or some other embedded
construct. And I think when I see &.->@@"foo?" it makes me
wonder what language this is! :D

----------------------------------------
Feature #12096: New notation for instance variables and class variables
https://bugs.ruby-lang.org/issues/12096#change-57088

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In order to create symbols that include non-word characters, we have the `:'...'` notation:

~~~RUBY
:'foo-bar'
:"foo-bar"
~~~

What about extending this notation to instance variables and class variables? The use case is to solve the problems raised in #12046, #11167, #10720. There, the problem was that, even though we can have methods like `foo?` or symbols like `:foo?`, we cannot have corresponding instance variables. My proposal is to introduce a similar notation for instance variables:

~~~RUBY
@'foo?'
@"foo?"
~~~

I can't think of a similar use case for class variables, but there is no reason to make class variables to behave different from instance variables more than necessary, so there can also be the corresponding notation for class variables:

~~~RUBY
@@'foo?'
@@"foo?"
~~~

Right now, these notations raise syntax errors, so I don't think it conflicts (raises ambiguity) with the existing syntax.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>