Valhalla Legends Forums Archive | General Programming | Programming 1101 - Functions

AuthorMessageTime
Grok
In math, a function accepts a domain of input and produces a range of output.  Functions act like black boxes.  One knows if they provide a given input, the output is always the same.

In programming, functions are similar.  With the exception being that the output can be different on every invocation, software functions take a domain of input and produce a range of output.

Over the last three years I've seen a lot of bot code, mostly ok, but a lot of it badly done.  It is just inexperience, so don't take it personally.

Your bots will be much better if your functions can stand alone.  In another thread I just posted a reply that included a function DebugOutput().  That function accepts a string and outputs a formatted string.  The output looks like what the debug program shows, only without the offsets.  Here is the declaration:

Public Function DebugOutput(ByVal sIn As String) As String

That's all you need to know as the user of this function.  There are no hidden dependencies on other things, it initializes all its own local variables, performs its own calculations, and produces the expected output, no matter the input.

By writing your functions so that even you don't have to remember what goes on inside it, you give yourself and others a toolkit of utilities that are reusable.

And despite the functions being in VB in this case, if you write a good function in one language, you can pretty easily duplicate the function in another language, or on another platform.

Hope this helps.
Grok
December 22, 2002, 4:46 PM
n00blar
I like your article ::claps:: despite the visual basic, it was really good =P
December 23, 2002, 12:45 AM
Grok
I just knew someone would try to show how much they knew by tacking on to my post.

Um, in the future, get your own topic thread.  The topic I posted was basic and introductory material, and purposefully so.  Throwing in encapsulation, inheritance, interfaces, classes has no place in day 1.

----
Next I'll talk about what makes a good function, how to spot a good one, how to spot a bad one, and related issues.

Grok
December 23, 2002, 3:08 AM
iago
And furthermore.....

ok fine, I have nothing.  
December 23, 2002, 5:28 AM
Eibro
I didn't try to "show how much I know"
I just thought it'd be nice to add something. Oh well, it's gone now.
December 23, 2002, 12:15 PM
iago
Now this just looks weird  :'(
December 23, 2002, 1:02 PM

Search