Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think some of your code is a bit too verbose and fluffy to let you see what's really going on. Take this small section:</p> <pre><code>if (foundGold1 == true) { if (field.alreadyFound1() == true) { } else { robot2.addGold(); field.foundGold1(); } } </code></pre> <p>It could be written like this:</p> <pre><code>if (foundGold1) { if (! field.alreadyFound1()) { robot2.addGold(); field.foundGold1(); } } </code></pre> <p>Depending upon how this code will "grow" over time, you might want to simplify it a little further:</p> <pre><code>if (foundGold1 &amp;&amp; ! field.alreadyFound1()) { robot2.addGold(); field.foundGold1(); } </code></pre> <p>Please note Matthew Cox's warning: <em>young programmers often get caught up in trying to minify their code as much as they possibly can (Look I did it in 2 lines of code instead of 3!)</em> -- I'm not arguing for the reformatted layout because it is smaller but because <em>I believe this is easier to read</em>. Depending upon the complexity of future code, I might give exactly the opposite advice to break apart conditions. The top priority is writing legible code. (The compiler can figure out nearly anything you throw at it -- <em>you</em> have to be able to understand it too.)</p> <p>His further advice to use arrays for <code>foundBomb[]</code>, <code>foundGold[]</code>, <code>robot[]</code>, etc. is superb -- and is best paired with using function <em>arguments</em> instead of writing multiple functions.</p> <p>Instead of <code>field.alreadyFound1()</code>, <code>field.alreadyFound2()</code>, etc, try: <code>field.alreadyFound(int something)</code> -- when you call them, it'll be <code>field.alreadyFound(2)</code>. This lets you cut the number of functions by three (which means you won't have to fix bugs three times in each function) and makes it easier to grow the program to five or six fields, piles of gold, bombs, robots, etc. It's just a parameter to a function then.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload