Giter Club home page Giter Club logo

emilybache / tennis-refactoring-kata Goto Github PK

View Code? Open in Web Editor NEW
669.0 19.0 1.2K 1.51 MB

This is a Refactoring Kata based on the rules of Tennis

Home Page: https://youtu.be/XifUs1FhWRc

License: MIT License

C++ 9.95% Python 6.33% C# 6.09% Go 2.09% Java 5.81% JavaScript 7.02% Objective-C 3.20% OCaml 1.57% Perl 2.58% PHP 3.64% Ruby 2.17% Scala 2.47% Makefile 0.14% HTML 2.12% ABAP 5.20% Groovy 1.91% TypeScript 29.86% Swift 2.73% Kotlin 3.56% CMake 1.54%

tennis-refactoring-kata's Introduction

Support this and all my katas via Patreon

Tennis Refactoring Kata

You can find out more about this exercise and where it comes from in this YouTube video. There are also some Guided Learning Hour videos that include demos of me solving parts of it.

The Scenario

Imagine you work for a consultancy company, and one of your colleagues has been doing some work for the Tennis Society. The contract is for 10 hours billable work, and your colleague has spent 8.5 hours working on it. Unfortunately he has now fallen ill. He says he has completed the work, and the tests all pass. Your boss has asked you to take over from him. She wants you to spend an hour or so on the code so she can bill the client for the full 10 hours. She instructs you to tidy up the code a little and perhaps make some notes so you can give your colleague some feedback on his chosen design. You should also prepare to talk to your boss about the value of this refactoring work, over and above the extra billable hours.

There are several versions of this refactoring kata, each with their own design smells and challenges. I suggest you start with the first one, with the class "TennisGame1". The test suite provided is fairly comprehensive, and fast to run. You should not need to change the tests, only run them often as you refactor.

There is a deliberate error in several of the implementations - the player names are hard-coded to "player1" and "player2". After you refactor, you may want to fix this problem and add suitable test cases to prove your fix works.

If you like this Kata, you may be interested in my books and website SammanCoaching.org

Kata Description

Here is a description of the problem this code is designed to solve: Tennis Kata.

Questions to discuss afterwards

  • How did it feel to work with such fast, comprehensive tests?
  • Did you make mistakes while refactoring that were caught by the tests?
  • If you used a tool to record your test runs, review it. Could you have taken smaller steps? Made fewer refactoring mistakes?
  • Did you ever make any refactoring mistakes and then back out your changes? How did it feel to throw away code?
  • What would you say to your colleague if they had written this code?
  • What would you say to your boss about the value of this refactoring work? Was there more reason to do it over and above the extra billable hour or so?

Code Reading Practice

Test your code reading skills. Here is a description of what to do: Scanning for Code Smells. There are suitable lists of urls to open in some of the language subdirectories.

tennis-refactoring-kata's People

Contributors

alexboly avatar balp avatar codecop avatar colindecarlo avatar danipardo avatar dependabot[bot] avatar dertseha avatar devl avatar dvrensk avatar emilybache avatar garak avatar hsegnitz avatar ivanrublev avatar jonasg avatar junior-ales avatar lechus avatar leider avatar leon19 avatar luisrovirosa avatar marcoemrich avatar matthiaslischka avatar neppord avatar objarni avatar paulroho avatar pen-y-fan avatar shawnbutton avatar stephansvoboda avatar ursmetz avatar ygrek avatar ytyubox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tennis-refactoring-kata's Issues

Java: use build management tool

Having used the Java version of the kata I've found it a bit complicated to "get the code into the IDE", e.g. make the IDE recognize the source folders etc. (at least using Eclipse). I think this could be made easier by using a build management tool like Maven or Gradle as the corresponding plugins for Eclipse and IntelliJ allow to easily import Java projects managed by one of the tools mentioned. Additionally, dependencies like JUnit or Hamcrest could be declared so that users of the kata would need to add them manually to the project (or depend on their IDE to user the version shipped with it).

Would this be a welcomed pull request? If so I could provide a build file for Maven and/or Gradle.

Sugerencia code smell Speculative Generality

Hola, he leido tu código y he encontrado lineas de código en la clase TennisGame2 que no tienen ningún uso ni aportan funcionalidad a tu programa, por lo que te recomendaría usar una técnica de refactorización para solucionar esto.

Técnica de refactorización: Te recomiendo que elimines esta parte de tu código y la pongas cuando realmente vayas a usarla para que no compliques el entendimiento del mismo

