Skip to content

Latest commit

 

History

History
65 lines (35 loc) · 3.25 KB

File metadata and controls

65 lines (35 loc) · 3.25 KB

Exercise: Fix the smelly code

You will learn to

  • Identify bad code
  • Fix code smells
  • Refactor with tests

How to get started

  • Start by cloning this repository into a folder on your computer. If you've never used git before, you can alternatively use the the "Download ZIP" button to the right.
  • Although you have this README.md file on your computer it's easier to read it on GitHub, so we recommend you keep this page open with the exercise tasks.

Required software and tools for this exercise

❓ Not familiar with IntelliJ? Take a look at the User interface docs and the interactive training course inside IntelliJ.

1.0 - Opening the "Pub" example code in IntelliJ

📖 This repository contains an "Pub" example app.

✏️ Open pom.xml in IntelliJ by selecting Open from the Welcome Screen. You can also use File --> Open --> and then select the pom.xml. (See Open an existing Maven project in the IntelliJ docs for more info about how to open projects.)

✏️ Select Open as Project.

1.1 - Run tests

✏️ Run all the tests in the PubPricesTest class and verify that they are all green. (See Run tests in the IntelliJ docs for more info about how to run tests.)

1.2 - Examining the code and the tests

✏️ Examine the tests and the code in the Pub class.

❓ What does this code do? Before you start changing the code, understand what the code does.

❓ What is wrong with the code? There are naming issues, magical numbers, bad structure and more.

1.3 - Refactoring the code

📖 The main part of this exercise is to refactor the code. Remember that refactoring is all about changing the internal structure of the code without changing its behavior.

❗ Remember to run the tests after each change to verify that behavior is unchanged

You'll get to do much of this on your own, but here are some fairly small tasks to start with. :

✏️ Fix all the magical numbers.

✏️ Rename existing functions so their names reflect what they do.

✏️ Remove bad comments.

✏️ Make functions where appropriate if there are clear bits of the code that are independent of the rest.

1.4 - Refactoring the code - freestyling

From now on you're on your own. There are many ways to refactor this code and not necessarily one correct one. It's useful to discuss whether you see any code that should be separated into and what each class should do.

❓ Can any of the code structures you've learned about make this code easier to read and easier to maintain?

❓ If you add more drinks to the menu, how can you make the code support this in the best way possible?

📖 See smells.md for a shortlist of code smells and how to fix them.