attr_protected, attr_pubpro, attr_Rw

Skip to first unread message

Felix von Ferey

Jul 28, 2015, 2:52:15 PM7/28/15

I'd like to solicit comments on the following issue:

Consider this class
class Foo
  attr_accessor bar:Bar
  attr_accessor baz:Baz
and now suppose the generated setter methods (Foo#bar=(), Foo#baz=()) should be made protected (such that only the getter methods are public). This pattern is very common. Hence, a macro abstracting this pattern should be part of the Mirah standard library. But how should the macro generating this be called?
  1. attr_protected ("protected" refers to the setter. The getter is still public.)
  2. attr_pubpro (meaning "pub"lic getter, "pro"tected setter)
  3. attr_Rw ("R" means public read, "r" means protected read, "W" means public write, "w" means protected write. The asymmetry in the capitalization mirrors the asymmetry in accessibility. As the characters '_' as well as 'R' are usually typed with the "shift" key held, there is actually no extra work when typing "attr_Rw" compared to "attr_rw".)
  4. [enter your suggestion here]



Sep 9, 2015, 10:30:11 AM9/9/15
to The Mirah Programming Language,
Sorry for later reply.

Proposed options are merely a shortcuts for:
class Foo
  attr_reader bar:Baz
  protected attr_writer bar:Baz

IMHO declaration above more clearly states what is declared. Also consider an option one need private writer or private final writer or any over combination.

I vote for:
#4 do not provide that kind of shortcuts in the std library. 

Consider another issue with this approach - it could greatly complicate code completion support for IDE.

I have already rised
Reply all
Reply to author
0 new messages