KEMBAR78
are Code Katas always Agile ? | PDF
it.ciroppina
Are Code Katas always Agile?
a brief analysis of a Kata solution(*) to the famous
TW’s Merchant’s Guide to the Galaxy problem
* find code here:
https://github.com/sudarshan89/merchant-galaxy
they believe code-katas design is always Agile,
here U are a Java-1.8 implementation of the
Roman-Numerals validation:
it.ciroppina
sorry, there(jump) is a lot of
magic names in the code
now here U are another (my) implementation of the
same validation, googleing a suitable regEx:
it.ciroppina
sorry, I dont know how to fill the slide
not wanting to mention the time it needs to code
the Kata solution, when compared with mine, here U
are the execution times (almost the same):
Kata Solution my Solution
it.ciroppina
validation functions are static in both codes
the «Merchant’s Guide» problems is a money
conversion one, where RareMetals (decimal) credits
are to be calculated from galactic (roman) strange
currencies’ expressions such as:
- glob (roman I)
- prok (roman V)
- pish (roman X)
- tegj (roman L)
the problem questions «how much»(s) and «how
many»(s) the solution must answer, producing a
well-defined and ordered console output
it.ciroppina
how to parse galactic (roman) strange currencies’
expressions (given as input to the solution)?
the code kata-er identified three kinds of expressions, in the input
lines (a plain-text lines’ file):
1) Galactic Currency Expression Transactions: i.e. how much is pish tegj glob glob ?
2) Per unit RareMetal value transactions: i.e. glob glob Silver is 34 Credits
3) Total credit evaluation transactions: i.e. how many Credits is glob prok Silver ?
1) and 3) are acknowledgeable by char ‘?’ and string «how»
2) is acknowledgeable by the absence of string «how»
Actually, the full input is composed of:
- 4 initialization sentences, followed by
- 3 RareMetal configuration sentences, followed by
- 5 questions to be answered (the last of them being unanswerable)
it.ciroppina
they believe code-katas design is always Agile,
here U are a Java-1.8 implementation of the
galactic expressions’ parsing problem – page 1
it.ciroppina
overall McCabe metrics here is: 6
max method metric is: 3
they believe code-katas design is always Agile,
here U are a Java-1.8 implementation of the
galactic expressions’ parsing problem – page 2
it.ciroppina
overall McCabe metrics here is: 10
max method metric is: 3
they believe code-katas design is always Agile,
here U are a Java-1.8 implementation of the
galactic expressions’ parsing problem – page 3
it.ciroppina
no enough room on this slide to
show all the code
they believe code-katas design is always Agile,
here U are a Java-1.8 implementation of the
galactic expressions’ parsing problem – page 4
it.ciroppina
nonetheless Kata’s methods are short (vertically);
only they suffer a little bit excessive horizontal
lenght: U can count till 8 inline methods’
invocations !
now here U are another (my) implementation of the
galactic expressions’ parsing problem – page 1
First of all:
- Configure NUMERALS
(Roman symbols)
- Configure UNITS
(Rare Metal units)
and compute their
unitary value
it.ciroppina
now here U are another (my) implementation of the
galactic expressions’ parsing problem – page 2
by the Help of a
simple Enum of
Symbols
it.ciroppina
now here U are another (my) implementation of the
galactic expressions’ parsing problem – page 3
and, in the end,
provide a method
that «decimalize»
the strange
galactic
expressions
it.ciroppina
both solutions, Kata-er’s and mine, provide tests
and main classes for execution
Kata App body My App body
it.ciroppina
difficult to read config, compute, answer
what about the Code Kata design ?
according to the Kata-er:
Some of the key concepts fundamental to my approach are:
- Use OO principles to drive the solution
- Use language used in the problem statement to drive class name's in the solution
- Divide the input into transaction types
a) Galactic Currency Expression Transaction :- how much is pish tegj glob glob ?
b) Per unit Rare metal value transaction :- glob glob Silver is 34 Credits
c) Total credit evaluation transaction :- how many Credits is glob prok Silver ?
- Once the Galactic Currency Expression Transaction can be evaluated then it can be re-used to evaluate Per unit
Rare metal value transaction and after you have a) and b) then they can be used to evaluate c)
but those do not look like design issues
it.ciroppina
what about the other (my) design ?
statically I read a regEx useful to validate
galactic-roman expression’s correctness. A proper
reader does the job for me:
public static String ROMANS_REGEX = null;
static {
ROMANS_REGEX = InputReader.loadThis("roman.regex");
}
…then, statically I ask an InputProcessor to load
the input lines for me:
public TheApp() {
InputProcessor.config();
}
now all-the-things ‘re ready to work……………………>
it.ciroppina
what about the other (my) design ?
finally all the input lines with a question-mark
are answered, one after the other, in the given
input order:
for (String q : lines) {
if (q.indexOf('?') > -1) {
System.out.println(answerThis(q) ); //console print
}
}
answerThis(q) template method:
- parses q
- compute credits
- prints the proper answer to
the console
it.ciroppina
what about the DESIGN ?
- nor Kata Code neither mine did use of
factory/builder/composition/chain-of-resp
- both solution are mainly based over string’s
parse
- my solution separates resources Loader/Processor
from the functional code
- both solutions make use of Maps/Lists (J1.8
immutables) or Enumeration of symbols
- both solutions separatedly tests the «parts» of
the code
it.ciroppina
METRICS
Kata Code: my Code:
it.ciroppina
it.ciroppina
So, why TW people fired me before hiring
after having evaluted my code for the famous
Merchant’s Guide to the Galaxy
problem ?
nonetheless,
I stay:

