Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 12-24-2008, 02:59 AM   #21
MDBurpo
Junior Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss14
Location: Martinsville, IN
Default

Claxon, thanks. That's what I was looking for. It sucks being a rookie.

Protector, I did not know that. I'm making the changes now. Hopefully, I should be done with it now.
MDBurpo is offline   Reply With Quote
Old 12-24-2008, 03:25 AM   #22
Claxon
Senior Member

Activity Longevity
0/20 18/20
Today Posts
0/11 ssssss345
Location: London
Default

Just to add a little to what Protector one said, you also seem to have misplaced terminology that could cause you a little confusion in the future.

Quote:
Originally Posted by MDBurpo View Post
Code:
int QuestionOne()
{
    int answer; //Initialize "answer" variable.
    int answer1; //Initialize "answer1" variable.
    int answer2; //Initialize "answer2" variable.
    int answer3; //Initialize "answer3" variable.
    int answer4; //Initialize "answer4" variable.
    answer1 = 1; //Set "answer1" variable to 1.
    answer2 = 2; //Set "answer2" variable to 2.
    answer3 = 3; //Set "answer3" variable to 3.
    answer4 = 4; //Set "answer4" variable to 4.
When you have a line like:
int answer;
you are defining the variable, so the memory space has been allocate but no
value has been set.

Then with lines like this:
answer1 = 1;
you are initializing the variable (well, technically it means the first time you set the value).

I'm just pointing that out so that when people say "Make sure you've initialized your variables" you know that they mean to assign a value to them, and not just to declare them.
Claxon is offline   Reply With Quote
Old 12-24-2008, 11:19 AM   #23
MDBurpo
Junior Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss14
Location: Martinsville, IN
Default

I understand the intializing and defining. What I can't figure out:

If I'm using answer only for cin << answer;, what do I initialize for answer? Just anything as the input will overwrite it?
MDBurpo is offline   Reply With Quote
Old 12-24-2008, 12:51 PM   #24
Adrir
Administrator
 
Adrir's Avatar

Activity Longevity
1/20 20/20
Today Posts
0/11 sssss1466
Location: London, UK
Default

Quote:
Originally Posted by MDBurpo View Post
If I'm using answer only for cin << answer;, what do I initialize for answer? Just anything as the input will overwrite it?
Yeah, any valid value really. I usually just initialize integers to 0 after I've declared them even if I'm planning on letting the user input a value. It just makes sure it's not filled with random junk that might mess something up if I later decide to remove the user input.
__________________
Michael 'Adrir' Scott :: Games, Virtual Worlds, Education
Networking | Current Project | Research | Teaching
Adrir is offline   Reply With Quote
Old 12-25-2008, 02:37 AM   #25
MDBurpo
Junior Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss14
Location: Martinsville, IN
Default

Thanks Adrir! That's exactly what I figured I should do when nef told me about my not initializing the answer variable. That was basically the only thing holding me back from wanting to move on with my learning.

Oh, Merry ChristmaKwanzaaChanukah everyone.
MDBurpo is offline   Reply With Quote
Old 12-31-2008, 09:44 PM   #26
nef
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss58
Default

nice man!

I also appreciate that you didn't put that last bit into another function, the part about pressing enter to exit. Something like that I wouldn't think deserves it's own function, and you didn't go nazi w/ the rules I posted In the end w/ all the good practices at your fingertips, it's your own good judgment that makes the difference.

I assume your commenting was just for this exercise, in practice, I probably would have had a totaly of four lines of comments. This is debatable, but I've always been a big fan of self documenting code and what you are doing is obvious. I don't need a comment telling me your printing a line or starting the logic for an else case

Good luck w/ your C++ learning. Best wishes
nef is offline   Reply With Quote
Old 01-02-2009, 09:12 AM   #27
Duckman
Member

Activity Longevity
0/20 17/20
Today Posts
0/11 sssssss84
Location: Tuckahoe, NY
Default

Quote:
Originally Posted by nef View Post
I assume your commenting was just for this exercise, in practice, I probably would have had a totaly of four lines of comments. This is debatable, but I've always been a big fan of self documenting code and what you are doing is obvious. I don't need a comment telling me your printing a line or starting the logic for an else case

I agree with the fact that you should not have comments saying:
Code:
// I am printing a line to the console here
   cout << "Pointless!"
I feel that comments are pretty crucial in terms of organization and communication for current and future programmers on projects. I have come to notice this from my current job. The current program that we are developing was originally developed by our offshore team and there was a lack of detailed comments on exactly what they did. Also, there was lack of documentation which you have also brought up.

This brings up another issue that I has come up while working here, organization of code. It was very difficult for me to get up to speed on the structure of this project with the lack of organization. The logic setup was good, business logic in one project, database interact in another, etc., but what I have noticed is that code tended to jump around so much you could get lost in the stack even with a call stack right in front of you lol.
So this thread is actually a very good issue to be brought up in terms of preferred method of coding. I've learned through this experience to structure my code better for others so that we can work as one unit, but I think I need to pick up myself a copy of Code Complete to make myself an expert at organization. Phew that was a post! LOL
__________________
Mike M
Facebook Profile LinkedIn Profile
Duckman is offline   Reply With Quote
Old 01-03-2009, 12:10 AM   #28
nef
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss58
Default

Quote:
Originally Posted by Duckman View Post
This brings up another issue that I has come up while working here, organization of code. It was very difficult for me to get up to speed on the structure of this project with the lack of organization. The logic setup was good, business logic in one project, database interact in another, etc., but what I have noticed is that code tended to jump around so much you could get lost in the stack even with a call stack right in front of you lol.
So this thread is actually a very good issue to be brought up in terms of preferred method of coding. I've learned through this experience to structure my code better for others so that we can work as one unit, but I think I need to pick up myself a copy of Code Complete to make myself an expert at organization. Phew that was a post! LOL
yup, yup. Another great tool for this are UML designs. I hate making the damned things, but they are a GREAT way to show off the overall logic flow of a project to another developer. It's so much easier to take a quick glance at a class diagram and see how modules are interacting than digging through thousands of lines of code for the same thing.

My goal when writing code is that if someone else looks at it, they would have to be retarded to not understand what I'm doing. I strive for that anyways, sometimes it can be difficult.

Some people favor clever/tricky code that is "more efficient" or just smaller. I must admit, I enjoy trying to rework code to be smaller or "more efficient" but it's something i force myself not to do, if not necessary. It's best that your code is organized well and written in a way that it's obvious. Generally, you will have lots of people coming back to it, whether to fix a bug or add a feature so you don't want to be a hinderance, or "that guy" (The guy whos code everyone dreads to work on/with)

heh, just a couple months ago i was dealing w/ some outsourced work myself. I'll just say this, I learned that some things in C++ are possible that I would never have thought could compile and I still ask myself, "WTF was this guy thinking?!"

Honestly, who declares a class (derived from some other class) w/ one object, an array of pointers of size 0 and memsets that object to fill it in later (W/ whatever length he deems fit)?! WTF GUY!

Arrgg, and one of my favorites. The global char array named: Str. Used everywhere in a multi-threaded application w/ thousands of lines of code. And w/ a hardcoded size (IE I had to find the declaration to know it only stored 256 characters). No wonder the damned thing randomly printed garbage to the console To make matters worse, it appears to have also stored multiple string w/in it null terminated and used on a per function basis. I hope I never have to go back into that hell again :P

Last edited by nef : 01-03-2009 at 12:15 AM.
nef is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 01:07 AM.






UBM Tech