On 23/02/02 9:28 AM, Bram Moolenaar wrote:
Doug Kearns wrote:

I was just looking at the constructor documentation and noticed that the
default constructor includes parameters for each field in the order they
were declared.  Having to change all the constructor call sites when
reordering field declarations seems like a probable source of bugs,
particularly when switching fields of the same type.  This seems like a
feature that really needs named-parameter support.
Good point.  Although I doubt it would happen often, it can be difficult
to figure out what went wrong when it does happen.

What we could do:

1. Do not change how it works, add remarks to the help warning for
    changing the member ordering.

BTW, it's easy to avoid the situation, add

   def new()
   enddef

to any class where you don't want the default constructor.

Without this, a lint could produce a warning about using default constructor.

-ernie


2. Make the default new() method not accept arguments.  The caller must
    set the fields after calling new().  This is safe, but requires
    several extra lines.
        var obj = Class.new()
        obj.line = 5
        obj.column = 0

3. Add a mechanism to name the members in the call, e.g.
        var obj = Class.new(line = 5, column = 0)
    This is similar to 2. but puts it in one line.
    It requires marking a method to not use positional arguments.a

Although 3. looks like a good solution, it requires implementing a new
mechanism.  And disallowing positional arguments might be considered
weird, I cannot think of a language that has this functionality.



--
--
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/651cb7ef-35b2-697e-6e15-fec7003c31be%40raelity.com.

Raspunde prin e-mail lui