Code Katas (Video library) What is the meaning and usefulness of the Code Katas? We could not see through a particular example? Yes, "String Kata Calculator." In particular, it will see a whole collection of performances of great technical merit and "artistic." A true performance and a great show!
I could not resist the urge to collect this precious material and to present the work done by so many friends in Milan and the XPUG SIAgile, from which I am learning to work really well, who spend their time with passion and professionalism to discipline of software development following the methodology of Extreme Programming Kent Beck & Co. This is a tasty, convenient and practical opportunity to see what is the TDD or Test Driven Development and to understand what it means incremental development or design emerging. The issue certainly is not exhausted in this post, there will be others, but surely tickle some readers to deepen the arguments and Agile Development.
Abstract Software development is a discipline. Its purpose is to satisfy customer needs, provide automatic solutions to problems articulated more or less applicants, responding to spoken and unspoken requirements of people who interact and communicate in work activities and games. Should help to improve people's lives, right?
Quindi non si tratta di un arte marziale, non si tratta neanche di un'arte, a mio parere. Come dice bene
Zio Bob scrivere software è un
artigianato . Sebbene qualche cosa di marziale credo ci sia. Sviluppare software infatti vuol dire spesso combattere contro la complessità, vuol dire ridurre rischi di incidenti i cui danni potrebbero essere incalcolabili, vuol dire spesso lottare contro i mulini a vento, è senz'altro una lotta contro il tempo e contro le avversità della realtà, una realtà che si cerca di astrarre, semplificare, dominare. Per dirla alla Karpov "lo sviluppo del software è uno dei giochi più crudeli al mondo". E a peggiorare le cose, si aggiunge il fatto che si tratta di un'attività virtually invisible to most.
Like any self-respecting discipline and command that we love - we think of music, sports, dance, yoga, politics and entertainment - including the development of software to be exercised. The exercise is even more important as unless we want to find excuses for not having the time necessary to produce high quality software, as rightly pointed out
Gabriele Lana in his article . Now we have the tools we need to proceed in this vital exercise.
Definition Here, as in the martial arts were born Kata computer (Code Katas
) from vocation
Dave Thomas (co-author of the book The Pragmatic Programmer
).
Kata is a Japanese term that indicates a predetermined sequence of choreographed movements practiced alone or in pairs, which represents a hypothetical combat with one or more imaginary opponents. The aim is to familiarize yourself, increase agility, buy the same spontaneity of movement through repetition and practice. In computing the
Code Katas consist of a set of requirements presented in a certain order to simulate the wishes of a hypothetical customer. Implementing them in a form also quite spectacular, with a choreography or musical ev. accompanied by a voice narrating and describing the path must be done in less than 30 minutes, say in a Tomato
Francesco Cirillo.
String calculator Kata Kata The Code of which we speak today is that developed by Roy Osherove
called
String Calculator . This is the following sequence of requirements:
- Create a simple calculator strings / text by a method int Add (string numbers)
- The method can take the numbers 0, 1 or 2, and returns their sum (the empty string returns 0), for example "" Or "1" or "1.2"
- Start with the simple case of testing for an empty string, then try with the number 1, and then with 2.
- Remember to resolve things as simple as possible, so you force yourself to write tests that I had not thought
- Remember to refactor (see Refactoring) to each test to become "green" (ie it works correctly)
- Allow the Add method to handle an unknown number of numbers
- allows the Add method to manage the "head" (new lines) between the given numbers (instead of the comma).
- the following testo è ok: “1\n2,3” (sarà uguale a 6)
- il seguente testo NON è ok: “1,\n”
- assicurati di testare solo gli input validi. Non è necessario prevedere input non validi per questo kata.
- Permetti al metodo Add di gestire differenti delimitatori:
- per cambiare un delimitatore, all'inizio del testo figura una linea separata come la seguente: “//[delimiter]\n[numbers…]” per esempio “//;\n1;2” deve restituire 3, dove il delimitatore di default è ‘;’.
- la prima linea è opzionale. Tutti gli scenari precedenti devono continuare a funzionare.
- Chiamando Add con un numero negativo, verrà lanciata un'eccezione “negatives not allowed” - e il numero negativo che è stato passato. Se ci sono più di un numero negativo, allora mostrali tutti nel messaggio dell'eccezione prodotta)
- [...]
(la versione completa del kata prevede 11 punti da realizzare in meno di 30 minuti!)
Ho voluto riportare il testo tradotto in italiano per favorire la didattica di questo Kata e consentire a tutti di leggerlo.
Executions Esso è stato svolto da diverse persone e in diversi linguaggi di programmazione, le quali poi hanno avuto la buona idea di registrarne in video tutta la loro esecuzione. Qualcuno ha messo come sottofondo persino delle musiche che rendono il tutto veramente gradevole. Un vero spettacolo!
Le cose interessanti di queste esecuzioni sono tante, e in particolare vorrei evidenziare le seguenti:
- il tempo di esecuzione della maggioranza dei Kata è stato inferiore ai 15 minuti! Questo vuol dire, per esempio, che possiamo ripetere il Kata ogni mattina prima di metterci al lavoro, un po' come una forma di riscaldamento "muscolare", cercando ogni volta di ottimizzare maggiormente i tempi di sviluppo e affinare le tecniche adottate.
- avete notato come, senza nessuna fretta di realizzare la funzionalità completa già al primo colpo, gli autori abbiano proceduto a piccoli passi, attendendo che l'esigenza di un certo design o implementazione emergesse dai requisiti e non perché era ovvio a priori? Adoro questi micro-passaggi.
- l'importanza rivestita dalla leggibilità del test è imperativa, difatti esso viene rifattorizzato at least once by almost all authors. The test is the requirement, which must be simple, complete and clear documentation, rather it is a documentation, it is dynamic and executable documentation. Formidable!
- is viewed as an ideal benchmark to evaluate and compare different languages \u200b\u200bused
- perform a Kata is an ideal approach for learning a new language
- some authors have used the tools of BDD (Behavior Driven Development ) to write the test. You also can not find an approach very elegant and simple at the same time?
- have seen how powerful working with meta-programming in some languages \u200b\u200bsuch as Ruby and C #, for example, it allows us to extend the String class with new and convenient methods in the test? Think instead of how much code is too often written in Java! (Even if the library lambdaj of home helps a lot)
thanks goes to the authors of these kata, because they allow us to learn new techniques and languages \u200b\u200bwith ease. You might ask why not also included my name in the list . Never fear, I also have done this several times Kata, touching the time of tomato and just get to a decent level and personal satisfaction, I will provide a link to my performance on a screencast in the comments on this post. For the moment my job is to give light to these people in the leg.
Conclusions
There are no more excuses: write good code and quickly as possible. We must practice course. If you are an employer, you should expect from your team this type of daily exercise. The same
Osherove suggested to perform the kata several times a day to reach its performance in less than 30 minutes (Kata) complete. The results do not allow themselves to wait, you see immediately. The quality of the software product that will in time create a climate virtuous merit and relaxed, allowing the organization to raise its trade and economic ambitions without having to increase the cost of development, indeed.