Learning to code on SMAUG is definitely not the easiest way to learn, because as you have discovered SMAUG is a pretty big piece of code (even though it is relatively simple not in size but in architecture). But, you've already come a fair way, so you might as well persevere!
You are correct about the first two arguments, but a 'bool' is a true/false variable. It's commonly called a 'flag' (in fact, the little 'f' in front of the name most likely stands for 'flag'). 'bool' stands for 'boolean', which comes from George Boole, who is largely credited with the invention of boolean algebra. (i.e. how to combine trues, falses, ands, ors, etc.)
So, in this case, fShort and fShowNothing aren't really data, they're more like ways to fine-tune the behavior of the function. This is a very important part of code re-use. Imagine you want to do many different things, but they're all really quite similar. What you can do is make one function to handle all of it, but depending on which arguments you give it (i.e. the boolean variables), it can do slightly different things.
In this example, I'm not sure what fShowNothing is for, but I'm willing to bet that if fShort is true, it only displays short descriptions, and if it's false, it displays long descriptions.
Quote: I know you showed me pretty much exactly how, Actually, I didn't, not really. What I did is try to provide a precise formulation of what you were trying to do; you wrote all the C code yourself. My goal is to show you that you have to think clearly in English first. Once you've done that, you've done the hardest part of the work. It's kind of like writing an essay. You can be a master of English, but if you have no idea what to say or how to write an essay, it won't make any sense at all and will be a disconnected, bad essay. Programming is even less forgiving than an essay, as you've probably noticed: "spelling" and "grammar" mistakes either make your program blow up, or worse yet, make it do something similar but subtly different that will cause problems later on.
As you get better, again, much like essays, the "English thinking" phase will become somewhat natural and you will be able to reason about high-level concepts fairly easily and quickly. The part that most people find so frustrating as they're learning, and rightly so, is that they have enough trouble thinking about the high level concepts, that thinking about code is overwhelming, and the end result is a big mish-mash of code and concepts. Trust me -- I've been there too. :P
The mistake generally made is to reason directly in terms of for loops, if statements, function calls etc. and forget the bigger picture. It's important to back off from the code a bit and think (in natural language, not programming terms) about what you're trying to do.
OK, I'll get off my soapbox now. :P |