Skip to main content
Code Review

Return to Answer

added 42 characters in body
Source Link
l0b0
  • 9.1k
  • 22
  • 36

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method:

     MAX_ROUNDS = 5
     class Player:
     def __init__(self):
     self.score = 0
     def win(self):
     self.score += 10
     def lose(self):
     self.score -= 5
     class Game:
     rounds = 0
     player_1 = Player()
     player_2 = Player()
     def play():
     if self.rounds >= MAX_ROUNDS:
     ...
     else:
     ...
     self.rounds += 1
    
  • Dependency injection of randint and input would allow this code to be unit tested.

  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method:

     MAX_ROUNDS = 5
     class Player:
     score = 0
     def win(self):
     self.score += 10
     def lose(self):
     self.score -= 5
     class Game:
     rounds = 0
     player_1 = Player()
     player_2 = Player()
     def play():
     if self.rounds >= MAX_ROUNDS:
     ...
     else:
     ...
     self.rounds += 1
    
  • Dependency injection of randint and input would allow this code to be unit tested.

  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method:

     MAX_ROUNDS = 5
     class Player:
     def __init__(self):
     self.score = 0
     def win(self):
     self.score += 10
     def lose(self):
     self.score -= 5
     class Game:
     rounds = 0
     player_1 = Player()
     player_2 = Player()
     def play():
     if self.rounds >= MAX_ROUNDS:
     ...
     else:
     ...
     self.rounds += 1
    
  • Dependency injection of randint and input would allow this code to be unit tested.

  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

added 500 characters in body
Source Link
l0b0
  • 9.1k
  • 22
  • 36

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method.

    Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method:

     MAX_ROUNDS = 5
     class Player:
     score = 0
     def win(self):
     self.score += 10
     def lose(self):
     self.score -= 5
     class Game:
     rounds = 0
     player_1 = Player()
     player_2 = Player()
     def play():
     if self.rounds >= MAX_ROUNDS:
     ...
     else:
     ...
     self.rounds += 1
    
  • Dependency injection of randint and input would allow this code to be unit tested.

    Dependency injection of randint and input would allow this code to be unit tested.

  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

    If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method.
  • Dependency injection of randint and input would allow this code to be unit tested.
  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method:

     MAX_ROUNDS = 5
     class Player:
     score = 0
     def win(self):
     self.score += 10
     def lose(self):
     self.score -= 5
     class Game:
     rounds = 0
     player_1 = Player()
     player_2 = Player()
     def play():
     if self.rounds >= MAX_ROUNDS:
     ...
     else:
     ...
     self.rounds += 1
    
  • Dependency injection of randint and input would allow this code to be unit tested.

  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.

Source Link
l0b0
  • 9.1k
  • 22
  • 36

Some suggestions:

  • Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a Player class could have a score field and a Game class could have a rounds field and a roll method.
  • Dependency injection of randint and input would allow this code to be unit tested.
  • If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the sleeps.
lang-py

AltStyle によって変換されたページ (->オリジナル) /