Ojala te sirva de ayuda.

Sugerencia code Smell Primitive Obsession

Hola, revisando tu código detalladamente he detectado un code smell bastante común, primitive obsession este code smell se debe a que usas string para crear los jugadores lo cual complica un poco añadir nuevas funcionalidades al programa.

Técnica de Refactorización: Te recomiendo refactorizar este code smell usando clases en lugar de datos primitivos, podrías crear una clase Player que guarde los datos basicos del jugador y una clase PlayerGameDetails que guarde los datos del jugador referente al juego como su puntaje.

Espero te sirva de ayuda.

GTest translation for C is not very good

Many of the teams I coach in C use googletest, so it seemed like a good idea to have gtest as an alternative to cmocka. So I had a go at a translation, and put it in the subfolder 'c_gtest'. Unfortunately my skills with C and gtest and CMake are really not up to it, and there is a lot of duplication in the test code, and if we're honest, more than's necessary in the production code header files. Anyway I thought I'd put it out there as an issue in case there's anyone who would like to improve on my attempts and send me a pull request :-)

Sugerencia para code smell Switch Case

Hola, revise tu proyecto y hay cosas que podrías cambiar para facilitar el entendimiento del mismo.
En tu clase TennisGame1 tienes una sentencia switch case en el método getScore(), la cual no esta mal pero sin embargo "daña" tu código visualmente por lo que te recomiendo refactorizar este método.

Técnica de refactorización: Para este tipo de code smell te recomiendo extraer esta sentencia en un nuevo método y con el fin de deshacerte del switch-case puedes usar enum, para encapsular los casos del switch.

Test in typescript project are not working

Node Version

14.15.4

Npm version

6.14.10

After installing dependencies and running npm run test the outcome is:

> [email protected] test C:\Users\Carlotta\workspaces\Tennis-Refactoring-Kata\typescript
> TS_NODE_FAST=true mocha --compilers ts:./node_modules/ts-node/register 'tests/**/*.test.ts'

"TS_NODE_FAST" non è riconosciuto come comando interno o esterno,
 un programma eseguibile o un file batch.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `TS_NODE_FAST=true mocha --compilers ts:./node_modules/ts-node/register 'tests/**/*.test.ts'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Carlotta\AppData\Roaming\npm-cache\_logs\2021-08-31T10_58_41_043Z-debug.log
PS C:\Users\Carlotta\workspaces\Tennis-Refactoring-Kata\typescript> code .
PS C:\Users\Carlotta\workspaces\Tennis-Refactoring-Kata\typescript> npm run test

> [email protected] test C:\Users\Carlotta\workspaces\Tennis-Refactoring-Kata\typescript
> mocha --compilers ts:./node_modules/ts-node/register 'tests/**/*.test.ts'

Warning: Could not find any test files matching pattern: 'tests/**/*.test.ts'
No test files found
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `mocha --compilers ts:./node_modules/ts-node/register 'tests/**/*.test.ts'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Carlotta\AppData\Roaming\npm-cache\_logs\2021-08-31T10_59_15_620Z-debug.log

Question to difference in Pythonv vs Java/TypeScript/C# of TennisGame3

First of all thanks for the great collection of Katas

In TennisGame3 WonPoint(playerName) all languages I checked implement it like this:

WonPoint(playerName)
    if playerName == "player1"

So if in "production" we want to know the score of Nadal vs Djokovic Nadal will never score a point or better said each point Nadal scores is counted for Djokovic.

In Python it is different:
if n == self.p1N

Is this difference intentional? Maybe to provoke the question if bugs should be fixed while refactoring.

Introductory text is not helpful

The introductory text suggests that refactoring is just a means to spend some billable hours on a project. That paints a dangerously wrong picture to some people. Wouldn't it suffice to say that e.g. "you" have been tasked with adding a new feature to the program and decided to clean up first?

CS Tests dont run

I cloned the repo. Try to run the CSharp tests but an error occurs:

"No test is available in D:**\Tennis-Refactoring-Kata\csharp\Tennis\bin\Debug\net5.0\Tennis.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again"

I'm not sure how to fix this.

C#: Improve the out-of-the-box-experience

For people not used to using NUnit, the following things would be of great help:

  • Provide a solution file
  • Change csproj to a ClassLibrary project, remove then obsolete Main.cs
  • Add nuget package for NUnit
  • Provide a hint how to install the NUnit VsTestAdapter

I will send a pull request.

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.