okay—here’s lesson number one for a total novice in programming–I hope it helps you realize both how easy it is to write a program and how stupid the computer really is:
Look at the shampoo in your bathroom. It has an algorithm printed on it, which you could write by yourself:
lather
rinse
repeat
but notice, dear novice programmer, that this algorithm has a serious defect in its logic, which you will learn in your first day in class:
if you follow the algorthm above, you will DIE washing your hair---- because you forgot to add a 4th step, which is :
STOP!!!
The computer will do exactly what you tell it to do—but it is so stupid that you have be really,really precise about your instructions.
So don’t be afraid of the damn machine. You are a whole lot smarter than it is.
Enjoy your class!
That won’t solve the problem, because line 4 will never be reached. So you’ll still die washing your hair. Instead, line 3 needs to be changed to something like “repeat, but only if your hair is still dirty” or “repeat, unless you have already repeated three times.”
True, and the absolutely worst thing a beginning (or any programmer) can do is to start coding before thinking. The algorithm needs to be there long before the program. I’ve been programming for 40 years, and I always write out, in text, how I’m going to handle even the smallest program. I often find things I missed when thinking about it.
It looks like we are having an outbreak of Muphry’s Law here. Not only what Walton Firm said, but Chappachula forgot to say START, without which, the computer won’t do anything at all.
Oh, c’mon now… no one’s specified a particular programming language, and it’s perfectly reasonable to assume one which doesn’t require explicit “START” or “STOP”. For that matter, it’s perfectly reasonable to assume the ordinary language “repeat” on a shampoo bottle means “repeat the above (but not this repetition instruction itself)” or perhaps “repeat the above as many times as you like (but not…)”. In fact, that is what it means, humorous but forced misinterpretations notwithstanding.
If you pick a specific formalized language of instruction (i.e., a programming language), then all that might go out the window. Then it depends on what exactly each command means in that language, and there may indeed be such a mismatch between the letter and the spirit of the law, so to speak. But we’re talking in ordinary language here, whose semantics are not so rigid as to allow such pedantry.
I’m going to disagree a bit. The ‘instructions’ are unclear, to the point where they don’t make a good algorithm, which should be specific enough that there’s no confusion about how many times to repeat a particular step, and so on. Since we’re talking about algorithms, it makes sense to bring that up in context. Also, the ‘repeat’ is unclear about if you only repeat the rinsing, or go back the lathering step and start again.
To specify an algorithm, you don’t need to be as formal about such things as you do when coding in a programming language, but the conventions you use for specifying an algorithm should be clear enough to eliminate big obvious ambiguities - either the words used should be clear and precise in and of themselves, or a shorthand like a particular flowchart or pseudocode style can be used, with a corresponding reference chart (or at least a person willing to explain what it means.)
Yes, I didn’t actually notice that comment. Obviously you start washing your hair, or anything else - an algorithm doesn’t need to state such things for them to be understood.
Myabe not. One of my very earliest experiences with computers, back in IMSAI 8080 days, was when a friend came over to me house to install a copy of BASIC he had on audio cassette. He then showed me how to load some games and how to play them (pure text, no graphics). After he left, I loaded one of the games from the Penny’s cassette player, and the computer just sat there. I loaded it again, same result. Why didn’t the game work?
So I called my friend up. Why won’t it play?
“Did you type RUN <enter>?” he said.
No, I hadn’t. Why should I? No one told me that was an essential step, he just assumed I knew. And I just assumed that once the game was loaded, it would begin. We were both wrong.
Sure, now you say :smack: but you’ve got to start somewhere.
Sure, sure. When you’re dealing with an actual machine and its particular mode of instruction, such details might become important, though they of course vary significantly from system to system. But clearly, the English language descriptions being given are not at that level, and, as such, needn’t be criticized for not conforming to its requirements.
Here is how the American Heritage dictionary defines algorithm:
al·go·rithm n. Mathematics. A step-by-step problem-solving procedure, especially an established, recursive computational procedure for solving a problem in a finite number of steps.
Since we’ve already gone way OT, note that this algorithm only had 4 lines, and it still had a problem. This happens all the time, and is the reason you’ll want to test your program with various inputs afterwards to make sure it’s working right. Or better yet…
Yes! For a time I was an average member of the UofA programming contest club (which does problems like these). You and your two team-mates get maybe 8 questions to do in ~6 hours. Time is of the essence, so when you get the problems, you have to… grab a pencil and start thinking. Do not go near the computer. I know that one looks easy; just don’t.
Write it out at least once at a fairly high level. If it’s complicated (and they usually are), write it out again a bit lower down. Think about both the whole problem and the bit you’re trying to solve right now. What if the number is negative? Is the problem much harder than you think? Maybe it’s actually far easier.
Trying to code before you fully understand what you’re doing is a recipe for confusion, struggling, and at least one “oh, wait” moment where 1/2 your code has to be deleted. Your motto should be “Whiteboard, not the keyboard!”
START (or RUN) isn’t part of the algorithm or the program, though; it’s a system command so that the computer will execute the program. For obvious reasons, a START command in the program itself would do sod all - the program itself cannot tell the computer to run the program, because if it could, it wouldn’t need to.
This is true for other engineering disciplines as well, but for some reason a lot of coders think they’re special. BTW, if you are quite good about doing this, what do you think of the literate programming style? Have you tried any of the packages?
How did you get a BA in history if you run out of the room in a panic every time you see a word that you don’t know?
Of course I’m pretty sure the answer to that question is that you didn’t. The real question is why are you treating new words in this subject differently than you did in the past and why would you abandon learning techniques that you have already employed successfully?
Handsomeharry has done us all a favor with his post. It’s released the subconscious arrogance, social stupidity, and didacticism that plague all engineers. I feel sorry for HH, but when you dare to enter this world, you get the bad with the good.
Ignore all the advice, including mine (except for the “Don’t Panic”, which I humbly believe is good advice in a lot of situations). Also ignore all the opinions about the right way to program. People are still debating that one.
All that you see but can not control is either terrifying or infuriating or both. The beginning programmer is terrified of making a mistake or being unable to figure out the “rules”. The experienced programmer is infuriated by systems that he/she can not figure out, and for which no documentation exists.
In the grand scheme of things, if you will relax and acknowledge that you’ll be adrift upon the darkening sea, with no hope of rescue, then you’ll be happier. Pepsi and Cheetos help.
I guess I’m the only one that noticed the classs hasn’t even STARTED yet.
Dude, if you are still in this much a panic after you’ve gotten your course materials and finished the classroom work that this assignment is based on, THEN you drop the class.
Until then, you’re acting like…well, this is GQ so never mind.
I’ll tell you something they won’t tell you in class, but you do need to know for when you start writing programs:
Your program isn’t going to work the first time you try to compile or run it.
(Compiling is something you have to do with programs in some languages to get them ready to run. The compiler, the program that you use to do this, looks for errors in your program, and won’t make an executable file if it finds errors.)
It just isn’t. There are going to be errors in it. Any programmer I know would die of shock if their program compiled or ran exactly right the first time they tried.
You will have to develop strategies of writing your programs a little at a time, getting the little bit you wrote so it works, then adding on. If you try to write the whole program at once and then get it to work, you will face endless frustration, and you probably never will get it to work. Maybe someone with a lot of programming experience could do it, but a beginner can’t.
Do you know what programming language they’re going to use in the course?
Go to the first couple of weeks of classes, and see if it still seems as scary. I remember wanting to drop all my classes after my first day of college, because they all seemed so scary. I ended up with a 4.0 for the semester.
Anyone who comes up with a language that has this capability is going to get enough money to make Bill Gates look middle-class.