User Control Panel
Advertisements

HELP US, HELP YOU!

Sub or If?
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Bot Depot Forum Index -> Recycle Bin 2.0
View unanswered posts
Author Message
davidk
Senior Member
Senior Member


Joined: 14 Feb 2004
Posts: 195
Location: United Kingdom, Europe, Earth, Solar system, The Milky Way, The Universe, the 3rd Dimension.
Reputation: 31.1Reputation: 31.1Reputation: 31.1

PostPosted: Wed Feb 16, 2005 4:44 pm    Post subject: Reply with quote

Which one? Not voted for it but If Razz I think.
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Wed Feb 16, 2005 6:12 pm    Post subject: Reply with quote

All of my code (including commands) use subroutines AND if statements. I don't see how you can write good, maintainable code without both.
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Feb 16, 2005 7:02 pm    Post subject: Reply with quote

QUOTE(Mojave @ Feb 16 2005, 01:12 PM)
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 Razz ), 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/
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Wed Feb 16, 2005 7:59 pm    Post subject: Reply with quote

I knew what he meant. Razz

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.
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Thu Feb 17, 2005 8:17 am    Post subject: Reply with quote

i use both, all good!

prefer subs though, if can get messy
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Thu Feb 17, 2005 4:32 pm    Post subject: Reply with quote

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
Back to top
shmookey
Newbie
Newbie


Joined: 21 Dec 2004
Posts: 49
Location: Western Australia
Reputation: 17.7Reputation: 17.7

PostPosted: Fri Feb 18, 2005 11:22 am    Post subject: Reply with quote

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.
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Fri Feb 18, 2005 3:34 pm    Post subject: Reply with quote

QUOTE(shmookey @ Feb 18 2005, 06:22 AM)
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
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Fri Feb 18, 2005 4:07 pm    Post subject: Reply with quote

QUOTE(alienz @ Feb 18 2005, 10:34 AM)
QUOTE(shmookey @ Feb 18 2005, 06:22 AM)
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 Razz ).

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Fri Feb 18, 2005 4:25 pm    Post subject: Reply with quote

QUOTE(Cer @ Feb 18 2005, 11:07 AM)
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 Razz ).

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
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Sat Feb 26, 2005 4:17 pm    Post subject: Reply with quote

yeah c++ requires int main which is the basis of the program
Back to top
M4RTIN
Member
Member


Joined: 31 Dec 2004
Posts: 134

Reputation: 19.2Reputation: 19.2

PostPosted: Sun Mar 06, 2005 3:12 pm    Post subject: Reply with quote

I voted on the 3rd one, Run it with sub, Commands with if's.

Smile
Back to top
MeltingWax
Member
Member


Joined: 27 Jan 2004
Posts: 132
Location: I dunno, but the padded walls are sweet...
Reputation: 30.4Reputation: 30.4Reputation: 30.4

PostPosted: Sun Mar 27, 2005 10:06 pm    Post subject: Reply with quote

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
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Sun Mar 27, 2005 10:17 pm    Post subject: Reply with quote

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.

Quote:
C and C++ are more complicated when it comes to subroutines and variables. Iit would take a while to explain. x_x


Go ahead and explain it to us. We'd all like to hear what you think. Razz
Back to top
shmookey
Newbie
Newbie


Joined: 21 Dec 2004
Posts: 49
Location: Western Australia
Reputation: 17.7Reputation: 17.7

PostPosted: Mon Mar 28, 2005 3:13 am    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Bot Depot Forum Index -> Recycle Bin 2.0 All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group