On Monday, 16 January 2023 at 07:19:29 UTC+11 Bram Moolenaar wrote:

The simplest would be that the parent constructor is always called 
first. However, it usually has arguments and those need to be passed 
somehow. 

Is there a language where this works nicely and we do it like that in 
Vim? 


Java uses the special keyword function "super()".    Also, I like how the 
Java compiler silently inserts a call to the super() constructor (the 
default no-argument constructor) into the child class constructor 
automatically if the developer doesn't manually include any call to super.  
 This is a nice convenience.
The developer can manually write the call to super() at the top of their 
child class constructor for clarity, and then the compiled byte code looks 
identical to the silently inserted call to super().  

But, as you said, often the developer wants to include arguments in the 
constructor, so in java, its up to the developer to write the call to 
super(...args.list..), and in that case the compiler doesn't silently 
insert a call to the zero-arg constructor. 

In case the parent class does not have a no-arg constructor, for example, 
it only has an argument list constructor, and if the child constructor 
constructor does not manually call that super(arg-list) constructor - then 
the compiler throws a warning.

That works OK, but the compiler needs to be able to check.

One idea, perhaps, for vim9, instead of introducing the super() keyword 
function,  is to enable the developer to just write a call to  
ParentClassName.new(..args.if.any..),  without needing a left hand side 
assignment.   I think this is clear and explicit.

-- 
-- 
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/88d17bdc-1283-481e-841a-686289a7eb88n%40googlegroups.com.

Raspunde prin e-mail lui