View Single Post
  #6   Spotlight this post!  
Unread 17-12-2009, 22:25
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Driverstation Pong!

Quote:
Originally Posted by Bigcheese View Post
This is quite a cool idea, although I did take a look at your code and found some issues.
  • There are quite a few places where there's no code formatting, making it very difficult to read.
  • The use of a try/catch statement for program flow is bad. There's no reason to do this. Simply use a goto statement if you want to reenter the loop.

Now, to defend the use of goto.
Using an exception is the exact same thing as a goto in this case, except that the try/catch implies something different is going on, and ignores all real exceptions because of the catch(...).

Yes, you could use some extra logic to handle exiting the double loop, but in the end, the simplest, and most readable solution is to have a label directly before the main while, and a goto on win.

Although the best solution would be to split the code up into separate functions such as.
  • Setup
  • WaitForStart
  • Update - Returns a value in {continue, player_1_won, player_2_won}

Then the problem wouldn't be there to begin with .
I know, Its not ideal (I could improve it a ton), but I did not want to spend too much time designing if statements, remembered about exceptions, and used them. (I did not think of goto until just now, being a very OOPy programmer)
Quote:
Originally Posted by John G View Post
cool. At first glance, I thought you were talking about "apple juice" pong. I then imagined trying to play DS pong and how hard it wouold be.
It is hard, I have a 30-40% hitting rate! (and about half are lost on the first hit)
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib

Last edited by byteit101 : 17-12-2009 at 22:28.