are Code Katas always Agile ?

  • 1.
    it.ciroppina Are Code Katasalways Agile? a brief analysis of a Kata solution(*) to the famous TW’s Merchant’s Guide to the Galaxy problem * find code here: https://github.com/sudarshan89/merchant-galaxy
  • 2.
    they believe code-katasdesign is always Agile, here U are a Java-1.8 implementation of the Roman-Numerals validation: it.ciroppina sorry, there(jump) is a lot of magic names in the code
  • 3.
    now here Uare another (my) implementation of the same validation, googleing a suitable regEx: it.ciroppina sorry, I dont know how to fill the slide
  • 4.
    not wanting tomention the time it needs to code the Kata solution, when compared with mine, here U are the execution times (almost the same): Kata Solution my Solution it.ciroppina validation functions are static in both codes
  • 5.
    the «Merchant’s Guide»problems is a money conversion one, where RareMetals (decimal) credits are to be calculated from galactic (roman) strange currencies’ expressions such as: - glob (roman I) - prok (roman V) - pish (roman X) - tegj (roman L) the problem questions «how much»(s) and «how many»(s) the solution must answer, producing a well-defined and ordered console output it.ciroppina
  • 6.
    how to parsegalactic (roman) strange currencies’ expressions (given as input to the solution)? the code kata-er identified three kinds of expressions, in the input lines (a plain-text lines’ file): 1) Galactic Currency Expression Transactions: i.e. how much is pish tegj glob glob ? 2) Per unit RareMetal value transactions: i.e. glob glob Silver is 34 Credits 3) Total credit evaluation transactions: i.e. how many Credits is glob prok Silver ? 1) and 3) are acknowledgeable by char ‘?’ and string «how» 2) is acknowledgeable by the absence of string «how» Actually, the full input is composed of: - 4 initialization sentences, followed by - 3 RareMetal configuration sentences, followed by - 5 questions to be answered (the last of them being unanswerable) it.ciroppina
  • 7.
    they believe code-katasdesign is always Agile, here U are a Java-1.8 implementation of the galactic expressions’ parsing problem – page 1 it.ciroppina overall McCabe metrics here is: 6 max method metric is: 3
  • 8.
    they believe code-katasdesign is always Agile, here U are a Java-1.8 implementation of the galactic expressions’ parsing problem – page 2 it.ciroppina overall McCabe metrics here is: 10 max method metric is: 3
  • 9.
    they believe code-katasdesign is always Agile, here U are a Java-1.8 implementation of the galactic expressions’ parsing problem – page 3 it.ciroppina no enough room on this slide to show all the code
  • 10.
    they believe code-katasdesign is always Agile, here U are a Java-1.8 implementation of the galactic expressions’ parsing problem – page 4 it.ciroppina nonetheless Kata’s methods are short (vertically); only they suffer a little bit excessive horizontal lenght: U can count till 8 inline methods’ invocations !
  • 11.
    now here Uare another (my) implementation of the galactic expressions’ parsing problem – page 1 First of all: - Configure NUMERALS (Roman symbols) - Configure UNITS (Rare Metal units) and compute their unitary value it.ciroppina
  • 12.
    now here Uare another (my) implementation of the galactic expressions’ parsing problem – page 2 by the Help of a simple Enum of Symbols it.ciroppina
  • 13.
    now here Uare another (my) implementation of the galactic expressions’ parsing problem – page 3 and, in the end, provide a method that «decimalize» the strange galactic expressions it.ciroppina
  • 14.
    both solutions, Kata-er’sand mine, provide tests and main classes for execution Kata App body My App body it.ciroppina difficult to read config, compute, answer
  • 15.
    what about theCode Kata design ? according to the Kata-er: Some of the key concepts fundamental to my approach are: - Use OO principles to drive the solution - Use language used in the problem statement to drive class name's in the solution - Divide the input into transaction types a) Galactic Currency Expression Transaction :- how much is pish tegj glob glob ? b) Per unit Rare metal value transaction :- glob glob Silver is 34 Credits c) Total credit evaluation transaction :- how many Credits is glob prok Silver ? - Once the Galactic Currency Expression Transaction can be evaluated then it can be re-used to evaluate Per unit Rare metal value transaction and after you have a) and b) then they can be used to evaluate c) but those do not look like design issues it.ciroppina
  • 16.
    what about theother (my) design ? statically I read a regEx useful to validate galactic-roman expression’s correctness. A proper reader does the job for me: public static String ROMANS_REGEX = null; static { ROMANS_REGEX = InputReader.loadThis("roman.regex"); } …then, statically I ask an InputProcessor to load the input lines for me: public TheApp() { InputProcessor.config(); } now all-the-things ‘re ready to work……………………> it.ciroppina
  • 17.
    what about theother (my) design ? finally all the input lines with a question-mark are answered, one after the other, in the given input order: for (String q : lines) { if (q.indexOf('?') > -1) { System.out.println(answerThis(q) ); //console print } } answerThis(q) template method: - parses q - compute credits - prints the proper answer to the console it.ciroppina
  • 18.
    what about theDESIGN ? - nor Kata Code neither mine did use of factory/builder/composition/chain-of-resp - both solution are mainly based over string’s parse - my solution separates resources Loader/Processor from the functional code - both solutions make use of Maps/Lists (J1.8 immutables) or Enumeration of symbols - both solutions separatedly tests the «parts» of the code it.ciroppina
  • 19.
    METRICS Kata Code: myCode: it.ciroppina
  • 20.
    it.ciroppina So, why TWpeople fired me before hiring after having evaluted my code for the famous Merchant’s Guide to the Galaxy problem ? nonetheless, I stay: