18 April 2014

Another quiz idea for your consideration: Code Pong

Thanks for all your feedback on the PL/SQL Countdown quiz. I am certain we will add that to the mix soon.

And since I have decided to no longer keep all my best ideas to myself ( :-) ), I offer another idea for a "quiz", though it is not really a quiz, I suppose. More of a "game"?

I call it Code Pong (some of you may know of the classic Pong game). Here's how it would work:

It starts with a piece of rather awful code (likely a function or procedure that is supposed to do X or display certain output). It has all sorts of issues: outright bugs, typos, logic flaws, etc.

Two people sign up to play. And they each take turns applying changes to the code to improve it. The rules for making a change are:

1. You can change 1 line.
2. You can insert up to 3 lines.
3. You can delete up to 3 lines.
4. You can reject the other player's last move.
5. Assert that the game is done.
6. Accept or reject other player's assertion that game is done.

Player must include a description of the change: how does it help get closer to a solution?

What this means is that you can't make one big wholesale change to the code to fix it. Instead, you must work with the other player, sometimes following their lead, sometimes leading the way, to make changes until you believe the code works and all the problems are removed (that is, it not only works, but also is now a program that is easy to understand and maintain.

Here's a simple example: Change the code so that "9" is displayed.
DECLARE
   l_index NUMBER;
BEGIN
   FOR rec IN (SELECT * FROM all_source WHERE rownum < 10)
   LOOP
      l_index := l_index + 1;
   END LOOP;
   DBMS_OUTPUT.PUT_LINE (l_index)
END;

Move 1 (player 1):

Change line 2 to:

l_index PLS_INTEGER;

Explanation: PLS_INTEGER is faster than NUMBER and you do not need NUMBER.

Move 2 (player 2):

Change line 2 to:

l_index PLS_INTEGER := 1;

Explanation: the default initial value is NULL and adding 1 to NULL returns 1. So l_index stays NULL throughout.

Move 3 (player 1):

Assert that game is done.

Move 4 (player2):

Accept; game is done!

What do you think? Too complicated? Too strange?


11 comments:

  1. I think it is pretty nice idea. we should discuss with other players and make it practical.

    ReplyDelete
  2. Great idea! I think it will be nice to have a possibility to see other's pong duels and comment them later.

    ReplyDelete
  3. It looks very interesting. I'd really like to try it!

    Kind regards,
    Frank

    ReplyDelete
  4. I think we need to change the rules a bit
    You can change / insert / delete EXACTLY one line.
    One line should not contain more than one semicolon (to avoid multiple operations located on one line)

    Viacheslav

    ReplyDelete
  5. I didn't understand. Who is the winner of the game?

    ReplyDelete
  6. Excellent question, Vitaliy.

    One possibility is the pair that is able to make the necessary changes in the smallest number of moves.

    But I'd sure like to be able to verify the correctness of the result automatically, and that can be tough.

    Another possibility is that we let players vote (likes) which they feel is the best solution.

    ReplyDelete
  7. If we adopt voting policy then weight of vote of player should be equal to rank of player. because non experience player can't judge the best solution properly.

    ReplyDelete
  8. Steven,

    I think, this is a perfect idea. In addition, it should be showed more performance issues rather than typos or logic flows. Moreover, performances issues relevant to SQL queries can be also asked (Execution plan, trace etc.). I think, this is the lack of Oracle, I mean Oracle cannot provide enough information about Execution plan, tracing, etc. for SQL queries. You know these things are very important for us.

    Regarding to the winner, I think, "players vote which they FEEL is the best solution" is not good idea. Because, maybe people believe that the answer is the best solution. However, we cannot be sure without testing it and see the results (efficiency, time).

    Also, it resembles me to "write no necessery code" quizes. In fact, I was going to ask, why "write no necessery code" quizes have been finished. In general, perfect idea. Keep up mate :)

    PL/SQL community beholden to you for bringing these kinds of creative things.

    Caglar

    ReplyDelete
  9. Thanks for the reminder about the "write no unnecessary code" quizzes, Calgar! I will do that for the next Challenge quiz.

    ReplyDelete
  10. This sounds like a lot of fun, but I'm not sure if there's a good way to rank solutions. For one thing, if speed was a factor then both parties would have to commit to being available for the same time slot - this could be hard given other commitments, different time zones etc.
    So maybe it should be offered 'just for fun' - but also it would be a good way of making 'coding friends' which woulf be cool.

    BTW - shouldn't l_index be initialised to 0?

    JasonC

    ReplyDelete
  11. I am sorry but I believe that the game isnt done... the code is not work until you put semicolon in line 9.
    :)
    and as Jason said the index should be initialised to 0 not 1;

    ReplyDelete