GithubHelp home page GithubHelp logo

ivanmoore / refactoring-golf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sf105/refactoring-golf

0.0 1.0 2.0 297 KB

An exercise on refactoring

License: GNU General Public License v3.0

Java 100.00%

refactoring-golf's Introduction

Refactoring Golf

A fork of https://github.com/sf105/refactoring-golf - I've slightly changed this readme and included the junit lib for easier import into different versions of IDEs.

To import into intelliJ IDEA, File -> New -> Project from existing sources...

Refactoring Golf is a game designed to stretch your refactoring muscles and to get you to explore your IDE to see what's really possible using shortcuts and automation. The idea is to focus on one aspect of coding and see how far it can be pushed.

This repository contains multiple versions of a simple class to calculate tax on a payslip.

  • The first 5,000 is tax free
  • Up to 20,000 is taxed at 10%
  • Up to 40,000 is taxed at 20%
  • Above 40,000 is taxed at 40%

Each version is a refactoring of the previous version. Sticking with the golf metaphor, going from one version to the next is called a "hole". i.e. Hole1 is payroll.hole01.Payslip -> payroll.hole02.Payslip

Your goal is to refactor from one state of the code to the next state safely and efficiently, using the features of the IDE with as few "strokes" as possible, where a stroke is an action that changes the code. Every stroke costs you points.

Your pairing partner should carefully score you as follows:

  • 0 points for formatting and selection
  • 1 point for every change made to the code using a shortcut or automated IDE feature (e.g., an automated refactoring, code template, rename, or Find/Replace)
  • 2 points for every manual edit. Note that a single "edit" could cover multiple lines of code.
  • There is a double points penalty for changes that leave the code failing the tests or not compiling.

Allow yourselves a maximum of 2 attempts at each round to determine your best score.

Hints

  • Each version has a notes.md file that describes the motivation for the next refactoring.
  • You might want to keep the target code open in another window, or perhaps on the partner's machine. It's easy to get confused about which file is which.
  • Commit your code frequently, especially after each refactoring stage. That will make rolling-back easier if you want to make another attempt or if you get confused.
  • Run the tests after each "stroke". You can do this by selecting the top-level refactoring-golf in the project view and selecting Run 'All Tests' from the pop-up menu.
  • Check your code in frequently so it's easier to try a refactoring more than once. Idea also has an excellent Local History option.

Practical

  • This exercise was written with Intellj Idea. You should be able to clone the repository and Open it as a project.
  • Idea has a Keymap Reference available from the help menu. If you're unfamiliar, it's worth reading this through and keeping it handy
  • Mouse actions are fine to start with, but learn the key shortcuts

Example scores

These are some example scores, achieved using IntelliJ.

HoleBest scoreNotes
1 6
2 3
3 9
4 17 lots of manual edits
5 13
6 14
7 29 This one is quite hard, but is possible
8 8
9 xx

Alternative version

There's an alternative version that was implemented using TDD from scratch in the reimplemented-with-tdd branch of the repository.

Acknowledgements

This exercise was mainly taken from an example by Lance Walton.

Other ideas were taken from David Denton and Ivan Sanchez, inspired by @ivanmoore and @rchatley

These instructions were mostly stolen from @jasongorman's Refactoring Golf.

Notes

  • we used double for the calculations. Using floating point types is usually a bad idea for money, but here it's to simplify the exercises. The alternative TDD version uses long. Both should probably use a decimal format.

refactoring-golf's People

Contributors

sf105 avatar ivanmoore avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.