Monday, November 25, 2013

Simpleton Geek Teaches Computer Programming Book 2 Ch 7A


7. Idle Loop
7.1 Input-Function-Output
The students were all waiting for their teacher to show up. They were showing each other their ASCII art and MADLIBS program. Everybody was enjoying themselves. Even at this early stage, they could do something fun.
“I wish there's a way to show more than one screen.” Nancy complained. “I can show more pretty things on my screen!”
“I'm sure there is a way to do so. Why not ask the teacher to show you?” said Linda, who was seated next to her.
“I'm afraid the teacher will get upset. You know how he is.” said Nancy. That's right. Terminator on the prowl.
The teacher comes into the classroom. “Okay, guys. Ready to start class?”
“Teacher, can you show us how to do 'Press A to continue?'” asked Peter.
“Hmmm. That will involve something you haven't learned already. A 'Press Enter to continue', however, is perfectly doable already. You mean you haven't tried that?”
“Sorry, teacher. It never occurred to me. Everything I've seen so far is 'Press A to continue'.” said Peter.
“Well, I guess I can't blame you for that. You never grow up in the environment where mouse and joystick are optional. Would you believe that at one time, the backspace key is optional? Gya ha ha ha!”
The teacher thought about it for a while. “Hey, you guys knows INPUT, right? Have you checked LINPUT yet?” Everybody shook their head.
“LINPUT is actually the simpler of the two. The reason why INPUT is taught because that's what was available back then, so it's done by convention. But INPUT actually parse the line so you can enter multiple values at once. You actually don't want it for a simple button press. So, use LINPUT instead. It only takes a single value, and is perfect for your use.”
?”PRESS (ENTER) TO CONTINUE”
LINPUT A$
?”YOU PRESSED (ENTER)!”
If you do that, you'll find that the program paused for your input before printing the second line. That's how you wait for further input. In fact, armed with this knowledge, you can do a mini note program, where you simply put the text on screen, one after the other. So far, you only have knowledge to just go down one route, no looping. That comes after GOTO. For now just do it the hard way. Gya ha ha ha!”
“But teacher, we don't want to learn GOTO!” said Nancy. The teacher's eyes narrowed dangerously. “Because GOTO means spaghetti code!” Nancy stammered her explanantion. The teacher was not convinced. “Because it jumbles the code and makes it hard to read!”
“GOTO doesn't make it hard to read. Code confusion is the fault of the programmer, not GOTO!” said the teacher.
“But it has been proven that GOTO means spaghetti code.” insisted Nancy.
“FAIL!” said the teacher as he stamped her forehead with the dreaded 'FAIL' stamper.
Nancy looked like she's about to cry. “Shouldn't a good teacher be able teach without violence?” she wailed.
“Hmmm. That's true. A good teacher can certainly do that.” the teacher said. “Too bad I'm not a teacher, but a professional! Gya ha ha ha!”

No comments:

Post a Comment