Skip to main content

It is tempting to write the code and thethen see if the result "looks right", but, as you rightly intuit, it's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calculation of the result easier.

  1. Use Excel. setSet up a spreadsheet that does some or all of the calculation for you. Keep it simple enough so that you can see the steps.

  2. Split your method up into smaller testable methods, each with itstheir own tests. When you are sure the smaller parts work, use them to manually work through the next step.

  3. Use aggregate properties to sanity-check. E.g.For example, say you have a probability calculator; you might not know what the individual results should be, but you know they all have to add up to 100%.

  4. Brute force. Write a program that generates all possible results, and check that none are better than what your algorithm generates.

It is tempting to write the code and the see if the result "looks right" but, as you rightly intuit, it's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calculation of the result easier.

  1. Use Excel. set up a spreadsheet that does some or all of the calculation for you. Keep it simple enough so that you can see the steps.

  2. Split your method up into smaller testable methods each with its own tests. When you are sure the smaller parts work, use them to manually work through the next step.

  3. Use aggregate properties to sanity-check. E.g., say you have a probability calculator; you might not know what the individual results should be, but you know they all have to add up to 100%.

  4. Brute force. Write a program that generates all possible results, and check that none are better than your algorithm generates.

It is tempting to write the code and then see if the result "looks right", but, as you rightly intuit, it's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calculation of the result easier.

  1. Use Excel. Set up a spreadsheet that does some or all of the calculation for you. Keep it simple enough so that you can see the steps.

  2. Split your method up into smaller testable methods, each with their own tests. When you are sure the smaller parts work, use them to manually work through the next step.

  3. Use aggregate properties to sanity-check. For example, say you have a probability calculator; you might not know what the individual results should be, but you know they all have to add up to 100%.

  4. Brute force. Write a program that generates all possible results, and check that none are better than what your algorithm generates.

Tidied up spelling, sentence breaks, punctuation, and capitalization
Source Link

It is tempting to write the code and the see if the result 'looks right'"looks right" but, as you rightly intuit. It's, it's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calccalculation of the result easier.

  1. Use excelExcel. set up a spreadsheet that does some or all of the calccalculation for you. Keep it simple enough so that you can see the steps.

  2. Split your method up into smaller testable methods each with its own tests. When you are sure the smaller parts work. Use, use them to manually work through the next step.

  3. Use agreegateaggregate properties to sense checksanity-check. Ie E.g., say you have a probablity calculatorprobability calculator; you might not know what indivialthe individual results should be, but you know they all have to add up to 100%.

  4. Brute force. Write a program that generates all possible results, and check that none are better than your algorithimalgorithm generates.

It is tempting to write the code and the see if the result 'looks right' but as you rightly intuit. It's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calc of the result easier.

  1. Use excel. set up a spreadsheet that does some or all of the calc for you. Keep it simple enough so that you can see the steps

  2. Split your method up into smaller testable methods each with its own tests. When you are sure the smaller parts work. Use them to manually work through the next step.

  3. Use agreegate properties to sense check. Ie say you have a probablity calculator you might not know what indivial results should be, but you know they all have to add up to 100%

  4. Brute force. Write a program that generates all possible results and check that none are better than your algorithim generates.

It is tempting to write the code and the see if the result "looks right" but, as you rightly intuit, it's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calculation of the result easier.

  1. Use Excel. set up a spreadsheet that does some or all of the calculation for you. Keep it simple enough so that you can see the steps.

  2. Split your method up into smaller testable methods each with its own tests. When you are sure the smaller parts work, use them to manually work through the next step.

  3. Use aggregate properties to sanity-check. E.g., say you have a probability calculator; you might not know what the individual results should be, but you know they all have to add up to 100%.

  4. Brute force. Write a program that generates all possible results, and check that none are better than your algorithm generates.

Source Link
Ewan
  • 79.9k
  • 5
  • 83
  • 179

It is tempting to write the code and the see if the result 'looks right' but as you rightly intuit. It's not a good idea.

When the algorithm is hard you can do a number of things to make the manual calc of the result easier.

  1. Use excel. set up a spreadsheet that does some or all of the calc for you. Keep it simple enough so that you can see the steps

  2. Split your method up into smaller testable methods each with its own tests. When you are sure the smaller parts work. Use them to manually work through the next step.

  3. Use agreegate properties to sense check. Ie say you have a probablity calculator you might not know what indivial results should be, but you know they all have to add up to 100%

  4. Brute force. Write a program that generates all possible results and check that none are better than your algorithim generates.