- Review code with partners and use code review rubric to assess quality
- Compare code quality of functions based on length and responsibility
- Discuss issues with ripple effects caused by tight coupling and ways to avoid it
- Discuss advantages of classes and object-oriented programming (OOP)
After completing this class session and the associated tutorial challenges, students will be able to ...
- Assess aspects of code quality including organization and modularity
- Refactor functions that use structures as class instance methods
- Plan application architecture to prepare for future expansion
These challenges are the baseline required to complete the project and course. Be sure to complete these before next class session and before starting on the stretch challenges below.
- Page 6: Application Architecture
- Improve code organization and quality based on peer feedback on code review rubric
- Write down your answers to questions about application architecture to plan improvements
- Implement
Dictogram
class (histogram as a subclass ofdict
type) using dictogram starter code:- Implement
add_count(word, count)
- increase the frequency count ofword
in the histogram bycount
- Implement
frequency(word)
- return the frequency count ofword
in the histogram, or0
if not found - Add
types
andtokens
properties that track the number of word types and tokens in the histogram - Run
python dictogram.py
to testDictogram
class instance methods on a few small examples - Run
pytest dictogram_test.py
to run the dictogram unit tests and fix any failures
- Implement
- Implement
Listogram
class (histogram as a subclass oflist
type) using listogram starter code:- Implement
add_count(word, count)
- increase the frequency count ofword
in the histogram bycount
- Implement
frequency(word)
- return the frequency count ofword
in the histogram, or0
if not found - Implement
__contains__(word)
- return a boolean indicating whetherword
is in the histogram - Implement
_index(word)
- return the index of the entry containingword
if found in the histogram, orNone
if not found - Add
types
andtokens
properties that track the number of word types and tokens in the histogram - Run
python listogram.py
to testListogram
class instance methods on a few small examples - Run
pytest listogram_test.py
to run the listogram unit tests and fix any failures
- Implement
- Restructure code files and functions to be more modular and flexible
These challenges are more difficult and help you push your skills and understanding to the next level.
- Page 6: Application Architecture
- Organize other app functions and classes based on your answers to app architecture questions
- Bonus challenges
- Improve the speed of accessing word frequencies in the
Listogram
class by storing entries in sorted order and searching for them in a clever way- An elegant way to do this is to make a
SortedListogram
class that inherits from theListogram
class and overrides some instance methods to specialize their behavior to handle entries in sorted order
- An elegant way to do this is to make a
- Want to make the
Listogram
class more convenient to use? Add methods so that it can be used as an iterable container, such as in afor
loop like this:fish_text = 'one fish two fish red fish blue fish' histogram = Listogram(fish_text.split()) for word in histogram: freq = histogram.frequency(word) print('{} occurs {} times'.format(word, freq))
- Improve the speed of accessing word frequencies in the