On Monday, 19 December 2022 at 19:52:34 UTC+11 Christopher Plewright wrote:
> I'm not a big fan of the "this" keyword. I agree if going to use it, > ensure to use it everywhere. Consistency is good. I like simplicity, and > dislike redundancy. > > So, about "this", alternatively, don't use it anywhere, but maybe you > could throw an error if a function argument name is also member variable > name. Not sure what static analysis is available - given that its a > scripting language. There's not really a compilation step is there? > > OR, perhaps another option, just thinking outside the box, if a function > argument does actually happen to match a member variable name - then > automatically force it to actually set that variable. When (if) this > becomes the expected behavior, I think it would enable simplifying some > things a lot. > > Explaining with an example. Often, when I'm coding and the arg name is > the same as a member variable name, then I usually find myself setting > that early-ish in the code. (just using a pseudo code to explain, > obviously not real code;) > > class Blahh > this.toX: TYPE_A > this.toY: TYPE_B > fn SetXandY(toX: TPYE_A, toY: TYPE_B ) > this.toX = toX > this.toY = toY > enfunc > endclass > > So, I find that pattern happens a lot. And it gets real tedious. I > think this could be simplified to the following; > > class Blahh > toX: TYPE_A > toY: TYPE_B > fn SetXandY(toX, toY) > enfunc > endclass > > ie. This would set the member variables, toX and toY automatically. > > Now, we might want to do some sanity check on the argument before > clobbering whatever was in there previously. The developer could very > easily use another temporary name, for example prefixed with p_ as they > wish, and check it is in range for example, before setting it. Like so; > > class Blahh > toX: TYPE_A > toY: TYPE_B > fn SetXandY(p_toX, toY) > if p_toX in range > toX = p_toX > else > ignore, or throw, or set some default, whatever for toX > endif > enfunc > endclass > > In this last example, any matching names could be automatically set, so > here, the toY would be automatically set. > > > This is inspired by your idea from the constructor idea you had here; > def new(this.lnum, this.col) > enddef > > I like that one :) > > Cheers, > > Chris Plewright > > >> 1. Sorry for top posting. I'm still learning to navigate the google groups platform. 2. typo: toX: TYPE_B was meant to be toY: TYPE_B Hope my idea is still readable. Have fixed that in this reply anyway. -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/04cd3cac-3895-4be2-804b-9f87b0ad3bb7n%40googlegroups.com.