So, instead of using the "this." prefix, vim9 could specify that member
variable names must either use the @ prefix for public, or use the _ prefix
for private. ie., all member variable names must have one of these two
prefixes. I think this is worth considering, because it's simple, clear
and explicit. You no longer need the following keywords; "this", "public"
and "private".
Sorry, one more idea to float... I was thinking that the "@" prefix looks
a bit odd, so, is there any reason we couldn't simply prefix public member
variable names with just period "."? So, instead of writing "this.xyz"
everywhere, just write ".xyz"
And just use the underscore "_" prefix for private member variables.
To show what I'm thinking, at the moment you have this;
class TextPosition
this._lnum: number
this._col: number
public this.depth: number
def new(lnum: number, col: number, depth: number)
this._lnum = lnum
this._col = col
this.depth = depth
enddef
def SetLnum(lnum: number)
this._lnum = lnum
enddef
def GetLnum()
return this._lnum
enddef
def SetCol(col: number)
this._col = col
enddef
def GetCol()
return this._col
enddef
def GetVolume()
return this._lnum * this._col * this.depth
enddef
def SetPosition(lnum: number, col: number, depth: number)
this._lnum = lnum
this._col = col
this.depth = depth
enddef
endclass
The idea I'm floating for consideration, is that we could simplify it to
something like this;
class TextPosition
_lnum: number
_col: number
.depth: number
def new(lnum: number, col: number, depth: number)
_lnum = lnum
_col = col
.depth = depth
enddef
def SetLnum(lnum: number)
_lnum = lnum
enddef
def GetLnum()
return _lnum
enddef
def SetCol(col: number)
_col = col
enddef
def GetCol()
return _col
enddef
def GetVolume()
return _lnum * _col * .depth
enddef
def SetPosition(lnum: number, col: number, depth: number)
_lnum = lnum
_col = col
.depth = depth
enddef
endclass
The advantages of this are;
1. It removes the need for "this." everywhere.
2. It's obvious when the member variable is public or private, wherever
you read it,
3. The dot prefix looks a bit more natural than "this." prefix everywhere,
and
4. The dot prefix nicely reflects similar to how it is accessed outside
the class
The usage from outside the class hierarchy would be the same;
var text_pos = TextPosition.new(3, 5, 8)
var text_pos_l = text_pos.GetLnum()
assert(text_pos_l, 3)
text_pos.SetLnum(text_pos_l + 1)
text_pos_l = text_pos.GetLnum()
assert(text_pos_l, 4)
var text_pos_c = text_pos.GetCol()
assert(text_pos_c , 5)
text_pos.SetCol(text_pos_c + 1)
text_pos_c = text_pos.GetCol()
assert(text_pos_c, 6)
var text_pos_d = text_pos.depth
assert(text_pos_d , 8)
text_pos.depth += 1
text_pos_d = text_pos.depth
assert(text_pos_d, 9)
var volume = text_pos.GetVolume()
assert(volume, (text_pos_l * text_pos_c * text_pos_d))
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/3f966524-130c-4a81-8a68-fc531883cca5n%40googlegroups.com.