> On Sunday, 25 December 2022 at 02:34:35 UTC+11 Doug Kearns wrote: > > > On Mon, 19 Dec 2022 at 00:33, Bram Moolenaar <br...@moolenaar.net> wrote: > > > >> > >> One thing I'm not yet sure about is the declaration. Currently it works > >> like this: > >> > >> this.name: string > >> this.gender: Gender > >> > >> Notice that there is no "var" keyword. It's not needed to recognize the > >> declaration. I can't think of a good reason to add "var" here, other > >> than that a declaration would be expected to always have "var". Well, I > >> don't have that expectation. > > > > > > This following currently defines a field and is, without context, > > indistinguishable from any other assignment. Is that intended? > > > > this.name = "Somebody" > > > > Is that right? if that's a declaration as well, shouldn't that include the > type? > I thought that the declaration would be like this; > > this.name : *string *= "Somebody" > > Or is auto-type detection at play here too?
It's called type inference. The type of the expression is used as the type of the variable. In most cases this works very well, keeps it short and it's obvious what the variable is used for. What it does not work well for is when using an empty list or dictionary. > >>> For class members most languages use the "static" keyword. It's a bit > >> of a weird word, but I suppose most people are used to it, and I can't > >> find a popular language that has a good alternative. > >> > >> If we leave out "var" for object members, I suppose we should also leave > >> it out for class members. We then get: > >> > >> static oneClassMember: number > >> static twoClassMember: string > >> > >> I think this looks fine. Any objections? > >> > > > > It seems from the documentation that static fields can be referenced as > > bare identifiers? This feels a bit unexpected to me given that instance > > fields are always qualified. > > Just sharing another idea - perhaps also require "*static.*" as the class > scope prefix, and enforce it - for all the same reasons that "*this.*" > would be enforced as the object scope prefix. I don't know a language that does this. As I mentioned, the word "static" is a bit strange anyway, using it in more places makes that worse. > Alternatively, perhaps we could use the actual class name as the enforced > prefix for static class scoped variables. Either option would avoid > confusion with inner function variables. Some languages use the class name as a prefix for class members. Outside of the class this makes sense, it's like a scope name. Inside the class, however, using the class name is more duplicating what you already know. With inheritance the question comes up if the current class name or the parent class name need to be used (maybe both work?). And class names have a tendency to be quite long. There is also some similarity of using a script-local variable in code and functions inside that script. We currently don't use a prefix, and that works fine. I can predict that using class members inside the class can work without a prefix without a problem, just like using script-local variables. > Either way, it seems consistency is important here. > > The following is all over the place; > > var static oneClassMember: number > var static twoClassMember: string > this.threeObjectMember: number > this.fourObjectMember: string Using "var" is either for both or none, this mix is not making sense. > I think that the following also looks inconsistent; > > static oneClassMember: number > static twoClassMember: string > this.threeObjectMember: number > this.fourObjectMember: string Class and object members *are* different, thus I don't think consistency is important here, or even a goal. > I think the following is better, more consistent, and this would be my > preference; > > static.oneClassMember: number > static.twoClassMember: string > this.threeObjectMember: number > this.fourObjectMember: string This goes against the syntax we know from any other language. Using "static" as a prefix looks weird to me. > I don't mind var, but I don't see a real need for it either, because the > declarations will have the type name included. Anyway, if going to use > var, please keep it consistent, eg like this; > > var static.oneClassMember: number > var static.twoClassMember: string > var this.threeObjectMember: number > var this.fourObjectMember: string Whether to use "var" or not was also part of the discussion. It does make it clearer that we're looking at a declaraction. But otherwise the "var" keyword is not actually needed. I also wonder if it should be "var static oneClassMember" or "static var oneClassMember". Just using "static oneClassMember" avoids that. That still leaves open the possibility to use: static oneClassMember: number var this.oneObjectMember: number Or: static oneClassMember: number this.oneObjectMember: number -- Mental Floss prevents moral decay! /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- 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/20221225154106.749321C0AA4%40moolenaar.net.