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 Slide

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

    View 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 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 Slide

  5. Disclaimer

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

  11. Round 1… code!!

    View Slide

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

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

  14. The transformations

    View Slide

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

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

    View Slide

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

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

    View Slide

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

    View Slide

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

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

    View Slide

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

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

  24. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

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

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

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

    View Slide

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

  36. Round 2… code!!

    View Slide

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

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

  39. https://goo.gl/AitF9H

    View Slide

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

    View Slide

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

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

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

    View Slide

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

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

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

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

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

    View Slide

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

    View Slide

  50. View Slide