Slide 1

Slide 1 text

Coding dojo: Kata de números romanos y TPP A Coruña, 3 de abril de 2018 Borja Fdez Pillado (@BorjaL) Isidro López (@islomar)

Slide 2

Slide 2 text

Ego slide Desarrollador de software (de sabático) @islomar islomar@gmail.com Desarrollador de software (Charplanet) @borjal https://borjafernandezpillado.com

Slide 3

Slide 3 text

¿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

Slide 4

Slide 4 text

¿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

Slide 5

Slide 5 text

Disclaimer

Slide 6

Slide 6 text

http://luizricardo.org/wordpress/wp-content/upload-files/2014/05/tdd_flow.gif

Slide 7

Slide 7 text

La regla dorada de TDD Nunca escribas nueva funcionalidad sin un test que falle

Slide 8

Slide 8 text

Recordemos: ¿qué aporta (y qué no) TDD? ¿Qué puede aportar? ● Foco ● Feedback rápido ● Simplicidad ● Cadencia ● Documentación ¿Qué no aporta necesariamente? ● Un buen diseño ● “Buenos” tests ● Buena documentación

Slide 9

Slide 9 text

Hands-on time!! Pair programming Pomodoros: ~25 min. Kata Roman Numerals http://cdn2.hubspot.net/hub/213381/file-367603473-jpg/images/kata.jpg

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Round 1… code!!

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

The transformations

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Example - Word Wrap Kata ({}–>nil) - Red @Test public void WrapNullReturnsEmptyString() throws Exception { assertThat(wrap(null, 10), is("")); }

Slide 17

Slide 17 text

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 ""; }

Slide 18

Slide 18 text

Example - Word Wrap Kata (nil–>constant) - Green @Test public void WrapEmptyStringReturnsEmptyString() throws Exception { assertThat(wrap("", 10), is("")); }

Slide 19

Slide 19 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("word", 5), is("word")); }

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void TwoWordsLongerThanLimitShouldWrap() throws Exception { assertThat(wrap("word word", 6), is("word\nword")); }

Slide 22

Slide 22 text

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"); }

Slide 23

Slide 23 text

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!

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("word", 5), is("word")); }

Slide 26

Slide 26 text

Example - Word Wrap Kata (constant->constant+) - Green public static String wrap(String s, int length) { if (s == null) return ""; return "word"; }

Slide 27

Slide 27 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void OneShortWordDoesNotWrap() throws Exception { assertThat(wrap("otherword", 10), is("otherword")); }

Slide 28

Slide 28 text

Example - Word Wrap Kata (constant->scalar) - Green public static String wrap(String s, int length) { if (s == null) return ""; return s; }

Slide 29

Slide 29 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void TwoWordsLongerThanLimitShouldWrap() throws Exception { assertThat(wrap("word word", 6), is("word\nword")); }

Slide 30

Slide 30 text

Example - Word Wrap Kata (constant->constant+) - Red @Test public void WordLongerThanLengthBreaksAtLength() throws Exception { assertThat(wrap("longword", 4), is("long\nword")); }

Slide 31

Slide 31 text

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"; } }

Slide 32

Slide 32 text

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")); }

Slide 33

Slide 33 text

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); } }

Slide 34

Slide 34 text

Example - Word Wrap Kata (constant>constant+) - Red @Test public void WordLongerThanTwiceLengthShouldBreakTwice() throws Exception { assertThat(wrap("verylongword", 4), is("very\nlong\nword")); }

Slide 35

Slide 35 text

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); } }

Slide 36

Slide 36 text

Round 2… code!!

Slide 37

Slide 37 text

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?

Slide 38

Slide 38 text

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.

Slide 39

Slide 39 text

https://goo.gl/AitF9H

Slide 40

Slide 40 text

Posibles “soluciones” http://codingdojo.org/record/GothPy081007/ http://www.solveet.com/exercises/Kata-Roman-Numerals/9

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Bibliografía ● TDD by example (Kent Beck) ● Growing Object-Oriented guided by tests (Steve Freeman, Nat Pryce) ● Diseño ágil con TDD (Carlos Blé) ● Specification by example (Gojko Adzic) ● Refactoring (Martin Fowler) ● Clean Code (Uncle Bob) ● XP Explained (Kent Beck)

Slide 43

Slide 43 text

Blogs http://blog.adrianbolboaca.ro/ http://blog.jbrains.ca/ https://codurance.com/publications/ https://www.codesai.com/publications/

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

Artículos y webs de interés ● https://martinfowler.com/bliki/IntegrationTest.html ● https://martinfowler.com/articles/microservice-testing/ ● http://www.agiledata.org/essays/tdd.html ● https://medium.com/@ramtop/what-im-talking-about-when-i-talk-about-t dd-546a383468be ● https://martinfowler.com/articles/practical-test-pyramid.html ● Ideas para katas: https://github.com/12meses12katas

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

http://3.bp.blogspot.com/-N6byEO21I0w/VoTzspUt8xI/AAAAAAAAC7M/oDukuU0kVdU/s1600/THANK-YOU-FOR-YOUR-TIME-1.png Graciñas!!

Slide 49

Slide 49 text

¡¡Gracias por el feedback!! https://islomar.typeform.com/to/HchXmN

Slide 50

Slide 50 text

No content