Why do I have so much... code?!

Started by
19 comments, last by Onemind 19 years, 8 months ago
lol, and how did you know im from Digipen??

and whoever quoted me... yes, i know what i was saying when i wrote that. what i meant/mean is that i have WRITTEN the program. i just need someone to help me trim it up and shorten it, i just didnt know how to do that.

and thunderhawk, thank you very much. i already knew there was that way to do it as well, it's just that, like you said, the point of the lesson was to do it using functions
Silence! I'm Psychoflexing...
Advertisement
Here's step one to shrinking your code. We can help you through it, but we won't write it all. Do this and then show what you have to see if there are further possibilities.

Here is one of your functions now:
float multiply(float multi1, float multi2){	float multi_answer;	multi_answer = multi1 * multi2;	return multi_answer;}

It is 3 lines that do this:
1. Create a variable to hold the answer.2. Assign the answer to the variable.4. Return the answer from the function.


Well, you don't really need a temp variable in this case. All this function has to do is take the arguments passed to it and return the result. You could do this:

float multiply(float multi1, float multi2){    return (multi1 * multi2);}


So you can shrink all your functions that way. You see (multi1 * multi2) produces a float, which is then returned :)
- A momentary maniac with casual delusions.
Quote:Original post by ugoff
lol, and how did you know im from Digipen??


"Your computer may be broadcasting an IP address." [rolleyes]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Washu
You do realize that there are people from Digipen who read these forums?


Is DigiPen hated or something? I was actually considering that school but, if it's a joke, then I'll look elsewhere!
- A momentary maniac with casual delusions.
Quote:Original post by Washu
You do realize that there are people from Digipen who read these forums?


He's not from Digipen, he's 14-15 according to his profile.

Anyhow, Your code looks just fine for a beginner and very clear. Anything homework related is frowned upon(and against the rules) around here, unless its general help IE-don't ask for a solution. Just so you know.

throw table_exception("(? ???)? ? ???");

oh i get it, so when somebody posts here, the mods and admins can see their IP addresses as well?? and rhaal, that is freaking awesome. thank you so much for showing that to me. i never thought of it, and it makes things so much easier

EDIT- oh, i AM coming from Digipen, but im not a full time student. im just here for a couple weeks doing a workshop
Silence! I'm Psychoflexing...
Quote:Original post by ugoff
lol, and how did you know im from Digipen??
...


Washu Moderator Member since: 3/24/2001 From: Kanemitsu

The bold part makes me see things in a new light!!!

While the point of the exercise was to demonstrate functions, I think the choice of material for the exercise was poor. One of the primary goals of learning to code should be learning to code correctly, and in having a lesson where you define such simple operations as functions will tend to ingrain in students...shall we say bad practices? Now, that's not saying that you will fall into that trap, but keep in mind that most classroom examples are "wrong" in industry. See the shapes example for instance.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Quote:Original post by Fruny
Quote:Original post by ugoff
lol, and how did you know im from Digipen??


"Your computer may be broadcasting an IP address." [rolleyes]


Ah, so he must be a summer-session kid... my bad.

throw table_exception("(? ???)? ? ???");

Quote:Original post by Washu
Now, that's not saying that you will fall into that trap, but keep in mind that most classroom examples are "wrong" in industry. See the shapes example for instance.


Also, at least according to what I've heard (I don't tend to read books on programming, but just occasionally Google things) most textbook examples are "wrong" according to the compiler. ;)
Quote:Original post by Washu
Now, that's not saying that you will fall into that trap, but keep in mind that most classroom examples are "wrong" in industry. See the shapes example for instance.


Which shapes example? The one in every book about inheritance? If so please explain why, because I've accepted the example so far!
- A momentary maniac with casual delusions.

This topic is closed to new replies.

Advertisement