Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualVladimirMarenus

Posted 14 November 2012 - 04:00 AM

The code is artificial, and more importantly, it doesn't do anything (except printing stuff). Thus there's very little that could be wrong with it on low level, and in the absence of context it's hard to say anything about design issues.

Just some cosmetic things I'd point out to a student:
- "a" is useless because you could be printing "index+1" instead
- any variables like "choice" should be defined as close as possible to where you actually use them for the first time
- instead of writing "choice-1" everywhere, sanitize the number once to the value you actually want (-=1)
- finally, magic numbers like "01" and "02" are generally bad; in a real program you would likely use an enum and descriptive labels like ITEM_HEALTHPOT or ITEM_FIREPOT

Which compiler are you using? If it's new enough to have some C++11 features, they can make your life easier in small (and occasionally big) ways.


Thank you very much. I realize the artificial nature. This is a glorified snippet that is mostly designed to teach me how to use and modify vectors. The suggestions I was looking for are exactly the ones you mentioned- just good housekeeping and dev habits in general. I'm learning this myself, so I'm not able to get the benefit of a teacher standing over me going "No- that won't work in six months when you're doing something better."

I'm using Microsoft VS 2012- I'm not sure what "C++11 features" are, but if they make my life easier, I'd certainly be interested in hearing about them!

EDIT: I've applied the changes you suggested, and the code reads much better.

EDIT 2: The next step for me is to turn this into a class, I suppose!

#4VladimirMarenus

Posted 14 November 2012 - 04:00 AM

The code is artificial, and more importantly, it doesn't do anything (except printing stuff). Thus there's very little that could be wrong with it on low level, and in the absence of context it's hard to say anything about design issues.

Just some cosmetic things I'd point out to a student:
- "a" is useless because you could be printing "index+1" instead
- any variables like "choice" should be defined as close as possible to where you actually use them for the first time
- instead of writing "choice-1" everywhere, sanitize the number once to the value you actually want (-=1)
- finally, magic numbers like "01" and "02" are generally bad; in a real program you would likely use an enum and descriptive labels like ITEM_HEALTHPOT or ITEM_FIREPOT

Which compiler are you using? If it's new enough to have some C++11 features, they can make your life easier in small (and occasionally big) ways.


Thank you very much. I realize the artificial nature. This is a glorified snippet that is mostly designed to teach me how to use and modify vectors. The suggestions I was looking for are exactly the ones you mentioned- just good housekeeping and dev habits in general. I'm learning this myself, so I'm not able to get the benefit of a teacher standing over me going "No- that won't work in six months when you're doing something better."

I'm using Microsoft VS 2012- I'm not sure what "C++11 features" are, but if they make my life easier, I'd certainly be interested in hearing about them!

EDIT: I've applied the changes you suggested, and the code reads much better.

EDIT 2: The next step for me is to turn this into a class, I suppose!

#3VladimirMarenus

Posted 14 November 2012 - 03:59 AM

The code is artificial, and more importantly, it doesn't do anything (except printing stuff). Thus there's very little that could be wrong with it on low level, and in the absence of context it's hard to say anything about design issues.

Just some cosmetic things I'd point out to a student:
- "a" is useless because you could be printing "index+1" instead
- any variables like "choice" should be defined as close as possible to where you actually use them for the first time
- instead of writing "choice-1" everywhere, sanitize the number once to the value you actually want (-=1)
- finally, magic numbers like "01" and "02" are generally bad; in a real program you would likely use an enum and descriptive labels like ITEM_HEALTHPOT or ITEM_FIREPOT

Which compiler are you using? If it's new enough to have some C++11 features, they can make your life easier in small (and occasionally big) ways.


Thank you very much. I realize the artificial nature. This is a glorified snippet that is mostly designed to teach me how to use and modify vectors. The suggestions I was looking for are exactly the ones you mentioned- just good housekeeping and dev habits in general. I'm learning this myself, so I'm not able to get the benefit of a teacher standing over me going "No- that won't work in six months when you're doing something better."

I'm using Microsoft VS 2012- I'm not sure what "C++11 features" are, but if they make my life easier, I'd certainly be interested in hearing about them!

EDIT: I've applied the changes you suggested, and the code reads much better.

#2VladimirMarenus

Posted 14 November 2012 - 03:48 AM

The code is artificial, and more importantly, it doesn't do anything (except printing stuff). Thus there's very little that could be wrong with it on low level, and in the absence of context it's hard to say anything about design issues.

Just some cosmetic things I'd point out to a student:
- "a" is useless because you could be printing "index+1" instead
- any variables like "choice" should be defined as close as possible to where you actually use them for the first time
- instead of writing "choice-1" everywhere, sanitize the number once to the value you actually want (-=1)
- finally, magic numbers like "01" and "02" are generally bad; in a real program you would likely use an enum and descriptive labels like ITEM_HEALTHPOT or ITEM_FIREPOT

Which compiler are you using? If it's new enough to have some C++11 features, they can make your life easier in small (and occasionally big) ways.


Thank you very much. I realize the artificial nature. This is a glorified snippet that is mostly designed to teach me how to use and modify vectors. The suggestions I was looking for are exactly the ones you mentioned- just good housekeeping and dev habits in general. I'm learning this myself, so I'm not able to get the benefit of a teacher standing over me going "No- that won't work in six months when you're doing something better."

I'm using Microsoft VS 2012- I'm not sure what "C++11 features" are, but if they make my life easier, I'd certainly be interested in hearing about them!


#1VladimirMarenus

Posted 14 November 2012 - 03:28 AM

The code is artificial, and more importantly, it doesn't do anything (except printing stuff). Thus there's very little that could be wrong with it on low level, and in the absence of context it's hard to say anything about design issues.

Just some cosmetic things I'd point out to a student:
- "a" is useless because you could be printing "index+1" instead
- any variables like "choice" should be defined as close as possible to where you actually use them for the first time
- instead of writing "choice-1" everywhere, sanitize the number once to the value you actually want (-=1)
- finally, magic numbers like "01" and "02" are generally bad; in a real program you would likely use an enum and descriptive labels like ITEM_HEALTHPOT or ITEM_FIREPOT

Which compiler are you using? If it's new enough to have some C++11 features, they can make your life easier in small (and occasionally big) ways.


Thank you very much. I realize the artificial nature. This is a glorified snippet that is mostly designed to teach me how to use and modify vectors. The suggestions I was looking for are exactly the ones you mentioned- just good housekeeping and dev habits in general. I'm learning this myself, so I'm not able to get the benefit of a teacher standing over me going "No- that won't work in six months when you're doing something better."

I'm using Microsoft VS 2012- I'm not sure what "C++11 features" are, but if they make my life easier, I'd certainly be interested in hearing about them!

PARTNERS