raisedragon / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

RFC to remove redundant <PircBotX> generic parameters #212

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm debating removing all the generic types that wrap the PircBotX class. The 
following classes would no longer accept <PircBotX> as a generic parameter
 - Listeners
 - Events
 - ListenerManagers
 - Configuration and Configuration.Builder
 - MultiBotManager
 - WaitForQueue methods (maybe)
 - Plus any stragglers I can't find right now

 Why? 
 - You probably shouldn't be extending the PircBotX class anyway unless you have a really good reason to. Data really should be stored in the Listeners themselves. This whole idea came from PircBot when it was the only way to use the class.
 - Most people, including myself and the wiki, never extend the PircBotX class and just leave all the types off. While technically legal, it breaks generics on fields (eg UserListEvent.getUsers() returns Set<Object> instead of Set<User>). 
 - Its at least caused Issue #40, Issue #45, Issue #133, and mailing list emails. 
 - Anywhere outside Event.getBot() you'd have to cast anyway since the generics aren't completely universial
 - IDE's complain about the raw types and will sometimes a handfull of times

However if you absolutely need to extend the PircBotX class you'll still be 
able to access your methods with a slightly different syntax

MyPircBotX bot = event.getBot(); //Clean way with no generics or casting!
bot.myMethod();
bot.myOtherMethod();

event.<MyPircBotX>getBot().myMethod(); //Short quick generics

((MyPircBotX)event.getBot()).myMethod(); //Regular old casting

Comments? Questions? Does this look better to you? I'd like input before I 
change something that's been around for a long time.

----

If your wondering what this would look like, this:
public class GenericsProblem extends ListenerAdapter<PircBotX> {
    @Override
    public void onGenericMessage(GenericMessageEvent<PircBotX> event) throws Exception {
        //Do stuff
    }

    public Configuration<PircBotX> createConfig() {
        ListenerManager<PircBotX> myCustomLM = new ThreadedListenerManager<PircBotX>();
        Configuration<PircBotX> config = new Configuration.Builder<PircBotX>()
                .setListenerManager(myCustomLM)
                //Do stuff
                .buildConfiguration();
        return config;
    }
}

would be transformed to this:
public class GenericsProblem extends ListenerAdapter {
    @Override
    public void onGenericMessage(GenericMessageEvent event) throws Exception {
        //Do stuff
    }

    public Configuration createConfig() {
        ListenerManager myCustomLM = new ThreadedListenerManager();
        Configuration config = new Configuration.Builder()
                .setListenerManager(myCustomLM)
                //Do stuff
                .buildConfiguration();
        return config;
    }
}

Original issue reported on code.google.com by Lord.Qua...@gmail.com on 5 Nov 2014 at 7:01

GoogleCodeExporter commented 9 years ago
Is this not a valid reason for extending the PircBotX class?
https://github.com/Shockah/Shocky3/blob/master/Shocky3/src/shocky3/pircbotx/Bot.
java

Basically, I need to detect when the message is ACTUALLY SENT (not when it's 
queued), for displaying it in interface.

Original comment by lolshoc...@gmail.com on 5 Nov 2014 at 11:40

GoogleCodeExporter commented 9 years ago
It is... Or we could make a separate event for outgoing messages - this has 
been a long standing issue if I'm not mistaken.

Original comment by jzhou2...@gmail.com on 5 Nov 2014 at 12:56

GoogleCodeExporter commented 9 years ago
This has been implemented in Revision 4e7ebbb6ed06. Also PircBotX now compiles 
successfully with -Xlint:unchecked. 

No more generics soup!

Original comment by Lord.Qua...@gmail.com on 21 Nov 2014 at 10:21