PyCon 2014

Mejora tu código con los tests unitarios

Greg Ward  · 




Extracto de la transcripción automática del vídeo realizada por YouTube.

alright hi everybody thank you for your patience I'd like to introduce Greg Ward who's going to talk about how unit testing makes your code better thanks everyone so unit testing is one of those things that everybody believes in everybody everybody

says it's a good thing but how many people really do it I'd like a quick show of hands how many people rigorously write unit tests for every piece of code they write every day of their lives production code work code personal projects yeah me neither

how many of you do up most of the time for most code especially when you're being paid money yeah that's about where I am excellent you're my heroes so you know it's kind of like public transportation that's the joke everybody everybody's

things other people should do it so I've got a couple assumptions about you for this talk I'm assuming that you either just SAT through Ned bachelors excellent talk and you're ready raring to go you've started to drink the kool-aid or you're

already actively drinking the kool-aid you're already into the unit test mindset in other words i'm not here to teach you unit testing Ned just did that so the corollary of assumption number one is you already get that unit testing helps make your

code more correct I'm not going to try to convince you of that it's as obvious as trying to convince you that water is wet or the sky is big when I say that unit testing makes your code better i'm talking on the higher plane I'm talking about

elegance aesthetics beauty that kind of stuff so if you're one of those people who says elegance elegance I just want to get something working I want to ship it I want customers or users running my code now or as soon as possible that's great I'm

a big fan of shipping code despite what some of my past managers might tell you but let me try to convince you that beautiful code is better code it takes a little more time up front but in the long run it pays off it's easier to understand it's easier

to extend its easier to reuse if unit testing makes your code more beautiful it makes it better so the plan for this talk is to work through a real-life case study this is not some imaginary made-up example this is this is real live code from my real life

job that did not have any unit tests when I started there about eight months ago I'm going to briefly sketch the process of adding tests to this code but that's not really the focus of the talk that that was Ned's job and he did a great job of

it Thank You Ned instead I'm going to try to demonstrate how imperfect design leads to Harry tests and Harry design or Harry tests are a smell that tells you the design is imperfect and when you modify the design so that your tests become simpler you have

better code you wind up in this virtuous cycle we're simpler tests means better code and better code means simpler tests so the background I have to spend a few minutes explaining like I said this is real life code where did it come from why does it exist

it's got certain requirements that mandate a few slight peculiarities about the code most importantly what requirements does it meet because while the code we're going to look at is not perfect it's pretty darn good code if you see the totality

of it I'm unfortunately going to focus on the kind of smellier bits but the whole module that I'm talking about was really quite beautiful and it met its requirements all I was there to do was add some unit tests but of course I couldn't resist

so we meaning my employer obligatory hyperlink there are in the business of measuring the internet and we do that a couple of ways one way is we paying every IP address in the world every couple of months more relevant we trace route all over the world from

all over the world all day long we collect about 200 million tracery today and 200 million tracer routes works out to about 3 billion hops every single day so we're trying to extract some sort of intelligent meaning from this torrent of data and when you're

dealing with that much data obviously clearly you need a super-duper highly advanced next-generation whiz-bang data storage and representation technology which is why we mostly use tab-separated text files yeah I mean yeah we use postgres when it's the

right tool and we use Redis when it's the right tool but we have vast stores of data in tab-separated text there are some obvious I hope well probably maybe not so obvious rules for staying sane with plain text plain text is a very simple data format keep

it simple stupid you really want to restrict the data tightly if you're using tab as your delimiter don't have any tabs in your data make sure you filter them at first if you're using comma for your delimiter don't have any commas in your data

[ ... ]

Nota: se han omitido las otras 2.436 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.