Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kata de números romanos y TPP

Kata de números romanos y TPP

Slides usadas para un coding dojo en la Coruña. En concreto se trata de la kata Roman Numerals aplicando la Transformation Priority Premise (TPP).

Isidro López

May 03, 2018
Tweet

More Decks by Isidro López

Other Decks in Programming

Transcript

  1. 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)

    View full-size slide

  2. Ego slide
    Desarrollador de software (de sabático)
    @islomar
    [email protected]
    Desarrollador de software (Charplanet)
    @borjal
    https://borjafernandezpillado.com

    View full-size slide

  3. ¿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

    View full-size slide

  4. ¿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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. 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

    View full-size slide

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

    View full-size slide

  9. 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

    View full-size slide

  10. Round 1… code!!

    View full-size slide

  11. 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.

    View full-size slide

  12. 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

    View full-size slide

  13. The transformations

    View full-size slide

  14. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. 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!

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  34. Round 2… code!!

    View full-size slide

  35. 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?

    View full-size slide

  36. 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.

    View full-size slide

  37. https://goo.gl/AitF9H

    View full-size slide

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

    View full-size slide

  39. 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

    View full-size slide

  40. 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)

    View full-size slide

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

    View full-size slide

  42. 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

    View full-size slide

  43. 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

    View full-size slide

  44. 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

    View full-size slide

  45. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide