• Welcome to Valhalla Legends Archive.
 

Programming 1101 - Functions

Started by Grok, December 22, 2002, 10:46 AM

Previous topic - Next topic

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

n00blar

#1
I like your article ::claps:: despite the visual basic, it was really good =P

Grok

#2
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

iago

#3
And furthermore.....

ok fine, I have nothing.  
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Eibro

#4
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.
Eibro of Yeti Lovers.

iago

#5
Now this just looks weird  :'(
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*