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 our function multiple times within a single function call, to avoid the
tedious task of manually calling our function over and over again.
My advice about how to prepare for this course is to consistently
review the lecture materials because most of the topics build on one another. In addition, the weekly exercises are very useful
as they are representative of what the weekly quizzes will be like. Moreover, I highly suggest attempting the
past tests because they are also very representative of what will appear on the
term tests. Likewise, if you have any
questions, the discussion board on Piazza is very useful since the TA’s and
instructors answer questions from students directly.
Comments
Post a Comment