\newpage \section{Script Language Programming -- A Tutorial} Script languages are a programming language, no matter what someone¨ may have told you. It is therefore important to keep in mind that bad¨ programs run badly, and while this script language is very far from¨ perfect, blaming me won't help you get the job done. (Though it might¨ make you feel better.) FidoTerm's script language is a ``machine language''. There is a basic ``machine model'' that is a little engine that runs¨ the script language, and has components that you manipulate in clever¨ ways to perform tricks that get you what you want. All machine¨ languages work this way. All machine languages are awful, because the underlying machines are¨ so primitive, but there is always some way you ``can get there from¨ here''. The measure of awfulness is how hard you have to work to get¨ from here to there. An Intel 8080A is very awful; a Motorola 68000¨ isn't too awful. I'm afraid this is nearer the 8080 end of things. Machine language programming is like: OK, you have before you a barely¨ housebroken animal of some sort that has the singular virtue of being¨ able to read and mindlessly follow directions. It has a large bucket¨ and a Volkswagen Beetle. You also have a pad of paper and a pencil¨ before you. There are the only things in the whole universe at your¨ disposal. Your job is to move your hated roommates belongings from your¨ apartment onto the steps in front of City Hall. (You live somewhere¨ trendy and too far to walk there from, say South of Market.) You cannot tell the beast ``go move the pile'', it's far too stupid.¨ It only understands the following things: \smallpagebreak \settabs\+\indent&99.\quad & \cr \+&Load the bucket\cr \+&Dump the bucket\cr \+&Get in the Beetle\cr \+&Get out of the Beetle\cr \+&Drive the Beetle somewhere\cr \+&Is the Beetle full?\cr \+&Is the apartment empty?\cr Which you can write on a piece of paper. Oh yeah, you can only write a¨ few instructions on a piece of paper, and if there's too many pieces¨ of paper the animal works slower. Yes, this is arbitrary as hell. Tough tootsies. Welcome to machine¨ language programming. Only the mentally deficient survive here for¨ long. OK, assuming you haven't quit yet, let's get to it. Let's write a¨ simple set of instructions for the stupid beast to follow. Try this: \skip \+&Is the apartment empty? (stop)\cr \+&Load the bucket\cr \+&Get into the Beetle\cr \+&Drive to City Hall\cr \+&Dump the bucket\cr \+&Drive to the apartment\cr Give the sheet of paper to the beastie, send it on it's way, sit back¨ and wait. \dots Well, and hour later it's still not back for it's second bucketload.¨ Obviously something's wrong. It only takes 15 minutes to drive there¨ even at rush hour. Look at the sheet again, line by line, word by¨ word. Draw on a piece of paper City Hall, your apartment, the Beetle,¨ the bucket and the beast. Follow the steps one by one. [I'm serious!] Well, for brevity's sake, let's skip up to City Hall. It gets out with¨ the bucket, dumps it in front of some protesters hanging out on the¨ steps, when all of a sudden the world ends. You seriously messed up. The beast can't drive back to the apartment,¨ until it gets back in the Beetle! ``It's obvious!'' you say, well,¨ sorry, we've all heard that one before and it's obviously not¨ ``obvious''. Since you are god, you go back to the start of time, with the Beetle¨ the bucket and the beast back at your apartment. Add the missing¨ command, and start over. (You can do this sort of thing, why do you¨ think so many programmers are so arrogant?) \skip \+&1.&Is the apartment empty? (stop)\cr \+&2.&Load the bucket\cr \+&3.&Get into the Beetle\cr \+&4.&Drive to City Hall\cr \+&5.&Dump the bucket\cr \+&6.&Get into the Beetle\cr \+&7.&Drive to the apartment\cr OK, again you sit and watch, and this time the Beetled beast (sorry¨ I'll stop now) comes back every ten minutes or so. Two days later you're still watching this, over and over, and the¨ apartment is still not empty. Play god and stop the world again. Well, the instructions work, in that the animal is doing what you told¨ it to do, not what you meant it to do, which was to get the damn¨ apartment empty in a reasonable amount of time. You forgot to think¨ about that, huh? There's always something isn't there. \proclaim{Real Life Note \#1}{The instructions you wrote we're easy to¨ think about, understand and make work properly. They were simple, (a¨ very good thing to be) but unfortunately simplistic (not very good at¨ all). You don't even have to be in a hurry to realize that some things¨ can take {\it so} long as to be impractical, or even worse! almost¨ practical. (In the latter case, there is the tendency to put up with¨ things that eventually drive you crazy\dots ) } OK, lets be real. We'd be happy if it took half a day to complete the¨ whole thing. In two wasted days so far, it looks like it did about a¨ tenth of the whole apartment, so we really need to speed it up a whole¨ lot. On a piece of paper figure this out: \centerline{\it One tenth in two days is 20 days for the whole thing} So we need to speed this up 40 times. Well\dots the Beetle ``looks¨ like'' it should hold 40 bucketfulls. Maybe it will! We have a number¨ of choices, two of which are to either figure out if 40 bucketfulls¨ will really fit, and another is just do it and see. Since we've decided on a Kludge, lets go all the way, and just¨ ``assume''. So: \skip \+&1.&Is the apartment empty? (stop)\cr \+&2.&Load the bucket\cr \+&3.&Get in the Beetle\cr \+&4.&Dump the bucket\cr \+&5.&Get out of the Beetle\cr \+&6.&Load the bucket\cr \+&7.&Get in the Beetle\cr \+&8.&Dump the bucket\cr \+&9.&Get out of the Beetle\cr \+&10.&\dots\cr \+&\dots&(repeat 40 times)\cr \+&\dots&\dots\cr \+&\dots&Drive to City Hall\cr \+&\dots\cr \+&\dots&Get in the Beetle\cr \+&\dots&Load the bucket\cr \+&\dots&Get out of the Beetle\cr \+&\dots&Dump the bucket\cr \+&\dots&Get in the Beetle\cr \+&\dots&Load the bucket\cr \+&\dots&Get out of the Beetle\cr \+&\dots&Dump the bucket\cr \+&\dots&\dots\cr \+&\dots&(repeat 40 times)\cr \+&\dots&\dots\cr \+&\dots&Drive to the apartment\cr This is a whole lot longer than the last one, it ain't pretty but who¨ cares. Sit back, hand the beast the instructions, and see what¨ happens. Lucky you: the Beetle seems to hold 40 bucketfulls with no problem.¨ After just under half a day, the apartments empty! (Some of the work¨ was done in the previous two days.) Since planning on having such roommates in the future you'd like to¨ treat like this seems a bad idea, we chose the easiest and simplest¨ solution. [Always keep in mind not only the goal, but the¨ environment!] \proclaim{Real Life Note \#2}{Either of the above processes is called¨ a ``Kludge''. It's OK to do if you have to solve a problem only once,¨ if you bury the evidence {\it immediately} afterwards. It's tempting¨ to get lazy and keep the kludge around for later use. (I guarantee you¨ will pay for that dearly at a later date.) It's also sometimes hard to¨ tell when a kludge is appropriate and when it's not. These are the¨ kind of issues you learn do deal with eventually. } Since this is a kludge, rip it up and throw it away. You'll be tempted¨ to save such a useful set of commands, but avoid temptation. Yeah it¨ worked perfectly, but there are lots of things you can't see. Like¨ maybe: next time you'll have only a moped (very fashionable these¨ days) and the tires will pop, or maybe you'll have a dump truck and¨ won't you look silly. Or maybe you'll have a matter transporter and¨ the whole idea will be stupid. Or maybe you'll have something totally¨ unpredictable. But certainly you have a set of very inflexible instructions that are¨ only good for one thing, with a very specific set of tools. Now you could stop here if your only desire was to get the SOB out of¨ your apartment; you've succeeded! But if you find the process itself¨ interesting (a sure sign of serious character flaws) check this out:¨ how about a set of somewhat general purpose instructions, for emptying¨ out {\it any} apartment you're in! Let's not make some of those same stupid assumptions as before. We¨ want it to be complete in a ``reasonable'' time, but we can't tell¨ what kind of tasks we might come across int he future. In this case,¨ consider this: if you go nearly as fast as is possible with the tools¨ you have, well, there's not much else you can do, right? (Short of¨ getting new tools.) So we have to change two things we just assumed before. Instead of¨ ``City Hall'' we want to fill that in later, so call it, for now,¨ ``there''. Since we don't know if we'll have a Beetle, moped or¨ shopping cart, ``40 bucketfulls'' probably won't work. There were commands we didn't use before, one was: ``is the Beetle¨ (moped, etc) full?''. You have to search and see what's available to¨ you and exploit everything! OK, try this: \skip \+&1.&Is the apartment empty? (stop)\cr \+&2.&Is the Beetle full? (go do step 8.)\cr \+&3.&Load the bucket\cr \+&4.&Get into the Beetle\cr \+&5.&Dump the bucket\cr \+&6.&Get out of the Beetle\cr \+&7.&Go do step 2.\cr \+&8.&Drive to ``there''\cr \+&9.&Is the Beetle empty? (go do step 15.)\cr \+&10.&Load the bucket\cr \+&11.&Get out of the Beetle\cr \+&12.&Dump the bucket\cr \+&13.&Get into the Beetle\cr \+&14.&Go do step 9\cr \+&15.&Drive to the apartment\cr Now\dots this even looks better. Instead of line after line of¨ repeated instructions, there are nice neat sections that do the same¨ thing, only better. Turns out, the Beetle will hold almost 60 buckets,¨ meaning we could have gotten the original job done is far less than¨ half a day! Sometimes it pays to hang in there and take a problem as far as¨ possible. Sometimes it's an utter waste of time. Sometimes you haven't¨ even defined the problem right, and the solution is doomed to failure before you start! \proclaim{Real Life Note \#3}{{\it What if\/} the drive from your¨ apartment to City Hall was really two hours. You waited an hour!¨ surely it should be back by now! so you fart and fiddle and just can't¨ find the problem. Well, if this had happened after we had repaired the¨ problem with the first set of instructions, we might have been led to¨ believe that wasn't the problem in the first place! There just is no¨ simple solution to these kind of problems. } \proclaim{Real Life Note \#4}{You'd think the kludgey solution would¨ be smaller and faster and easier to design than an efficient and¨ flexible solution. Almost never is. The efficient adaptable ones are¨ almost always simpler and work better with less problems. The¨ dismaying thing is that there are a lot of basic programming ``mental¨ tools'' like these that you only get through experience, and is the¨ thing that lots of ``How To Program'' books leave out. I wish there¨ was an easier solution. } Now this is definitely not enough to explain how to write any¨ reasonable program, but that wasn't the goal. The intent was to¨ explain the level of detail you must work with to get useful things¨ accomplished with this script language or most machine languages. Programming is a skill that can be learned by anybody, and involves¨ thinking, primarily. (``Rigorous'' thinking is the phrase I like¨ most.) It sounds tedious to examine things step by step, but I think¨ you'll find that it ends up being faster and easier than staring at¨ the whole thing and grumbling at me. (And will get your script running¨ faster too, since I swear I won't fix it for you!) A pad of paper is¨ the only tool I'd suggest having.