Assignment 1 Common ErrorsContractIn the contract, some students used nat when num was more appropriate. num, int, and nat are different:
Many students did not include type restrictions in the contracts. For example, in question 3, the individual and synchronization scores must be between 0 and 10, a restriction of [>=0, <=10] can be included for each parameter in the contract. PurposeSome students did not refer to the parameters. The purpose should mention the parameters by name, and briefly describe their meaning. TestsMany students did not have enough tests. You should test boundary cases, as well as typical cases. For example, if a function consumes positive integers, then you should include a test where the function consumes 1, the smallest positive integer. Here are the test cases that students missed:
ConstantsMany students did not use constants in questions 1 and 3. Constants allow you to give names to numbers. In question 1, when someone reads your code and sees the number 5 in your function, they may wonder where it came from or what its meaning is. However, if you define it as a constant with a meaningful name, such as fee, then the reader can infer from the name fee that the value is the service charge. Similarly, in question 3, you should define the adjustment factor of 0.6 as a constant. Helper FunctionsMany students did not use helper functions. You should use helper functions to reduce repeated expressions and the amount of code in the main function. For example, in question 3, you can use a helper function to calculate the individual score, and use that helper function two or more times in your main function. When you use helper functions, give them meaningful names. WhitespacePlease follow the whitespace rules in the Style Guide. In particular, try to avoid long lines and indent your code properly. DrRacket can indent your code for you. Click "Racket" from the menu bar and choose "Reindent All". |
Last modified on Wednesday, 03 October 2012, at 15:11 hours.
Course Supported by Instructional Support Group