|
|||||||
| Forum Home | Register | Members List | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 | ||||||||
|
Junior Member
Location: Martinsville, IN |
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. |
||||||||
|
|
|
|
|
#22 | |||||||||
|
Senior Member
Location: London |
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:
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. |
|||||||||
|
|
|
|
|
#23 | ||||||||
|
Junior Member
Location: Martinsville, IN |
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? |
||||||||
|
|
|
|
|
#24 | ||||||||
|
Administrator
Location: London, UK |
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 | Research | Teaching |
||||||||
|
|
|
|
|
#25 | ||||||||
|
Junior Member
Location: Martinsville, IN |
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. ![]() |
||||||||
|
|
|
|
|
#26 | ||||||||
|
Member
|
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 ![]() |
||||||||
|
|
|
|
|
#27 | |||||||||
|
Member
Location: Tuckahoe, NY |
Quote:
I agree with the fact that you should not have comments saying: Code:
// I am printing a line to the console here cout << "Pointless!" 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 |
|||||||||
|
|
|
|
|
#28 | |||||||||
|
Member
|
Quote:
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 :PLast edited by nef : 01-03-2009 at 12:15 AM. |
|||||||||
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 08:24 AM.
























In the end w/ all the good practices at your fingertips, it's your own good judgment that makes the difference.
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
Linear Mode

