Last active
May 30, 2022 22:31
-
-
Save SonOfLilit/a32560011ada5e668ec733c446772475 to your computer and use it in GitHub Desktop.
Refactoring challenge from Clean Code on Toilet #1: Naming Things.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fork and refactor before you look at the official solution[1] or other players' forks | |
# [1]: https://bit.ly/ccot1solution | |
class PlayerRecorder: | |
def user_clicked_piano_note(self, value): | |
self.engine.send_note(value) | |
if self.play and self.r: | |
if value[0] == ON: | |
self.temp[value[1]] = value | |
elif value[0] == OFF: | |
self.temp.pop(value[1]) | |
bisect.insort(self.recorded, (self.time_int, value[1:])) | |
def user_clicked_R(self, value): | |
self.r = value | |
if not value: | |
for value in self.temp.values(): # turn off all held notes | |
self.temp.pop(value[1]) | |
bisect.insort(self.recorded, (self.time_int, value[1:])) | |
self.temp = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment