[Gd-hackers] gtk interface: shorten identifiers, ... ?
Danny Milosavljevic
danny_milo at yahoo.com
Fri Dec 1 00:22:00 CET 2006
Hi,
On Tue, 28 Nov 2006 23:51:31 -0800, Mike Austin wrote:
> Bruce Hoult wrote:
>> On 11/29/06, Danny Milosavljevic <danny_milo at yahoo.com> wrote:
>>> Does that mean it doesn't support "overloading" properly?
>>> I mean its a nice idea to have classes not introduce their own namespace
>>> (since that can be found out by the argument types), but all the methods of
>>> different objects which coincidencially had the same name would need to
>>> have the same number of arguments as well? That's pretty improbable :)
>>
>> They can't "coincidentally have the same name". The name of a method
>> is actually the name of the Generic Function that the method is added
>> to. All methods in a Generic Function have to be congruent.
>>
>> So Dylan doesn't have casual overloading of unrelated functions.
>>
>> If you need to use several classes together that were developed
>> independently and have coincidentally the same function names then
>> you'd rename one or both of them on import.
>
> There is a way around this, one of which Bruce will cringe because I mentioned
> it before. :)
>
> Define your object specific method like this:
>
> define method window-foo(window, a, b, c)
> end method;
>
> Now define a generic function which dispatches on one argument, and return the
> actual curried function you want to call:
>
> define method foo(window :: <window>)
> return curry(window-foo, window);
> end method;
>
> window.foo returns the curried function you want to call, and
>
> window.foo(1, 2, 3);
>
> calls it. You will still run into name clashes, but not with your defined
> functions. The above is the same as window(foo)(1, 2, 3).
>
> Yes, it's hacky. But isn't anything experimental?
Oh. Very nice. Being the rookie that I am I'd apply that to every object _method_ of gtk as a silver bullet.
Is that bad? ;) (do I need to seal it afterwards to make it optimizeable? what exactly?)
I started to estimate about how many functions that would have the same name and so far for gtk (without gdk, pango, ...) we have:
http://www.scratchpost.org/patches/gtk-dupes
(methods are in the list no matter whether they have congruent arguments or not, for now... yes yes I'm filtering them next ;))
Contenders for the top are so far:
- "clear" (surprise surprise)
- "activate"
- "copy" (well, they do the cloning thing)
- "free"
- "get_active" (a method that's actually superfluous because there is a property for that - ignore)
- "get_icon_name" (likewise)
- "get_model" (likewise)
- "get_name" (likewise)
- "get_orientation" (likewise),
- "get_pixbuf" (hmm... not always a property)
- "get_text" (property)
- "get_width" (property)
- "get_xdisplay" (property?)
- "insert" (uh oh)
- "remove" (uh oh)
- "select_all"
- (setters for properties above)
signals:
- "activate"
- "changed"
- "set_scroll_adjustments"
- "toggled"
So the real stuff:
Contenders for the top are so far:
- "clear" (surprise surprise)
- "activate"
- "get_pixbuf" (hmm... not always a property)
- "insert" (uh oh)
- "remove" (uh oh)
- "select_all"
signals:
- "activate"
- "changed"
- "set_scroll_adjustments"
- "toggled"
So a quick view yields "doable". I forsee that I will regret having tried, but I can't resist... ;)
cheers,
Danny
More information about the hackers
mailing list