Get Kata - Kevlin Henney

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] okay you're all technology you know what this is yeah it's an Internet device it has a secondary use of the telephone actually it might be a tertiary use these days apparently it makes noises when you do that it's got these have vibrate features it's a really novel feature that we have in the 21st century so if you really are expecting that call then that's how you doing okay that's that's that the technology built at all done so what am I going to talk about what am I going to talk about so that's Michael Caine 1971 what's that got to do it anything get Carter this is the film that he was in a kind of London gangster movie there was apparently a remake of Get Carter with Sylvester Stallone done in 2000 we do not speak of this okay the little bit like Sylvester Stallone and Judge Dredd in 95 we do not speak of that version it does not exist Dredd with Karl Urban is the only true canonical version so good um so yeah so so this is what I'm talking about I'm afraid you don't get me with a shotgun you get me with this but it's not quite a school but Get Carter and which came first the film title did the title of the talk or the content of the talk well obviously the title of the talk came first i sat there one day thinking of British movies and I thought you know what there's something funny that could be done here I wonder if there was a talk we now have an answer yes there is okay what am I going to talk about I'm going to talk about it cancer okay now it turns out this is a word that has got absorbed into the software craftsmanship community I think it was originally introduced by pragmatic Dave pragmatic programmers in trying to get this focus get us to think about what it is that we are doing and practice because one of the things that we lack in software development is a sort of form of deliberate practice and focus it's not that we don't get much practice but there is the old joke you know oh yeah I've been in this industry 10 years oh or is that one year 10 times ok we go round in circles that's a different form of iteration ok it's not very helpful but we also do not get the opportunity to explore and learn with most things particularly in a sort of an educational environment in the practice environment you get to repeat things you get to try things again to get to affect them if you play a musical instrument or you want to take a sport you know that you do the same thing again to perfect it to try it the idea of a carto is the repetition in software development software development is filled with things I kind of like other things but they're not identical once you've mastered them or you think you're just about to master them you move on to the next piece of software in other words you try to think I think I've got it oh ok we've shipped it and now I've got to move on to something else the idea of the Carter is actually to slow you down to make you focus on what you're doing and to choose something very small now the term comes terms Japanese and it has a couple of ways of being transcribed you know so I clearly did my did my homework and we've got to kind of form then you've got it has to kanji forms that one and that one I do not know enough Japanese as in this much Jeff actually I probably know more Japanese when I do Hebrew to be fair but there are two forms I'm not entirely sure what the preferred one is but in terms of pronunciation there are lots of different pronunciations people try to use katha actually it does come out of Carter Carter is closer to it's a supposedly true pronunciation but there are various translations form is one of them structure that the form of what you're doing structure in space and structure in time it is applied in martial arts as a practice form so it covers both of these concepts which is very dear to my heart I've cast a couple of books on patterns I find the pattern way of thinking is a very profound way of approaching problems and solving them reasoning through forces thinking about context I'm fortunate that's not the bit that people normally associate with patterns because it's hard and like most things that are hard people ignore the hard bit and go for the easy bit and style there is this idea that a collection of patterns gives you a style patterns originated a building architecture we use term architectural style and pattern almost interchangeably and there's an idea there if you do something in a particular way you create a particular results you cannot separate the way that you do something from the thing that comes out at the other end and then training exercise which is the most common idea from martial art into the software craftsmanship community it is normally associated with really getting into test-first programming but I'm not really going to talk exactly about that what I want to talk about is a very sort of simple idea first of all the deliberate practice approach but then I want to go beyond the deliberate practice approach so this is a book I did a few years ago 97 things every program should know and my friend John Jagger had the century do lots of deliberate practice and this is the focus deliberate practice this is what we're after you do deliberate practice to improve your ability to perform a task it's about skill and technique it means repetition it is not about completing the task it is about mastering the task which is different your daily work is about completion the goal here is master is fundamentally different you have to slow down and stop but I'm also interested in something else I'm interested in the idea that a Carter is almost a small laboratory it is the laboratory which one you understand it well what are you doing laboratories you experiment you try things out Emile Auguste RT a lovely quote probably one of my favorite all-purpose quotes nothing is more dangerous than an idea when you have only one idea okay you feel free to use this throughout your whole life okay you know you can leave now if this is the most important thing you're going to learn this evening okay but there is this we normally as developers have a very bad habit of doing a first fit in other words yep I've got it okay let's do it that way it's just like well okay that's the first idea you have what about the second idea no no this is fine I had you know it turns out one of the things that humans are reasonably good at although apparently in the UK and in the US we seem to be struggling with this idea of comparing things normally we're quite good when given two choices most humans with the exemption of yeah the UK in the US and when given two options we're not be quite good at comparing them how do you know that's a good idea give me a second idea what's your third idea yeah the first idea is also something that may have just come out it's just like yeah it's clearing your brain ok the second idea might be better it might be worse but you won't know until you get to compare them experiment how do you experiment well I'm going to take off I'm going to take our large product and start experimenting on that Oh easy there maybe you don't want to do the big experiment I may just try small things a Carter is an opportunity to experiment and the smallest elements of style and this is really important I think people often overlook this idea often people talk about software they look at coding practice well that's just a small detail and I and I always come back to them and say well what do you think software is that's the whole point of software software is all about the details all the rest is the stuff that happens in meetings it's the hand waving and then you have detail and a working software system is lots of details put together so they work that is the whole point of software ok everything else is just conversation so there's this idea there is no such thing as a detail that is too small and particularly one of the things you may observe is that as a software system grows as parts of it grow we experience what is known as an inflation face and I was those small little ripples in that tiny tiny method that you once wrote but you didn't pay much attention to when it got maintained and grown and extended and grown those little ripples suddenly became the galaxies of your system okay you can normally track back the warts the weird with the technical debt locales - something that somebody did and then somebody else followed through and they followed through they normally grew out of a small detail so details matter and we often find that the large scale architectures reflect ideas and the small so I want to just start off from somewhere completely different and demonstrate the value of different ideas and lateral thinking so this is a right angle triangle Wow okay what do want to take a guess at what dimensions I might have chosen all right three four five yeah so so three four five which you know we're going to be mathematical we don't use numbers in math that's the arithmetic real mathematicians don't use numbers okay so as they do pants there you go so we've got this whole idea Pythagoras brilliant and if you want to do visually you have this now there is a thought here I'd already learnt this at one point or another and you may also have learned to proof I learn to proof at school I think the first proof I was shown was approved by similar triangles mmm I know he did a different one he did do one he did the dissection one the similar angles huh there's the one-line together there's the shortest Institute that's a different one yeah there are about 400 it turns out this is what I discovered when I started digging into this topic yeah Einstein does a very different a slightly different approach but it wasn't the it wasn't it wasn't that one that I was taught at school but there is an interesting question here what the hell did Pythagoras do I mean you know quite a very obvious thing Pythagoras is not going to use the Roman alphabet but first observation when did this notation come about you know the equal sign is actually quite young it's a couple of centuries old the squaring is really young so how did it this whole algebra concept that's really yeah what did he do he clearly didn't do it like this so this is a sort of my basic this is the kind of the basic kind of approach you did a proof by rearrangement because that you can do standing there with your stick in the sand or tiles you can do the proof by rearrangement move it around and then logically you can say and you can call them whatever you like so this is the original proof was approved by rearrangement we move things around there are actually quite a few proofs by rearrangement it turns out so yeah that'll work my favorite one is probably my favorite algebraic one all most memorable one there's a number of variations is this and the observation that if those are C then and those aren't that a that's B therefore this must be like that you get C squared plus B squared therefore this is a plus B plus brilliant and so we get this and you cancel things out and magic happens marvelous that's the second way it's completely different but my recent favorite I discovered this December last year is this one the trapezoid one this one was proven by President Garfield of the United States the 23rd president I think he was at the u.s. I just want you to compare that with number 45 the current incumbent President Garfield well actually before he became president he was not wasn't president very long it was a bank when you know Sassa nations were popular but in the 1870s when he was a senator I believe he came up with an original proof yeah standards are fallen okay but yeah a very very simple idea it's just like what was that those are see on each side then innocence not okay this is really very elegant it all works out beautifully and you've got this you have to know a little bit about areas but that's fine and the right things happen the house disappear and you got it so three approaches and as I said it was almost a rite of passage everybody's got to have their own okay so yeah Einstein did one everybody did one except you know every president after Garfield but as I said there seem to be nearly 400 there might be more but apparently there was a book published in the 1960s that had about 350 so I'm presuming somebody's come up with a few since then have you heard different ways of looking at the same thing now what is interesting about them is that they have different appeals to different people approved by rearrangement is something that you can demonstrate just on a table well it's quite elegant in that point of view the previous algebraic proof I managed to show to my youngest son when he was 10 and he got it and it's just a case of like what is it that appeals everybody finds a different simplicity and a different way of looking at something so what we going to do we got to look at a real enterprise problem here fizzbuzz okay and you know this is the heart of every major system of course so as a number of you have beer in your hands just just check who is familiar with fizzbuzz okay let's try that one again who's not familiar with fizzbuzz okay good there are a few people okay fizzbuzz is a counting game okay and it's relatively simple you go group of friends group of enemies it doesn't really matter actually might be a good way to at all international conflicts one two fears every number divisible by three is replaced by fears for buzz every number divisible by five is replaced by buzz fears 7 8 9 I got it wrong take a drink okay if you do not have a drink it is really not very exciting I have okay yeah bye my wife and my sons we were on holiday last year and we were waiting for food in a restaurant they had not yet service the wine both my boys they are mathematically you know good both the adults were sober and we've played this game waiting for the food it is really boring everybody gets everything right okay because the only quirk is that every number divisible by three and five fifteen is replaced by fizzbuzz 1314 v 1617 fears 19 buzz okay somewhere along the line somebody decided this to be a good interview question for programmers I'm actually is not a bad interview question you hope you're surprised how many people struggle with it and it's also become a kind of rite of passage in the software craftsmanship community can you write can you TDD this so what I do is we just sort of take on a relatively simple implementation one that is very much structured in terms of accumulator the idea of accumulating it's a fairly sequential approach but people normally eventually come across this and they are they are sort of happy and happy at the basic elegance that since business is an emergent property you only have to care about spheres and buzz and the rest happens by magic but you are dealing with accumulated state okay so that works alternatively we have something that uses tail return everything has a mutually exclusive path everything is handled and you know if your friends kind of saying hey you should do more functional whether this is more functional there's no kind of like state changes there's no variables so you can say oh this is functional your friend comes along ago that's not functional come on man you know come on that's functional ok it's going to be an expression you're using statements you know what yeah yeah you're right you're right I think I can see that but then start thinking differently okay because is it an arithmetic problem is an arithmetic problem are we dividing things by three are we asking the question is it divisible by three is it divisible by can we invert that and say actually I've got a set of numbers by the way just in case you're wondering about the upper limit the problem is normally specified over the domain of 1 to 100 because people have either four people either way too drunk by that point or just bored out of their tiny minds but you know from a programmers point of view that that's normally the way it's specified so you've got this so what we're going to do here is going to turn it around we're going to invert it we're going to say look I'm going to have the set of numbers that are the 15s so 15 30 45 if this number is in that set then how it's fizzbuzz if it's in the set of 3s so I'm going to turn the problem round instead of thinking of it as a problem of I'm applying an operation a divisibility operation something I'm going to turn it around into set membership okay and so this changes the shape of the problem ever so slightly it is another one so what I'm going to do here is I'm going to say why don't we construct this and recover our emergent property which is quite nice before do something slightly different the the stopper at the beginning and the end are just two aligned numbers and zero based counting all account from one but the other way of looking at it is to ask a very simple question show me all the visits okay between here 100 where does the fizz's occur while the fizzes are every three so that's blank blank fields blank blank blank blank foods please generate that for me so that's another way of doing it so I'm going to do that and I'm going to index that the buzz is for blanks and a buzz repeat as necessary okay now what I'm going to do is what all the numbers between 1 and 100 but as strings okay so now I'm going to string a file or number so I go 1 2 3 so now I've got all the resources I'll ever need okay I've got numbers and I've got words and then compose them together I take the fist I take the buzz I can catenate them if there's something there we either have fizzbuzz or fizzbuzz if there isn't I go love Python to this Python has a very kind of loose relationship with the whole idea of boolean myths I ain't quite good it's it well no sorry it's either really good or you really hate it okay there is it's a something that lives at one or two extremes so it's a case of like well if there was something there then we're good with it otherwise get one of those numbers and we're good okay so that's a different way of looking at it and then your friend comes along and says no no no notes I've gotta be able Outlanders carefully you've got to have lambdas and Python is one of those languages that couldn't come up with a short notation for lambdas they really struggle with the spelling of it so they spelled it lambda every other language that uses lambdas with possible accession of list actually does not spell it out lambda they come up with some kind of crazy notation okay and it's like a competition between languages what are you going to do well I'm giving is a lethal sign they're followed by an arrow okay okay well I'm going to use square brackets and an emoji oh cool you know so there's a like a competition fight it was terribly dull so yeah it's called lambda okay right so we're going to have Landers for Fears buzz numbered this is probably enough to get you excommunicated from the Python community because it's not very pythonic but we're also going to mess about you know explore the languages a bit kick the tires of it okay Python is a language so as I said it has a very loose relationship with the concept of boolean this it also has some very interesting relationships with numbers so n n mod 3 equals 0 well that's going to be either true or false ok so false times a string is empty string true times a string is the identity operation is the string brilliant so we can actually do boolean multiplication of strings excellent yeah so so we've got that that's fantastic so now we've got all of this stuff and then we just combine it and this is pure addition ok it's just like yeah this is really nice a really nice do you really hate it there's this one which combines it all into one although it turns out when we realize we can do that I like this one because you can put it in a tweet with a comment okay just sort of say you know yes so this is here it's great so um we can really mess them out with this but the question comes yeah Kevin stuff - these are all small examples I work in an enterprise environment okay there is of course first Bible Enterprise Edition if you have not come across this go and spend some time looking at this and then run away very very fast now I'm clear I'm of a particular generation and inclination that I still cannot do this I still you know it doesn't matter that the whole Java Enterprise thing kicked off 20 years ago the word Enterprise I only think of one thing you know I still you know two decades on you say enterprise and book Captain Kirk pops into my head I'm thinking NCC 1701 or am I thinking NCC 1701 a maybe B maybe C maybe D maybe the reboot I really love this it's beautiful it's gorgeous it's a lot better than most enterprise software I have ever seen okay but there is something here that is true and deep and profound and physically possible that gives us a road into understanding this it turns out the NASA have actually been looking into warp drive although don't you know don't pack your bags for the Mitford for Proxima Centauri just yet there is actually a research group that looks into this and naturally enough they named their you know this is this is one of the artists mock-ups of what a craft would look like enterprise because it actually turns out that there is a possibility of warp drive okay Miguel Alcubierre Mexican physicist 1994 explored the equations of general relativity and came to the conclusion that it was actually possible to actually possible to warp space in a way that allowed you to travel faster okay so there is a basic Einstein got a mention earlier on probably not that well known for his Pythagorean proof he's probably a little better known for his theories of relativity and there is this solution that allows you to get around or seemingly get around this whole issue of the speed of light being a bit of a speed limit it's the speed of light in a vacuum or to be precise the speed of light in space-time okay now you can't go faster than that but here's the clever bit if you can make space-time move then you still respect the law in other words if I said well I'm still traveling less than speed of light in space-time but somebody else is moving space-time for me and it's faster notice it's a beautiful illusion we have warped reality now you understand the relationship to enterprise software okay it is a reality distortion field there are a couple of small issues with Miguel Alcubierre theory when it comes to what they call an implementation detail remember that there are no details the idea here is these are actually warp coils this is actually there is an idea that you hold this this will warp the space around the craft okay and what are these filled with they are filled with exotic matter we don't actually know that that stuff exists and if it does exist we don't know how to make it we're not entirely sure how much we would need one estimate says you might need to condense the mass of the moon into these warp coils these are small details okay you know if you're a manager yeah this is it's just a detail however it does return us to the reality or the distorted reality of enterprise software and I do strongly recommend as I say going having having a look at this thing Eddy provides software marks a special high-grade plaster software that makes careful use of relevant software architecture design principles to build particularly customizable and extensible solutions to real problems by the way just in case you know you've had a long day in your sense of humor is failing at this point this is a spoof site war rather it's intended as humor I did have to clarify that to one person perhaps they've just had a really hard time in the industry and that this actually looks quite plausible this book yeah Hyrum yes yes there you've got a job this project is an example of how the popular Finn's bias game might be built where it's subject to the high quality standards of enterprise software and you know you can just wander through the git repo and you know it's got all the really good stuff yeah people actually see that there are commits to this you've got a fifth string return a factory you got an integer integer printer return a factory you've got a no fizzbuzz no buzz strategy Factory and you know it's it so this is the as you can tell this is this is just the factory stuff okay there's a whole codebase out there possibilities yes where's the open poll request from two months ago um that's a very good question of this screengrab was a few months before that yeah it's really it's absolutely magnificent you don't want this in your codebase I pull land of some science fiction author I have yet to see any problem however complicated which when you looked at it in the right way did not become still more complicated this is a really useful thing I think secretly all programmers know this they just didn't know that they knew this this is kind of like there's a deep belief I see that problem that you've set me I can make it more complex yeah oh yeah it's a really easy requirement but if I added this it would make it interesting okay we're always playing so there's a certain playfulness but I do want to channel a playfulness into a different form of experimentation you can do this with different models so this is an orc solution okay quite like orchids the language that is much neglected these days partly it had a bit of a fight with Perl in the 1990s and lost as a friend of mine described Perl as being executable line noise but I've never I've never moved from that belief but orc has a very dedicated view is about pattern matching and it is structured around that in other words you don't have a loop to loop over your input there just is input you are part of a stream and this is invoked every single time you don't need to repeat the fact so there's a little more it's a little more of a the invocation environment it's got a slightly different execution model to what you might find in other imperative languages so what i'm doing here simply is just matching is it divisible by three by five by not by three and by five and then for all cases i will print that this matches the last one always matches and we print out a new line now how we test this how we drive it well to drive it it's fairly easy we use you know that old functional programming technique called the shell people often overlook the fact that a shell environment a pipeline environment is actually a data flow architecture which is a particular form of concatenative programming and this generates this quite nicely and if you want to test it we can just pump it into there now it turns out this problem is small enough that we don't necessarily need to define all the properties because we're only doing it up to a hundred you can generate all the values by going around the table sober so we can actually just cat the file and there it is yeah just difficulty if you have a small enough set this actually works out fine so why have I picked on orc well for a number of reasons one I think it's a much neglected language to it there's an unusual solution for this and three it's the oldest example of test first programming I've been able to find Alfred a ho in who is the a in orc a ho Weinberg a Korean when he Ames interviewed and he made an observation about how they developed this in the 1970s we instituted a rigorous regression test for all the features of hawk by the way the lead-up to the story is that it had a bug so there's a question like well what do we do now they decided that the only way to get the only way to get complete coverage and guarantee that you have the best coverage possible is to always have more coverage than code how is that possible well you write your tests first therefore by definition you're covering things that you do not yet have yeah so I know it's a kind of a it's a normal football manager thing to say you know our football is gave it 110 percent you know the guys gave it 110% that's the all pointers of TDD you give it 110 percent what you coverage 110 percent at the moment it's like okay if it fails doesn't it yeah because your that's that's a fancy way of saying it fails so next time next time you have a read you can now translate that into 110 percent you can give courage figures that are higher than reasonable okay you can exceed the limits like the speed of light and so on any of the three of us who put in a new feature into the language first had to write a test for the new feature this is test first programing 1970s style okay so it turns out the testers programming TDD but all this stuff has a long prehistory but it was just very scattered and then it kind of started coming together with XP and it became an entity in its own right but up until that it's not it was unknown it just was edge cases so here is how people morally present the test first cycle red green refactor and a lot of people when they arrive at this they're not entirely sure about it and so they kind of go well you know I don't really see the point because right a failing test well anybody can do that I mean you know where's the skill in that yeah I can write a failing test with my eyes closed so there's no skill in that so the problem is I find when people run this stuff they often end up spending a lot of time on green they're trying to get to green so no no no no you need to show what you're going to do the idea is to show what you're going to do red green refactor now when people start getting the rhythm red green red green they keep forgetting about this bit below the line so you end up with the dumbed down version I got a failing test I write just enough passed just enough code to make it pass then I write another test case then I write enough another piece of code to make it pass yeah yeah that yeah we missed out that bit and then we end up with some really crazy code and we say this test were stuff it doesn't really work and unfortunately that kind of view although Uncle Bob didn't mean to put it like this he's three laws of TDD and these are not laws that anybody is going to come round and knock on your door ago I'm afraid you've broken the law these are not physics laws you can actually break them it's quite easy we do it every day I but three guidelines okay one you are not allowed to write any production code unless it is to make a failing unit test pass - you are not allowed to write anymore of a unit test than it's sufficient to fail and compilation failures of failures three you are not allowed to write any more production code than it's sufficient to pass the one failing unit tests it turns out we actually need four because this is not enough what happens if I just follow these I actually I get this so what's that look like in practice okay let's do fizzbuzz right we're going to build it up this time okay assert fifth part of one is one brilliant how do I pass that pretty dumb a set of bits both of two - how I passed that copy paste copy paste this is the other kind of Enterprise programming it's not the one that is architectural II complex it is the one that is pure copy and paste it's brilliant cuz your productivity is awesome in one day okay because I've done yet done is okay how you doing let's just tidy it up so we feel there's a sort of elegant regularity boom done go home how you doing one hundred lines of code today yeah does it work one hundred one you're right you're right I get a free one as well that's great so hopefully one line code that works because we had tests how many lines are tested you have 100 you wrote 201 lines of code that works today brilliant yeah excellent have you reviewed it no has anybody else reviewed it no mmm so then you go home you think about this and you think you know what I'm not using all my techniques I'm not using all my education or using my brainpower you know what I need and you like us yes brilliant I need Landers and I need lookups this is how we do it this is how we do it's a dictionary it's a lookup I've been told to make my code more declarative I've been told I need to get more functional magnificent you know that's a work of art and then your colleague comes along and says yeah actually and in fact if we think about it it's not really that exciting but that's a terrible solution this is the point this is the bit here you're supposed to bring your brain to the party I don't actually like this as a way of describing the test first approach or the philosophy of TDD I prefer anchoring it in something slightly different I prefer the Deming shuart cycle which people normally associate with lean or agile thinking and at the large PDS a originated with shoe ups popularized by Deming a variation is that plan-do-check-act but I find the study I find the study term is is more important because study sounds slow study has the same first two letters as stop okay coincidence I think not okay the idea is to slow down static check is very cursory it's just like yeah checked it it's good study suggests you use your brain this is very hard well the evidence suggests it's very hard this is the bit that is below the water line plan and do a highly visible study enact these are they don't have substance so they're quite difficult to pin down but they turns out but if you want to run an experimental life cycle if you want to experiment in the large this is the most important bit people are always planning doing planning doing planning doing but the reaction about well how did that work out why did it not work out give me three theories don't just give me one give me three okay rule through that nothing is more dangerous than an idea when you have only one two is a good start three well now it becomes difficult to stop once you've got three you'll get four so the point here is this is the hardest part to do this is the bit we normally focus on the plan and the do whether it is user stories sprint velocities or whatever it is because it's visible this is hardly visible at all but it's the bit that makes the difference if you can experiment and try new things you need this lower part so what does it's got to do with TDD why do I think there's a better way of describing the test first cycle because if you can do it exactly the same way plan what you're going to do oh that's the tester here's the test for the code this is the behavior that I want this is what I'm about to write this is what it looks like or at least what I think it looks like I would like this to work it's a pull driven approach I'm going to pull from the ether or at least my brain I'm going to pull out an idea you should look like this let me implement it let me do it let me rare fire reifies to make real okay make it substance okay our test respect and then I make it real then I reflect on it in as necessary I refactor so there's this kind of idea of like when you look at it like that I okay that's why it makes sense red green refactor it sounds kind of catchy but it's actually it doesn't quite get you thinking is that this is about thinking okay it turns out this mostly about slowing down yeah if if software development were based on typing speed we would have solved that problem decades ago okay it turns out this bit is the hard bit having solutions it's the idea of being able to pause and think every now and then so let's try a different way of doing this okay so um so I've got and so I've got an actual so here's a list of all the fizz buzzes from 1 to 100 so I'm going to try a different way of testing it and there are lots of different varieties of testing one is obviously that you have a sample of here are all the possible outcomes it turns out for a hundred values that is certainly doable but when somebody says enterprise system which can have trillions or quadrillions of different states it turns out this is less than practical so therefore you need a different way of reasoning about it so let's just try a different approach not example based I'm going to take a property based approach I'm going to have an array or a list of truths okay there are things that must be true of the actual result for it to be a successful fizzbuzz okay and what I'm going to do is like assert all truths what are the truths look like well every result is fizzbuzz these buds or a decimal string every decimal result corresponds to its ordinal position every third result contains is every fit result contains buzz and every 15th result is fizzbuzz this is necessary but it's not sufficient it turns out you need another three conditions the ordinal position of every buzz every feeds result is divisible by three the ordinal position of every buzz result divisible by five ordinal position of every fizzbuzz divisible by 15 and now we discover the reason I chose Python is because it turns out it's quite easy to convert into Python so therefore we have a very simple concept of here are all the truths that are the characterize this okay so this is allows you to experiment in the small would like how good am I at discovering how to articulate the truth now you might want a framework at this point to make this a little easier but the basic mechanics if you like this very raw approach a lot of people assume that TDD is about frameworks and things like that it isn't framework extends the reach extends it extends the reach of your thinking but if you don't have the thinking they use have you're a fool with the tool unfortunately and I don't want to meditate out of you that's obvious to your colleagues not you because you turned up okay oh and your bosses I you know so they were your colleagues but they got promoted because they weren't good enough you know so stuff like that so at the point here is that it's the idea that there is do I understand the idea do I understand what I want from the framework and then it's just like yeah yeah I do this is the philosophy of taking a car to understand how it works and it's really good if you put it back together again but you know taking apart is fun in fact they taking it apart is fundamental decomposition where is the basis but there's another side of this composition and one of those composable approaches that we tend to think of these days people are focused very much on functional programming as a model of composability and I stumbled across this paper by matchy pirogue and apologies if I pronounced his name correctly fizzbuzz in Haskell by embedding a domain-specific language it's like yeah there's some really mental stuff in this paper it's yeah yeah however I'm just going to extract a small observation here and then take one of his results and do it slightly differently the default action is executed only if some previous actions were not executed this is true of everything that we've done okay so we looked at some programming languages for a bit of variety we look at javascript yes I did say that there we go this is the first solution just done as done again in JavaScript and you can see we are doing default action which is pretty number or generating number only as some previous actions we're not generated okay there's a stop that so there's a currently answer shame I can even get crazy with it let's do this by lookup okay yeah when you're bored in the office tomorrow you want to replace although this statements yeah you know why not you know this is this is a great way of doing it that great was in quotes by the way I'm not recommending this however we have a table lookup approach but again the default action into string is only executed if there's a there's a branch here it may it may look like an inner piece of notation but there is a conditional branch and he makes the observation ask the question can we accomplish this without having to check conditions for previous actions twice in other words can we make the control flow follow the information flow without losing modularity and the explores this in great debt I'm not going to explore in great depth but I'll give you I did this in a few languages and some great it was quite good fun reimplemented it's in different languages seeing how easy it was in some languages versus how hard curiously enough Java was actually the hardest the notation was really simple for the Landers but it's an absolute nightmare to get the declarations right and it's just like you're sitting there and you've got the declarations and then somewhere over on the right-hand side of the screen it's a little lambda expression that is oh so tiny and short out to the left is this really long preamble that you're going to ignore because it really isn't very interesting what we're going to do is we're going to have a lander called test it's going to take the divisor it's going to take a string and it's going to take something we can execute and what we're going to do is we're going to have a fizz that takes something that it can execute in other words another function and we're going to test and depending on whether or not the number n is divisible by three we're going to make a decision and what we're going to do is we're going to decide we're going to compose with another lambda so you end up with this beautiful expression at the end this is the identity operation that all works it's great anyway I recommend you go and look at the paper and have a go in your language of choice as to this and or drop me a line for the drop me an email for this code I put it up on SlideShare just so you can have a bit of fun with it but yet try in different languages feel what they find out what they feel like for me I think in terms of regular languages python and groovy were the easiest I found most languages most mainstream languages with an opinion on types are actually quite difficult by comparison anyway after a while I'm not recommending this as practical this is pure art except is it I mean there's a lot of ideas in here that are quite profound but let's look at another way there is another way let's make a very simple observation let's encode this okay let's see so let's encode this here we have a list 0 means is the default it's the number one means fit 2 means buzz 3 means fizzbuzz ok that's what it looks like and then it just repeats okay so that's the basic model okay so we've encoded it what I'm doing is I'm going to shift it round 1 so that all the indexing works from 0 and then yeah you could do this so a little bit of Ruby here 100 we Matt I into that and then we do this over here then a modular arithmetic and magic this works but here's the really crazy thing if you ever want to have a conversation with somebody about random numbers and so you know those random numbers they're not really random you do this so this blog I came across somebody recommended this to me because I've talked about fizzbuzz often enough that people send me crazy solutions assic magnificent this guy basically searched the rand space basically search the exceeded and searched for that little sequence that I just showed there where does this sequence occur ok and there it is for Round 4 that's the sequence so that's the magic number okay at that point you will get a nice repeatable implementation as long as nobody changes the implementation of s around and ran yeah yeah and so this is what we're talking about you might think wait a minute wait a minute that Emile Auguste Chartier quote maybe it is too dangerous to have more than one I do this is the kind of idea you're coming up with Kevin I know but it's fun this is the whole point it's enjoyable then I guess we ought to have a look at Haskell this is a variation of a solution I originally saw from Dirk Koenig who's responsible for the Frager language on the JVM and the way to introduce it is actually to return to one of the earlier observations about one of the earlier examples I had in Python but you know that originally the problem was limited to a domain of 100 why don't we just let go of the limits a little bit fiza's this is all the fizzes you will ever need blank blank fizz blank blank blank blank foods blank blank how many of them infinite you certain they go like let's see how much memory do I have on my my laptop yeah infinite ok here's all the busses you'll ever need ok blank blank blank blank buzz repeat until infinity so this slide currently contains two infinities ah this is great the slides got a lot of capacity because here's the third infinity I'm going to take those two infinities and I'm going to merge them caregivers zip them together so I've got now is blank blank spheres blank bugs see it's blank blanks there's bugs where it's necessary ok so these are all the words we will ever ever need for infinities these are all the numbers strings fives we will ever need 1 2 3 4 infinities you have a new PowerPoint could take that and now we have to make a decision number or word number or words and then we compose it so we get this bus what's interesting here is we're not actually defining any new functions in this this is actually that fizzbuzz is an infinite sequence okay or semi infinite because we know where it starts okay it starts at one then it goes to then it goes fizz then it goes for it just goes on and on and on to infinity okay what we do is we apply our choice to the words and the numbers we choose between them and then we just zip all the way down making that choice it's nice okay here's how we get away with it because it turns out that the best way to understand this is this infinitude which normally has to be expressed using enumerators or iterators in other languages is that this is all about laziness or another way of putting it is it's hypotheticals when we clarify what I mean by that because what we're going to do is blank blank fears we're going to cycle it from here to infinity dozen so we're going to cycle apamea to infinity words it looks like we're actually going to do some work but this is the clever bit this is how the lazy evaluation side of functional programming works it's so lazy it doesn't happen it's kind of like a promise it's like an idea it's just like if I were so this is the way you do it this is how this is how haskell gets around things like side-effects and how how functional programming gets around it it's a very clever way just for the side effects for i/o for example the weight of reason about it is to say in a pure functional language you cannot have side effects because these are pure functions but let me describe to you how I would do i oh I'm not doing it oh no no no doing is a an imperative thing but if I were to do it notice something very careful is an extra level of indirection in what I'm saying if I were to do i/o it would look like this but I'm not doing i/o but it would look like this Oh clever and then you hand this off to the wrong time but you are still pure yeah clever it's an outsourcing trick okay you outsource the state change you just describe it as if you were going to do it if I were to have infinite sequences this is how yeah if I were to count connect Lord this is how I would do if I wanted all the numbers I would take them this is stringify I'm going to apply the string operation from 1 to infinity if I were to do it it would look like this are you going to do it I never said I was going to do it I'm just telling you how I might do it classic mathematician approach yeah choice is either profoundly elegant or a real hack depending on your point of view I think it's really elegant this was I'm very pleased with this it turns out the numbers order perfectly with respect to the letters yeah or rather so this actually works out based on any character set you care to name on which there is a Haskell compiler because I did have somebody say yeah but one of your characters that doesn't do the right thing I will buy you a meal if you can find a Haskell implementation on a platform that has a character set that disobeys this no you can't hack it no it's good yeah no no no your gear you're getting me the mill yeah yeah this is it I might give you an olive ok you know ok ok so this is how we do so all this is all hypothetical nothing's actually happened here we just made a bunch of promises at this point we actually do some work give me the first 100 at this point we actually have an imperative statement or Haskell programs I tell you it's not imperative trust me I know language take is and I've got kids take is a very strong state stateful operation ok ok at this point we're going to make a commitment give me the first hundred at this point something actually happens up until this point nothing has happened yeah and so this is why it's called declarative I do declare this have you done anything absolutely nothing at all yeah so but it's a very elegant way of looking at the problem and this kind of stream based thinking this kind of incident thinking this kind of idea of operations on things it's both profound but also quite amusing this is quote from 2009 I love functional programming it takes smart people who would otherwise be competing with me and turns them into unemployable crazies it's because you see that is the problem when you start looking you know this is the kind of classic nature if you look into the abyss the abyss will stare back at you there are four infinities on this slide no I'm wrong five infinities I forgot this one there are five infinities you cannot look at infinity without having some kind of reality Distortion you go crazy of this okay I know it just enough time for a couple more things have a nice yeah so let's look at another Carter and I'm gonna do something slightly different with that I said I know a little bit about words exam right and I know a little bit about words and so therefore one of the things I do is I run a page word Friday on Facebook and every Friday I present an unusual word and the definition the rest of the week is just language and linguistic stuff that I find interesting that I found on the web the reason this is relevant is one of the words I featured a couple of years ago bike winery coded decimal okay you get bonus points if you can drop that into a conversation naturally tomorrow okay I do actually know somebody who always checks my word Friday stuff and sees if he can get it into a conversation over the weekend you know just get the word in sometimes it's quite a challenge sometimes you can do it ordinarily yes there you go that's perfect you know but you need to be more discreet you need to somehow just slip it in as if there we go yeah this is it or do it as a promise do it as a kind of like a declarative approach we've learned all about that so here my query coded decimal oh yeah what which work was that there you go so there's that that was a message based protocol you so you can cover all paradigms with this okay so system of representing numbers based on counting in fives I have no idea where that idea came from okay right counting in fives with an additional indicator to show whether the count is in the first or the second half of the decimal range whether the number represented in the range 0 to 4 or 5 to 9 or 1 to 5 and 6 to 10 ok so where do we see this well you see this in classic abacus systems like the professional advocate systems or the one you give to you not the ones you give to your kids which actually have 10 beads you have a 2 and a 5 system okay it was actually used in the Colossus computer a Bletchley Park before they figured out the binary was a lot easier to do and perhaps one of the best known ones is the Roman numeral system one of the other classic Carter's now there is a fabled tale which I wish were true but I don't think it is that actually the the letters of the Roman numeral system were came about visually in other words they correspond did not originally fer two letters but two indications that you could do across a marketplace so obviously one to historically you would actually do four rather than IV but if I want to show that something's five then that's five okay and then that's ten okay and you see this all works beautifully there's there's there's fifty and there's a hundred I want this to be true I don't think it is but I want it to be true okay however we don't have to worry about the truth of such things because we're going to do this enterprise style we're going to just do this one thing at a time we're going to build it up and we're going to do this and yeah okay let's try that change the font size there you go brilliant okay if you're being paid by the line of code this is magnificent okay this is this is how you earn your living but it is entirely possible you may spot some regularity I hope now one of the things I find interesting is a very subtle observation I noticed this when teaching my younger boy a little bit about programming is that if you ignore the else then an F is just a single one time is a limited form of while you can normally there's a lot of fun to be had trying to express one control flow mechanism in terms of other control flow mechanisms and it if it's simply a while with a very limited range okay Lex acute zero or one times whereas a wire will be 0 1 to n with that regularity in mind you can condense it down to a lookup ok now what is interesting about this is obviously the declarative approach there's this very simple idea that if you show me your data structures then I can tell you what your program does if you show me your data err your control flow I will struggle kind of obvious what we're doing there we've actually separated this out what is interesting is this kind of separation is actually quite fundamental in the large to a lot of software systems I have a look up and I have well I have a way of processing it processing things to look up that is that is proper division done the integer way it's kind of like divide now I really mean it you know yeah so so yeah this is integer division it turns out that the idea of polymorphic division based on types in a dynamically typed language is fundamentally flawed but it's taken a few few decades to discover that so here we have a simple way of ripping through a lookup and now what we've got is two areas of focus stability funnily enough this actually looks like a message processing loop that I wrote many years ago it was just like yeah I can do it all through a table and then suddenly we have a completely stable piece of code that is comprehensible and then a tabular representation that is extensible I don't expect to be extending the domain of roman numbers but nonetheless there is a fundamental idea here now this is all well and good but I mentioned John jagger before right at the beginning he came round in my house a couple of years back and we did some coding and he said oh I came across a new solution an alternative solution was an airshaft solution to the Roman numerals problem and I thought maybe we could try it out and so we tried it out in Ruby I'm not really a ruby guy no I'm not a ruby guy there's no really about it I'm not a ruby guy I can read bits of it and then I look at the rest and go you're kidding right so so I translated a mediator pison but it's elegant because again we've got another problem here that looks like an arithmetic problem but actually it and what we're going to do is if you thought binary was the fundamental accounting system because you're programmers you think binary you know that's it unary unary is more fundamental unary is the base that the universe uses okay it doesn't have a condensed form if I've got one thing I've got one thing if I've got two things it's two things this is two in unary okay this is three in unary you see four five you've got a billion stars yes there's a lot of them in unity one thing at a time so what I do is I take the number and I convert it into unary you give me the number 323 and multiply by I've got a 323 ice okay unary is fundamental perhaps it's not very Roman though so we reduce it it'll by little we condense it down we pipeline it we filter it we cook it down now I'm not making any claims for insufficiency but I am making massive claims for its elegance and importantly its explained ability because interesting enough good experiment with my kids I said I showed them this version and then I showed them this version the old ones 15 the young ones 11 and so you know but they still have the desire to go and look at something else that's got a screen and doesn't involve dad but so they got it there's a patience limit but you can actually show it's just like oh okay that makes sense there's a vector than elegance here it's just my hair I quite like this john emailed me the other day he'd be messing about with it as well he he decided he wanted to try a different variation so he decided to just focus on eyes axes and fees we could also factor that out ten nine five four ten nine five four ten nine five four there's lots of displays showing the regularities because a lot of elegance we had here although the disappointment here is we've reintroduced multiplication in lots of locations but actually no that's good because we've done no division and it's string multiplication anyway so there's a very simple idea here about thinking this is not actually an arithmetic problem it is a symbolic manipulation problem and there's a different way of looking at it so we may say okay well yeah Python but that's not really you know well you know I need to do proper functional programming so let's do this enclosure and this is why this is also talked about style because it turns out that not everything has a uniform easy-to-access style so if I do a straight translation into a standard afflictive language model then I end up with this let's change the font size on that yeah it's got that kind of I mean it's got a sort of maybe it looks like an airplane I don't know what do you think maybe it geese migrating in the winter I've lots of choices here comprehensible not so much so this the straight afflictive mole is not the one we want so we need to do some composition in other words in other words good need to start thinking in terms of higher-order functions so what we going to do here is two changes one is I'm going to use anonymous functions lambdas but not spelt lambda okay see this is the creativity you're going to invent a language don't spell lambda lambda all right either to either let your cat walk across the keyboard you know let your kids pick a random emoji or just ripple the valves out it's a function and I know it's a func got it brilliant we'll do it feel free use F next time because everybody will understand what you mean okay okay so now what we do is we've got a different model here okay so we've got comp composition okay so first of all we join this is our unary converter then we successively ah there's a problem with this but the problem here is that we are reading from the bottom to the top now every now and then a lisp programmer or close your program or columns they know it's perfectly natural no it isn't they are wrong they are trying to sell you something okay because in the same code base you'll have things that read from top to bottom and in other places you would read from bottom to top I don't mind which order just choose one so here there's a notion here right yeah I've got the elegance I've got a power but it's going against the grain of what I want to do in terms of pipelining so okay let's simplify it before we get there now it's beginning to look much more like a table so a little few abbreviations we can throw then I'm going to use a threading operator and I'm actually going to go back and use the member replace just to keep it simple here and then we've recovered that but we've got a very different way of looking at it and there's a what is nice about this is I'm no closure programmer but it doesn't take a lot to explain this what is interesting about a number of these solutions is they're explanatory power it's the idea that it's not that you can read it immediately but it takes very little to unlock it if you look at the if-elsif versions if you look at these complex control flow versions they take a lot more deciphering here you can show somebody who doesn't even program what you're doing you can just walk them through it they go huh it's easily explainable explain abilities are very often overlooked power or quality of code so there's a really important idea here and richard fineman and we could of course use many notation we want do not laugh at notations invent them they are powerful in fact mathematics is to a large extent invention of better notations okay there is a very simple idea sometimes we go syntax sugaring it doesn't really change it does change things it changes things profoundly certain symbols whether we are talking about moving from Roman numerals which really are quite difficult to work with okay so the Arabic model which is positional and is much easier to work with it makes things easier there are notations that allow us to stretch further and what you're doing when you program is inventing a language to talk about your problem to me okay so feel free to push out a little bit don't go too crazy but if you're going to do it do it in a concert it's a perfect place to experiment it's a small self-contained laboratory for techniques now if we're going to talk about notations and I've been talking about pipelining and things like that I did think I would have a go at doing this on the command line just for fun roman 42 xlviii there we go there's my unary converter that's very pleased with this this is hideous being efficient so we can actually put it all in set so there it really is just text manipulation it's a text manipulation problem it is not an arithmetic problem at all you thought it was about numbers it's not so again there is something profound here that is basic to all all programming will you convert a problem that looks like this into a problem that looks like that oh you told me it was a number problem actually it's not or rather I can show you something else let me show let me take that problem and now I understand it turn it through 180 degrees and then an imaginary amount and I will give you something else that you did not think of before and it will provoke thinking that's the whole point of these so I will end with Jeb Browns quote we talked about style talked about form style of times full form is time student form is ultimately what you're after forming body's understanding when we use the term car towed it's not simply a training exercise of repetition which is good that's about that the basis of it it's practice but it's also an opportunity to experiment and sometimes we overlook the second part of like okay I think I know this I showed this to a friend of mine as a mathematician which kind of came up to me afterwards and said okay two things one I didn't know they were that many proofs of Pythagoras too I thought I knew the Roman numerals solution okay there is always more and there always will be more thank you very much [Applause] okay we've done a couple questions maybe yep yes hey I'm fine for you yeah have you responded right in their palaces and don't vote that's really interesting no that's why I do this because now you give me an idea that's great I love it the letters like oh yeah yeah there's a regular patenting and once you've seen it hmm yeah sorry ten five ten nine five four there is this recurring pattern what about extending Roman numerals okay so therefore let's just imagine occur people love the alternative timelines what if the Romans had kind of gone on for a bit longer and decided that they'd keep the number system and decided that numbers were not big enough how would we extend this you could make it regular you could create your own number system based on this bike winery code decimal system I have an extension oh yes yes but actually I think I might go through the I might go for the Eastern Empire because the result would be quite violent I'm okay right another question and feel free to do it extended revenuers code I've never thought of that I've seen extended fizzbuzz I've not seen extended Roman that's great any other questions thoughts reflections desires severe desire to play fizzbuzz in Brackman you've got to be practical haven't you I've just shown you the theory of this bus afterwards that's right excellent sampling with videos and iNDOT of sewing business so I spent a couple hours writing other yeah it is it is quite fun because it's a self-contained problem you'd be surprised how much you can come out with and occasionally a spark of inspiration comes along goes you know what I think this could lead to something else it makes you look something else that you learn more of the language it makes you say what about this language what about that language it causes you to do things that creates a chain reaction occasionally people say but how can I use this in my everyday code my answer is I don't know you tell me okay that's that's the idea of play this is a really important idea so it's fundamentally so yeah change the context and there's actually some very good examples yeah change the context change things like the sizing of the domain what if it's a thousand what if it's a million okay yes yeah there are fizzbuzz variations that do other things in other words there's lots of possibilities of variation and each one points in a different direction it was actually a very interesting example I did at a company it was bigger than this bigger than these ones it was actually a programming contest example over the phone number lookup approach phone number prefix lookup approach and it was interesting because four of us had an approach we did it in Python and it was for a workshop and we wanted to show four fundamentally different approaches so I went for an approach that was minimal pythonic and functional somebody else for went for an approach that was massively efficient used trees and all kinds of stuff somebody else decided to just do it in a scripting style you know I will do pipe in the manner of a scripting language just pure scripting approach sort of classic procedural scripting and then somebody else did an in-memory approach and it was interesting if you change the parameters the problem slightly then it became completely impractical but memory is one of those things that you know we seem to be getting more off because it turns out one of the things that we have learned is you can't beat the speed of light okay unless you have all that exotic matter you know we you know if you have it then you know what are you doing here on earth it turns out that we are it turns out that the network is always going to be slower than your local memory so therefore if you have more local memory so that you can do a lot more computation so this idea is that his solution would scale given enough years yeah and that's not a stupid idea because if we look at many of the solutions that we now adopt if you go back ten years go back 20 years just like people would say you'd never be able to run that in memory that's impractical oh we're doing it all the time now so these things change yes ah sleep so I love sleep sort sleeps thought is one of the most counterintuitive and yet profoundly elegant ways of doing something has anybody come across sleep saw and this is this is off I'm going way off slide here sleep thought is is I have an example I think I have an example it is it is it is beautiful in a way that is insane it will it is yeah there's something there is something quite beautiful about it oh yes there we go here it is okay so so here is my reduction of sleep sort sleep thought was possibly the only good thing to ever come out of 4chan we don't know who invented it because it was a non anonymous poster they posted a much more complex version I've reduced it down to actually straight Bourne shell you don't even need Bosch so we've got that and then ok let's execute it and what we're going to do is I'm going to sleep sort 30 digits of pi 1 1 3 4 5 wait for it this is a new rule sort of requirement I get like gee knowing I have to look at that because I this one that has certain properties I guess that one of the properties it shares with the quantum computation actually no the quantum one should be oh one this is linear yes yes yes I've got other sorting algorithms on this particular slide deck you know if you're really interested in you know really bad sorting algorithms I I've got them you know so here's a permutation based approach which is factorial complexity this I use this I use this one people say oh yeah we don't have any performance requirements you know the best way to find out people's requirements you give them something like this and then suddenly they will discover they have requirements ok it's just like this is this has got factorial complexity then we've got BOGO sort I didn't I didn't put any of the other ones in which just uses random take a take a sequence shuffle it is it sorted no shuffles again keep going the complexity of this is OMG so yeah there's a whole host of these things but they are all provocative they all do something they get you thinking and sleep sort I just love the nonsense or the insanity or the elegance of sleep sort because this whole idea of it actually linear but it shows you that you can now form all of these processes out if you have if you have all that stuff available then everything is a processing note you just have to scale the time appropriately because it turns out that the linearity logarithm assist logarithm is City or quadratic nurse is actually not your problem it turns out it's a different problem but it makes you understand that performance is not simply a property of complexity but yeah so you know there are some really insane things out there and on that note we're done thank you [Applause]
Info
Channel: Wix Engineering Tech Talks
Views: 31,030
Rating: 4.8386412 out of 5
Keywords: Wix Engineering, Wix Eng, Kata, Kevlin Henney
Id: _M4o0ExLQCs
Channel Id: undefined
Length: 74min 33sec (4473 seconds)
Published: Tue Aug 15 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.