Writing clean and elegant code is more that just following a specific style. It involves a continuous work flow of rewriting, restructuring, and rethinking how your code functions. Homework 2 will get you started in the journey of developing code that smells good.
-
Read sections 13.1 - 13.4 in Advanced R by Hadley Wickham.
-
Watch Code Smells and Feels by Jenny Bryan. Her slides and related materials are available on GitHub here.
As a team, agree on a common coding style. You may want to refresh yourself with Hadley's style guide before you agree on a consistent style.
Create a new class for the S3 OOP system along with two methods. You may
create a new S3 generic or use an existing one. For your class include
constructor, validator, and helper functions. Demonstrate your class and methods
with two examples for each method. One working example for inspiration of an
S3 class is given by the "Roman" class. See ?utils::as.roman()
.
A portion of the total points for this task will be allocated to the complexity level of the class and methods you create.
Provide a write-up that explains your class and methods. Discuss weaknesses and possible improvements.
Please keep the tasks separated in your R Markdown file.
The deadline to submit Homework 2 is 11:59pm on Wednesday, February 5. Only your final commit and code in the master branch will be graded. Do not forget to push your work to your assigned team repository on GitHub before the deadline.
-
Post your questions in the #hw2 channel on Slack. Explain your error / problem in as much detail as possible or give a reproducible example that generates the same error. Make use of the code snippet option available in Slack.
-
Visit the instructor or TAs in office hours.
-
The instructor and TAs will not answer any questions unrelated to directions and interpretation within the first 12 hours of this homework being assigned, and they will not answer questions within 6 hours of the deadline.
This is a team assignment. You should not communicate with other teams. As a reminder, any code you use directly or as inspiration must be cited.
To uphold the Duke Community Standard:
- I will not lie, cheat, or steal in my academic endeavors;
- I will conduct myself honorably in all my endeavors; and
- I will act if the Standard is compromised.
Topic | Points |
---|---|
Task 3 | 15 |
Task 4 | 6 |
at least 1 significant commit per team member | 4 |
Code style and format | 4 |
Named R code chunks | 1 |
Total | 30 |
Documents that fail to knit after minimal intervention will receive a 0.