CSC104 SLOG Week 9
What advice would you give to a student beginning this course about (a) how to design a function, and (b) how to prepare for this course? My advice to a student beginning this course about how to design a function is to first describe what the function will do. This can be achieved by writing a function contract, for example function-name: number -> number. In addition, writing a full-design check-expect is helpful because we can start with our output value, and work backwards to recreate that output. We can then substitute check-expect with define and each variable with a parameter. Depending on what the function is intended to do, it may be necessary to think about special cases and recursion. To illustrate, in the Fibonacci sequence, the first and second terms are both 1. Therefore, when a defining a function to compute the Fibonacci sequence, we will need to include the special case of n < 2 in our function design. Likewise, we can use the power of recursion to call