All of my code (including commands) use subroutines AND if statements. I don't see how you can write good, maintainable code without both.
All bots need at least one subroutine (to receive Messages ), but I think he means what one do you use for your bot's main code (i.e. commands)
Like, do you do if ($msg =~ /menu/i) { $self->sendMessage ("Here is my menu:"); }
or do sub menu { return "This is my menu:"; }
I use subroutines for commands, because that way all your main variables ($self,$username,$message,etc.) are always local for each command, and you don't have to worry about accidentally overwriting them (with subroutines, one command may set $username to undef, but that won't stop your other commands from being able to use the original value of $username).
I think subroutines are best for commands, if statements can go inside subroutine commands for if you do things with callbacks or other changing values. _________________ Current Site (2008) http://www.cuvou.com/
I'm just saying that I like to group commands into more logical units, modules. So I end up calling methods, but also doing if tests inside those.
At some point, commands need to use if tests to route them to the right place, unless you are using eval or soft references, in which case you should at least be using an if to make sure what you are evaling is safe.
Subroutines and modules all the way. It's the proper way to code. _________________ Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Joined: 21 Dec 2004 Posts: 49 Location: Western Australia
Posted: Fri Feb 18, 2005 11:22 am Post subject:
QUOTE(alienz @ Feb 17 2005, 08:32 AM)
Subroutines and modules all the way. It's the proper way to code.
Here here.
The question is a little silly though. When it comes to writing your own bot, not using a template, it is literally impossible to use one but not the other in C++, and I'm pretty sure its either impossible or indecently, sinfully obscure to do it in perl.
I think it is better for a set of core commands to have their own methods within the bot propper, and all others must be in independent loadable modules.
When it comes to writing your own bot, not using a template, it is literally impossible to use one but not the other in C
C wont let you use both subs and modules at the same time? _________________ Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
When it comes to writing your own bot, not using a template, it is literally impossible to use one but not the other in C
C wont let you use both subs and modules at the same time?
He said it is literally impossible to use one without the other (the one being subroutines, the other being if statements). I don't think C can have just If statements and no subroutines (doesn't it need int main to even begin the program? that's a subroutine too ). _________________ Current Site (2008) http://www.cuvou.com/
He said it is literally impossible to use one without the other (the one being subroutines, the other being if statements). I don't think C can have just If statements and no subroutines (doesn't it need int main to even begin the program? that's a subroutine too ).
Ahh, I see...posted when I was still waking up LOL _________________ Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Joined: 27 Jan 2004 Posts: 132 Location: I dunno, but the padded walls are sweet...
Posted: Sun Mar 27, 2005 10:06 pm Post subject:
I like subroutines in this case. If I ever want to reuse that function for any reason I can easily be done.
The majority of programming languages use things called libraries, not modules. C and C++ are more complicated when it comes to subroutines and variables. Iit would take a while to explain. x_x
Joined: 21 Dec 2004 Posts: 49 Location: Western Australia
Posted: Mon Mar 28, 2005 3:13 am Post subject:
QUOTE(Mojave @ Mar 27 2005, 02:17 PM)
Quote:
The majority of programming languages use things called libraries, not modules.
They are the same thing, except that one is compiled and the other is not. [right][snapback]47287[/snapback][/right]
Hmm, not necessarily. Most libraries are already compiled when you want to use them in your project, and if you have a precompiled addon to you can call it a plugin, or a module. Also, some libraries, like the Microsoft GRETA library are designed to be compiled at the same time as the project. So they can both be compiled, or they can both be not. It's actually quite common that they both aren't, and less common but still around that they both are.