HWZ Forums

Login Register FAQ Mark Forums Read

C++ help needed :(

Like Tree20Likes
Reply
 
LinkBack Thread Tools
Old 30-10-2013, 07:38 PM   #16
Junior Member
 
Join Date: May 2008
Posts: 84
woah...i think we should look at TS question...the question asked about preferred method, there is no right or wrong method as long as it gets the job done, both are correct and both get the job done. Based on my experience version 2 is preferred imho. why?

v1 have 2 return code, and v2 has 1. Maintaining v2 code is definitely easier. When your function code size increases (think 100lines - 1000lines compared to 10 lines here?) and it is suppose to return a value, you would be sure you want to have a single return point.

p.s. hope you have fun learning programming!
saysuzu and aaronxg like this.
leofireng86 is offline   Reply With Quote
Old 30-10-2013, 08:14 PM   #17
Arch-Supremacy Member
 
reno77's Avatar
 
Join Date: Jun 2000
Posts: 13,113
Well you are not casting your x y to int, so version 1 I think will crash if a char is entered, version 2 might return a uninitialized random maxno

C++ character to int - Stack Overflow
saysuzu likes this.
reno77 is offline   Reply With Quote
Old 30-10-2013, 11:09 PM   #18
Member
 
Join Date: Jun 2010
Posts: 312
Thank you all for your help!
Time to digest
aaronxg is offline   Reply With Quote
Old 23-11-2013, 10:51 PM   #19
Master Member
 
Join Date: Nov 2003
Posts: 4,888
IN the real world and the software world, things are not always in black and white. Some things are still useful in some scenarios. I resort to the mentioned optimization in a image processing tight loop where in debug mode, the process cannot keep up with the required fps. I also use in LUA where the code is interpreted simply, not optimized. Of cos, as rule of thumb, when doing programming, we should not put on optimizing hat, except where it really matters.
AnimeNewbie is offline   Reply With Quote
Reply
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Terms of Service for more information.


Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On