Skip to content

Instantly share code, notes, and snippets.

@SonOfLilit
Last active May 30, 2022 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SonOfLilit/a32560011ada5e668ec733c446772475 to your computer and use it in GitHub Desktop.
Save SonOfLilit/a32560011ada5e668ec733c446772475 to your computer and use it in GitHub Desktop.
Refactoring challenge from Clean Code on Toilet #1: Naming Things.
# 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