¿Para qué estamos aquí? ● Para divertirnos, aprender y compartir ● Practicar TDD (Test-Driven Development) ● Aprender qué es TPP (Transformation Priority Premise) ● Trabajar en parejas y con pomodoros
¿Qué es un Coding Dojo? ● Lugar donde aprender, mejorar y divertirse programando ● Lugar donde experimentar ● Lugar seguro para practicar: diseño, testing, refactoring, herramientas, etc. ● En parejas: humildad, generosidad, agradecimiento ● Práctica deliberada ● NO es un curso ni una formación ni una “clase maestra”: facilitadores
Kata de números romanos https://github.com/CraftersEntrePercebes/RomanNumerals http://cyber-dojo.org Write a function to convert from normal numbers to Roman Numerals. (there is no need to be able to convert numbers larger than about 3000) Ayuda: ● http://www.novaroma.org/via_romana/numbers.html : no más de tres símbolos similares seguidos ● https://www.rapidtables.com/convert/number/roman-numerals-converter.html
Baby steps y el problema del impás Baby steps ● RED -> GREEN: escribir el mínimo código necesario para pasar el test. ● Feedback rápido ● Baja complejidad en cada iteración El problema del impás ● Mala elección en el orden de creación de los tests: bloqueo y “explosión”. ● No hacer el código cada vez más genérico con cada test.
Transformation Priority Premise ● Transformation -> Modifica el comportamiento del código ● Cada transformación tiene una prioridad o un orden ● Cuanta más alta es la prioridad, más simple es la transformación ● Ayuda al programador a crear el paso más simple posible (Baby step) ● El código va de específico a genérico
TDD and TPP ● When passing a test, prefer higher priority transformations. ● When posing a test choose one that can be passed with higher priority transformations. ● When an implementation seems to require a low priority transformation, backtrack to see if there is a simpler test to pass
Example - Word Wrap Kata ({}–>nil) - Red public static String wrap(String s, int length) { return null; } (nil->constant) - Green public static String wrap(String s, int length) { return ""; }
Example - Word Wrap Kata (nil–>constant) - Green @Test public void WrapEmptyStringReturnsEmptyString() throws Exception { assertThat(wrap("", 10), is("")); }
Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("word", 5), is("word")); }
Example - Word Wrap Kata (unconditional->if) & (constant->scalar) - Green public static String wrap(String s, int length) { if (s == null) return ""; return s; } Ignoramos la premisa con mayor prioridad
Example - Word Wrap Kata (constant->constant+) - Red @Test public void TwoWordsLongerThanLimitShouldWrap() throws Exception { assertThat(wrap("word word", 6), is("word\nword")); }
Example - Word Wrap Kata (expression->function) - Green (Too low in the list) public static String wrap(String s, int length) { if (s == null) return ""; return s.replaceAll(" ", "\n"); }
Example - Word Wrap Kata (constant->constant+) - Red @Test public void ThreeWordsJustOverTheLimitShouldWrapAtSecondWord() throws Exception { assertThat(wrap("word word word", 9), is("word word\nword")); } ¡Atención Impás!
Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("word", 5), is("word")); }
Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("otherword", 10), is("otherword")); }
Example - Word Wrap Kata (constant->constant+) - Red @Test public void TwoWordsLongerThanLimitShouldWrap() throws Exception { assertThat(wrap("word word", 6), is("word\nword")); }
Example - Word Wrap Kata (constant->constant+) - Red @Test public void WordLongerThanLengthBreaksAtLength() throws Exception { assertThat(wrap("longword", 4), is("long\nword")); }
Example - Word Wrap Kata (unconditional->if) - Green public static String wrap(String s, int length) { if (s == null) return ""; if (s.length() <= length) return s; else { return "long\nword"; } }
Example - Word Wrap Kata (statement->statements) - Red @Test public void WordLongerThanLengthBreaksAtLength() throws Exception { assertThat(wrap("longword", 4), is("long\nword")); assertThat(wrap("longerword", 6), is("longer\nword")); }
Example - Word Wrap Kata (expression->function) - Green public static String wrap(String s, int length) { if (s == null) return ""; if (s.length() <= length) return s; else { return s.substring(0, length) + "\n" + s.substring(length); } }
Example - Word Wrap Kata (constant>constant+) - Red @Test public void WordLongerThanTwiceLengthShouldBreakTwice() throws Exception { assertThat(wrap("verylongword", 4), is("very\nlong\nword")); }
Example - Word Wrap Kata (statement->recursion) - Green public static String wrap(String s, int length) { if (s == null) return ""; if (s.length() <= length) return s; else { return s.substring(0, length) + "\n" + wrap (s.substring(length), length); } }
Algunas reflexiones ● ¿Existen otras transformaciones? (seguramente) ● ¿Son éstas las transformaciones correctas? (probablemente no) ● ¿Existen mejores nombres para las transformaciones? (casi sseguro) ● ¿Existe realmente una prioridad?
Resumiendo, que es gerundio ● It appears that the green phase can be achieved by employing a fixed set of behavior changing transformations to the code. ● These changes move the code from a specific form to a more generic form. ● It also appears that these transformations have a preferred order based on complexity. This ordering can be used in both the red and green phases of TDD. ● TDD impasses will be reduced or eliminated.
Sobre la kata de números romanos y TPP ● Blog post: ○ https://codurance.com/2015/05/18/applying-transformation-priority-premise-to-roman-n umerals-kata/ ○ https://8thlight.com/blog/micah-martin/2012/11/17/transformation-priority-premise-appli ed.html (it includes screencast with TPP for another kata) ● Screencasts: ○ http://blog.coreyhaines.com/2012/12/roman-numerals-kata-with-commentary.html ○ https://www.infoq.com/presentations/TDD-Managers-Nicolette-Scotland ○ https://vimeo.com/15104374 ● Uncle Bob - Advanced TDD, the Transformation Priority Premise [min 34:00]: https://vimeo.com/97516288
Screencasts ● Screencasts de Sandro Mancuso: ○ Algorithms: https://www.youtube.com/watch?v=iZjgj1S0FCY ○ Outside-In TDD: ■ https://www.youtube.com/watch?v=XHnuMjah6ps ■ https://www.youtube.com/watch?v=24vzFAvOzo0 ● Carlos Blé ○ Implementando algoritmos con TDD ○ Kata sobre juego de cartas
Charlas ● Joaquín Engelmo (@kinisoftware) ○ Adicto al verde ○ Dando amor a los tests ● The limited red society ● The three laws of TDD ● Test-Bridle Development (@flipper83), SCPNA
Cursos http://www.codium.team/curso-tdd.html : Vigo, 11 y 12 de junio https://www.codesai.com/curso-de-tdd/ http://www.jbrains.ca/training/the-worlds-best-introduction-to-test-driven-dev elopment/ http://www.codemanship.co.uk/tdd.html Pluralsight: https://www.pluralsight.com/search?q=TDD