ponylang / rfcs

RFCs for changes to Pony
https://ponylang.io/
61 stars 48 forks source link

access symbol of private fields is wrong #206

Closed lyrachord closed 1 year ago

lyrachord commented 1 year ago

By design, What does the leading underscore _ mean? It means something is private.

Look,

class Wombat
  var _hunger_level: U64
  fun ref set_hunger(to: U64 = 0): U64 => _hunger_level = to

equivalent to the following

class Wombat
  var private_hunger_level: U64
  fun ref set_hunger(to: U64 = 0): U64 => private_hunger_level = to

here, the leading underscore _ does not mean that something is private. It does means private prefix from a syntax view. In deed the above code should be corrected like the following

class Wombat
  var hunger_level: U64
  fun ref set_hunger(to: U64 = 0): U64 => hunger_level = to

OK, someone gets the point, but one would say, how about cases with name conflict? f.e.

class Wombat
  var x: U64
  fun ref set_hunger(x: U64 = 0): U64 => x = x

Some languages introduce a solution with scope limition.

class Wombat
  var x: U64
  fun ref set_hunger(x: U64 = 0): U64 => this.x = x

So absolute pretty good bad boilerplate!

Solution: affix again! prefix or suffix, it denpends. Experiences, preferences, wisdom, balance and coordination, from designer. f.e.

class Wombat
  var x: U64
  fun ref set_hunger(x: U64 = 0): U64 => x! 
  fun ref set_hunger(x: U64 = 0): U64 => @x 

BTW, in the language design domain, old school teachs that how other languages works, but there is no lesson that you can not override them.

SeanTAllen commented 1 year ago

This isn't an RFC nor a request for someone to right one.

If you can explain something you would like someone to write an RFC for, open an issue and maybe someone will (but probably not).

Otherwise, please follow the RFC process and write an RFC.

You've open two issues today that don't follow along with our documented "how to contribute steps".

I'm going to assume good intent but if the pattern continues, I'm going to start assuming bad intent and that you are mostly interested in spamming.