Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Re: idea for refactoring

Gregg G. Wonderly wrote:
Nope :)
varargs  are also useful.
But sometimes like Dan said you have something like this:


For trailing optional arguments, varargs will provide a mechanism. However, the general case won't work with varargs. I, personally, think this adds confusion to the reader of the code. APIs like JOptionPane have continuously been frustrating because there are too many overrides, some with more than 3 arguments which is the jumpoff point for my eye and brain coordination.

Well, python offers a clean solution:

    def func (a, b, c=1, d=[], *args, **kw):
        ...

a and b are a normal parameter (python is untyped)
c is an optional parameter. If you don't specify it in the method call, it will be 1.
d is the empty list or whatever you put into it.

    func (1,2,d=3)

will set a to 1, b to 2, c to 1 and d to 3.

Anything else which is of the form "name=value" will end up in the hashmap kw. And all the other stuff will be in args which is a list.

To take this idea further: How about a precompiler for Java which implements things like this?

Doesn't Eclipse come with its own Java compiler? How about adding hooks to it where developers can plug in parsers and special compilers to extend Java?

--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.philmann-dark.de/


Back to the top