Did you come to software development outside the traditional computer science path?
This is common, and it's even how I got into programming myself.
I think it's especially true for data scientists and folks doing scientific computing.
That's why I'm thrilled to bring you an episode with Daniel Chen
about maintainable data science tips and techniques.
This is Talk Python to Me, episode 227, recorded August 6th, 2019.
Welcome to Talk Python to Me, a weekly podcast on Python,
the language, the libraries, the ecosystem, and the personalities.
This is your host, Michael Kennedy.
Follow me on Twitter, where I'm @mkennedy.
Keep up with the show and listen to past episodes at talkpython.fm,
and follow the show on Twitter via at Talk Python.
This episode is sponsored by Indeed and Rollbar.
Please check out what they're offering during their segments.
It really helps support the show.
Dan, welcome to Talk Python to Me.
Hi, Mike. Nice to meet you.
It's great to meet you as well.
I'm so glad that we got a chance to run into each other at PyCon this year
and learn about what you're up to because we're going to have a good time talking about it.
Yeah, and this year was the first year I was at PyCon,
and I typically live in the data science world,
so it was one super cool to be at pretty much a convention of Python users.
And I almost forgotten how Python is outside of data science.
Django is a thing.
It was a thing that was repeated back to me.
Yeah, exactly.
That's pretty interesting.
What was your take on it?
Do you recommend people, especially data scientists, attend PyCon?
You're happy you went?
Yeah.
I mean, it was super cool.
I mean, data science is sort of one of the growing parts of Python as a language.
And I think a lot of people have said it's sort of the reason why Python has picked up in popularity recently.
And so, yeah, it was super cool just to see all the booths.
I personally gave a pandas tutorial there, so it is becoming more and more of a thing.
And I think there were two or at least three pandas-related tutorials during the session.
Yeah, I know Kevin Markham gave one as well, I'm pretty sure.
At least something on data science there.
So, yeah, there was definitely some interest.
I think I met one other person who's doing one.
So, yeah, it's pretty incredible, right?
Yeah, yeah.
And then, again, there's this whole web stack of things that I almost never really use,
but a lot of people do use it as well.
So, it's super cool just to see it and be reminded what Python can do as a language.
Yeah, that's cool.
And for me, it's exactly the opposite, right?
Like, I spend a lot of my days writing web apps and APIs and things.
And then to see the data science stuff, it really reminds me, like,
there's a really different way to work and other things to optimize than, you know, scalable web apps.
Yeah, yeah.
For sure.
So, totally recommended to go.
And, like, you know, there was, like, some talk on Twitter, like,
don't always try to do the hallway track if you can, because, like, speakers,
sometimes speakers would like people in their audience.
But I tried to go to the talks that I can.
But then there were a few, like, education-related hallway track groupings or meetups.
And that's what I attended to.
So, it was just nice seeing other, like, Python educators,
which I also went to SciPy a couple weeks later.
So, it was some of the people I saw again for the second time.
And I was like, oh, cool.
Yeah, I definitely love going to Python.
As people know, I talk about it all the time.
And it's a really great experience.
And what I think is interesting is a lot of people feel like they have to be experts to go.
I met a lot of people who are fairly beginner in their career.
And it was really valuable to them to be there.
So, I just want to throw that out there for people.
Yeah, super welcoming.
I mean, that's sort of the reason why I stuck around with Python.
I'm also, like, pretty active in the R community as well.
And between Python and R, a lot of people join for whatever reason.
But again, like, the saying, as the saying goes, like, they stay because of the community.
And everyone's, like, just super nice and helpful and super beginner-friendly.
Absolutely, absolutely.
All right, well, I haven't got a chance to ask you the opening questions.
Let's start there.
So, before we get into all the techniques and tips and stuff you have for data scientists
to bring in more structured programming stuff to make their data science techniques and tools better,
let's talk about you.
How did you get into programming in Python?
So, I was pretty much always surrounded by computers as a kid.
I always had, like, the hand-me-down computer when I was a kid from, like, my parents when they were working.
I guess it sort of does help that my dad is a software engineer.
But it wasn't really, like, a thing when I was at home.
Other than, like, hey, dad does things on computers.
That's kind of cool.
I was always tinkering around with computers.
So, like, I do remember, like, the first thing I would do every time, like, I open a new app is, like,
hey, let's go to edit and preferences and just see, like, what I can change.
And it was sort of just tinkering.
I grew up in New York City.
I'm from Queens.
And I went to one of the specialized math and science high schools in New York City.
And so, for us, sophomore year, it was actually mandated that every student take one semester of computer science and one semester of technical drawing or drafting.
That's pretty cool.
I think drafting is less valuable than people imagined it.
Because I remember I had a drafting class as well and I don't really see it.
But the software thinking and tools and ideas are certainly is.
What language was that in?
Pen and paper.
And then CAD towards the end.
Yeah.
So, yeah, we were, we were, like, in, like, a room and we were drawing, like, isometrics by pen or pencil and ruler.
Those big slanted tables.
And the programming one, what was that?
What technologies did you all cover?
It was, like, it was only towards the end.
And it was, like, in some CAD program that I don't remember.
Oh, okay.
Yeah.
And it's, like, interesting.
Like, that was a thing I never, I thought it was super cool.
And then, like, now that 3D printing is a thing, it's sort of, like, oh, wait, I used to kind of, I've done this once.
But, like, I just haven't done it in many years.
So, it's, like, kind of interesting.
Yeah.
How interesting.
Yeah.
How cool.
Well, that's a great introduction.
And then did you study computer science in college?
So, I didn't.
And that was part of it was I didn't notice until I was in college.
But when we had to take computer science in high school, it was sort of, man, all of these other people.
And by, like, other people, it's, like, just a handful.
It was, like, man, they're really good at this.
There's no way I'm going to be able to study this in the future or, like, for a career and whatnot.
We did the one semester of computer science.
I didn't go for the AP or anything because, like, originally I was going to, like, go down and be a medical doctor.
That was my original plan.
So, then in college, I ended up, how do I make my, like, medical education as strong as possible?
Let's do, like, neuroscience and sort of, like, a bio-heavy program.
But, like, that's where I sort of took my first set of statistics courses.
And I was, oh, yeah, like, we hear about mean and standard deviation.
But to finally understand it in the context of, oh, yeah, here's the exam scores for the previous exam.
Like, how do you actually rank?
Just something like that, like, get some meaningful understanding of, like, where do you rank in the class?
And it's, like, oh, maybe this is how the curve is going to be.
Or, like, did I, I didn't do very well in the exam, but, like, I'm actually kind of okay.
So, that was cool.
And then because I ended up switching into neuroscience my second year, I had to stay, like, a fifth year in college.
And so, like, my last two years was, like, oh, you only need four classes to do, like, a computer science minor.
So, I was, like, yeah, I've done this in high school.
Let's, like, just pick this up for fun.
And then so, it was that first intro computer science class when we got to, like, the actual Python programming portion where I was, like, wait, this is actually not as terrible.
And I would see the other students, like, in which case, like, they would be freshmen and I would have been, like, already a junior.
And I would see the freshmen, like, they've never seen this before.
Their struggles were essentially my struggles back in high school.
And then I realized, oh, it's literally because, like, I saw it before.
And, like, even though, like, not much of it got retained, it was just thinking about things procedurally, just doing it once.
Now I can actually think about, like, syntax errors versus, like, doing everything at once.
That's sort of when I was, like, huh, maybe I could have done this as, like, a career choice.
But, nope, nope.
Let's keep going down the medicine route.
So, I ended up doing a master's in public health and epidemiology just to stack on more research skills.
The thought being was, hey, research in medicine was super cool, but I'm pretty sure if I ever start medical school, I'm never going to learn this stuff again.
So, let's just learn everything and then go to medical school.
So, I did my master's in epidemiology, and that's when I took my first, like, intro to data science course.
And that is probably the most life-changing moment in my life.
When I was doing my master's, I was already just learning about all of these other basic statistical techniques.
I've never heard of logistic regression before.
And that's, like, the type of analysis you do when you have a binary outcome.
So, for us, it was like, did this person die?
Yes or no.
Or did this person get cancer?
Yes or no.
And I've never seen that before.
And it was just like, wow, this is amazing.
And then I take my data science class and I was like, what is this random forest thing?
This is amazing.
Or, like, what is this, like, ridge and lasso regression?
And, like, I can just, like, condense, like, thousands of variables into, like, something meaningful.
Like, that's super cool.
And so, that sort of started this whole trajectory down to where I am now.
Because it wasn't until, like, that data science course I, during that semester, because there was so much learning to do, the instructors set up a software carpentry workshop.
And so, I was an attendee for software carpentry.
I think software carpentry is a really cool project for folks with the background exactly like you described.
I actually had Jonah Duckles on the show way back in episode 93 talking about software carpentry.
So, it's been a really long time since I've spoken about it.
Maybe just tell the listeners out there what software carpentry workshop is about.
Because it'd be good for a lot of folks who are in the data science and sort of science in the programming space.
So, yeah, it's sort of expanded over the past, like, couple years.
But software carpentry and their sister program, Data Carpentry, they're housed under this one umbrella called the Carpentries.
And, essentially, they're this nonprofit organization.
And their goal is simply to teach researchers or scientists the skills that they need for, in the sense of software carpentry, like, programming skills.
And then, in the case of Data Carpentry, like, working with data.
So, like, data skills.
And the two really just go hand in hand.
So, you'll mix and match.
They have a lot of overlap.
And, essentially, there's these two-day workshops where they cover Bash for the shell.
And the whole premise of that is to, like, show you about, like, what is a working directory?
And programs do one thing and one thing really well.
And you can pipe them into one another to chain things together.
So, that's, like, what you're supposed to take away from Bash.
And then they go through Git for version control, which it's really hard to get an understanding of Git in three hours.
But it's just to show you that, like, there are better ways than naming your files final, final, final, et cetera, et cetera.
Putting the date on the end.
No, like, really, final.
Yeah, and putting the date.
And then there's a section on Python or some of, like, R or any of the other programming languages.
And it used to be that they also had a fourth section on SQL.
But then, usually, SQL gets bumped out for, like, a longer Python or R session.
So, it's a two-day workshop that covers those skills.
And it's really to give, like, researchers a primer because we go into science not thinking that we're going to program.
And so, like, a lot of this stuff is just like, oh, I picked it up on my own.
And it's just a bunch of stuff hobbled together.
And that's how we learned it.
And actually, that's how, like, a lot of people in data science, like, that's how they learn programming.
And then this is, like, the first time, like.
I feel like, yeah, I feel like this is actually really common, as you're saying.
And I think it's also a little bit why Python is growing a lot in the data science space.
Is it's, like, what can I do that's an easy step to do just enough computation to solve my problem so I can go back to what I actually care about?
Because I don't want to be a programmer.
I want to be a biologist or a doctor or whatever.
But then you slowly find yourself six months later with, like, a lot of scripts.
And you're running code and you're using pandas or NumPy.
And you're like, well, I have no qualification for this.
But here I am, like, in it somehow, even though I swore I would never do this because I hated math or something like that, right?
Yeah.
So that's the whole premise of the carpentries is, like, okay, let's take one step back.
You learn how to do this on your own.
And let's, like, refresh, like, the actual basics and, like, kind of, like, steer you in the correct way.
That's the general lowdown of what the carpentries are.
That's cool.
And you started as a student, but you became an instructor, right?
I was a student, like, fall of 2013.
And then it was, like, just at the cusp of, wait, I can actually teach this stuff.
It wasn't, like, that much a leap and bounce.
Like, I already knew a little bit about Python programming.
So, and then the Bash stuff.
I was, like, one of those people in college that was, like, I'm just going to install Linux and see what happens.
Deal with, like, problems that come from that.
I've been saying to myself, like, it's the year of the Linux desktop since, like, 2010 or something.
It's almost here.
So I ended up signing up to, like, go help out.
You end up realizing that, like, for a lot of newcomers, a lot of the problems that they have aren't actually that complicated.
And then just to go into, like, education theory a little bit, it's, they don't have a lot of nodes to make connections with.
And so a lot of their problems is also, like, just they'd made a typing mistake, right?
Like, they're just not used to hitting tab to tab complete things.
So, like, everything is mainly a typo.
So I started off helping out a few workshops.
And then I matriculated into, like, their next, like, instructor class where I was, like, certified to be an instructor where it was mainly, like, getting familiar with the material and, like, learning how to teach the material.
That's cool.
Yeah.
And then I was an instructor.
And my first couple of years as an instructor, that was, like, right on the border of, I was still in grads.
I was, like, finishing up my master's program.
And also, like, I had a job.
But I ended up working so much during my job that my boss was pretty much, like, please go home.
And so I spent a lot of time going home.
But it was really just, like, go teach, like, other workshops.
And it was, like, super nice being in the New York City area because, like, going to a university or any place was pretty much local for me.
So I got a lot of teaching experience out of that.
And I didn't know at the time, but I say it now, like, teaching is, like, one of the best ways to learn something.
So Bash and Git and Python and later on R, like, I just got more familiar with it just because I was teaching it all the time.
And then, you know, once you have some foundation, like, learning the next small bit of information is, it becomes easier and easier.
And then it just snowballs into something.
That's cool.
Yeah.
And then, like, all of that teaching knowledge ended up being, like, the foundation for, like, the book that I ended up writing or was tasked to write or call pandas for everyone.
I mean, it's really, like, an honor that, like, I got recommended to write this thing.
So I should frame it in that sense.
I've done a lot of training as well.
And I feel like once you kind of go through a couple of cycles of that, you just get so good at learning something with enough depth to present it that it becomes, like, this really great power.
And it's kind of addicting, right?
You're like, oh, what's the next thing I can learn?
What's the next research project I can go on?
And, yeah.
So it sounds like you did the software carpentry thing and it kind of somehow sucked you down this pandas for everyone hole of writing this book, which is Addison Wesley, which is pretty cool.
Even writing the book, like, now you're just like, oh, I just can't write, like, really janky code anymore.
Like, this actually needs to be, like, quote, unquote, like, the better way of doing things.
So, like, there was, like, still, even though I was, like, writing a book and I was supposed to be the expert in this, like, a lot of it was also, like, I should probably read this part of the documentation just to make sure.
Because, like, I also learned this, like, on my own.
Right. Well, that's the thing about the difference of practicing as a programmer or as a data scientist versus an author or an instructor, right?
Like, as a practicing person, you have a problem.
You're like, I need to figure out how to make pandas do this.
Like, it doesn't matter how it happens.
But if you can make it happen, you're done.
Like, that's the end of the research.
You're done.
This part is solved.
What's the next problem?
But as an instructor, like, well, but there's these other two ways.
And but if somebody says, well, why not this way versus that way?
What's the difference?
All of a sudden, like, all these cases that would you would never go down, like, you have to start going down those now, which is I think is awesome, actually.
But it's definitely a different way of thinking.
It's super cool because, like, now it becomes its own, like, learning path.
Like, you see other people have problems and you see how they think about it.
And, like, it sort of adapts how you present material.
For me, when I was originally, when I first started off teaching workshops out of the book, I pretty much went in the order that I presented the chapters in.
And then more and more recently, like, I realized, like, wait, like, tidy data principles is actually, like, one of the most important things in, like, data science and data cleaning.
After we load our first data set, I pretty much just jumped to, like, that chapter.
Because if you can really understand that, everything else becomes way easier, quote unquote easier.
Yeah, sure.
Well, if you're trying to do operations on bad data and it keeps crashing, like, that's no fun.
Like, why does it say none?
Is that invalid?
You know, it doesn't have this attribute.
I don't understand.
Like, well, let's talk about that.
This portion of Talk Python to Me is brought to you by Indeed Prime.
Are you putting your Python skills to good use?
Find your dream role with Indeed Prime and start doing more of what you love every day.
Whether you're a developer, data scientist, or anything in between, one application puts you in front of hundreds of companies like PayPal and VRBO in over 90 cities.
Indeed Prime showcases your experience and tech skills to match you with great fit roles that meet and exceed your salary, location, and career goals.
And when you start a one-on-one conversation with one of their career coaches, you'll get resume reviews and personalized advice to help you get what you deserve.
So, if filling out countless job applications isn't your thing, let top tech companies apply to you.
Join Indeed Prime for free at talkpython.fm/indeed.
That's talkpython.fm/indeed.
The reason I wanted to talk a little bit about software carpentry, other than just like you have been doing in his school,
is I think it's a really good segue into this larger topic of how do you take the average data scientist and the work that they're doing
and help bring in these more computer science, maybe not even computer science, let's say software engineering principles,
to help them basically be more effective, right?
So, maybe we start at the beginning.
We've got some idea.
We probably found out we can open up a Jupyter notebook, load something into Pandas,
and poke around with it with a Matplotlib or something, right?
Maybe that's it, right?
Maybe we've seen a lot of Matlab code as well, where it's like, well, I got this does this thing,
but it's like there's no functions.
Maybe there's loops, maybe not, right?
It's just like all crammed in there.
And those are PhDs writing that.
So, like really brilliant people, but they just don't have the software engineering skills.
So, where do we start with that?
There's a few papers I would direct people to sort of get a sense of where I'm coming from.
So, there's this one paper by William Noble called A Quick Guide to Organizing Computational Biology Projects.
And that's sort of the premise of how, I guess, I would present, how do we introduce software skills?
And in that paper, he literally talks about you should have a folder structure.
And maybe this is one way you should set up your folders for your analysis projects.
And I'll talk a little bit about that in a bit.
But yeah.
Yeah.
So, it's called A Quick Guide for Organizing Computational Biology Projects.
And, you know, it's probably focused on biologists, but I'm sure that it's like pretty generally applicable.
Yeah.
Other than like maybe the sequence.py file, like replace that name with whatever you need.
Right.
It's Hubble.py or whatever.
Yeah.
And the other two papers, the first author is by Greg Wilson, who restarted Starforce Carpentry, like back in the 2000s.
And he wrote two papers, one in 2014 called like Best Practices for Scientific Computing.
And then in 2017, the paper is called Good Enough Practices in Scientific Computing.
If you just look at the papers, it almost seems like, hey, we're presenting like the ideal case.
And then we almost realize like that's impossible in the real world.
But they're both like pretty good papers.
And they talk about like different things.
Right.
What would we have if we had like the perfect adaptation of software engineering to this world?
Like, okay, well, what can we reasonably ask people to do that will make their life better?
It sounds like.
Yeah.
And the way I approach it is like, just like when I teach data science skills, I pretty much make a beeline to tidy data and tidy data principles.
In this case, it's almost like a beeline towards project organization.
Just having some kind of structure to your analysis project.
That will snowball into all of the cool tools that you probably heard of and don't know how people end up there.
But if you take slow steps, I found that project organization is the fundamental thing where it's sort of like the gateway to everything else.
Right.
Because a lot of what you need, it sounds like, is code organization.
Right.
It's like the architecture and functions, classes, different modules, the concept of I'm going to pass data to this thing and make it reusable.
All of that stuff really seems to be like natural follow-ons of like, well, how do we organize this project by function or by purpose?
And like, just really think through that, right?
Yeah.
And it doesn't even have to be as complicated as, oh, we're doing like proper software engineering and like we need to create a Python package.
Like that can all be deferred to much later.
Because usually what ends up happening, you mentioned like, hey, I'm a scientist.
I found out about Jupyter Notebooks.
It's a really cool tool.
Taking pictures of black holes out, like using them.
So, yeah, you have all these tools.
And like the scenario is like, hey, it's great that you're using a programming language to work with data.
Excel is a great GUI for data, but it has its limitations.
Cool.
You are now using a programming language.
Where can we go from there?
And like when you are in that beginning state, just to make everything work, like you dump everything in one folder.
You have like your Jupyter Notebooks.
You have all your scripts, all your data.
Your data files.
Yeah.
If I say load this, I just want to say the file name.
I don't want to have to think about like where that's relative to the other on some like server or something like that, right?
Yeah.
And then like as an academic, you might have like a Word doc in there or maybe a LaTeX file.
And then you compile that thing and it very quickly becomes this folder with hundreds of files and you can't find anything.
And that's when you just start end up, you know, maybe the word final comes into like the beginning of the file name just so like you can find things, right?
Yeah.
I was going to say it already sounds bad.
And then if you start trying to do version control by like having multiple files named the same thing, then you're really pushing your luck.
Yeah.
So the most important thing, I think like if you're at that point, where can you go next, right?
It's always like trying to do things incrementally.
Like how do you make your life like 10% better each time?
And then it's like a nice way, especially if you're like brand new grad student or you're in science, but like you've never really learned programming.
Like where can you go from there?
It's useful to have some kind of guide or path that you can follow or think about to like make yourself better and do these things more efficiently.
Yeah.
So let's talk about some of the programming things that you can think about.
One of the ones that you have is like try to make your code easy to read.
Oh, yes.
So one of the things I talk about in programming is like make things easier to read.
Do things in steps.
Don't try to like write one for loop that have a whole bunch of like side effects going on, right?
Like things should just be incremental just to take like a cue from like education.
Like we as human beings can only carry, I think the number is like four plus or minus three objects in our mind at the same time, like roughly seven.
You should pretty much follow that too.
When you're programming, you shouldn't have to have, I mean yourself or like potentially another reader try to carry like 10 different things going on at the same time.
It's just not helpful for.
Like maybe an example is I'm trying to go through a loop.
I'm really trying to do three things.
Like as I get the data and I compute something with the first step and then I do some other filtering and I do another thing.
I could try to cram that into like one giant loop or maybe it should be three separate little loops.
One that like cleans the data, one that like does that computation, another that then filters it, right?
Three loops sounds like a better step than one giant loop trying to do it all.
Yeah.
Or you can more in like education framework, like, or you can like group things together.
And in programming, the way we group things together is like write functions.
So then you end up with one giant loop and it's really just making three function calls, but that's easier to keep track of than like, let's say we didn't write the function.
Now we have like three different things like scattered in our code and you end up with a loop that's 150 lines long.
And that's like scary because like I see a loop and like before I even look at this thing, like I'm already like, oh man, we are in for a ride.
Right.
So let me just give my perspective from like the software development, web dev, you know, more application side of things.
It's like, if I see a function that's more than 10 lines long, it starts to make me nervous.
I'm like, there is something going on here that's probably bad unless there's like a lot of error handling and like response, like even 10 is a lot in the typical scientific computing bits that I've at least seen a while ago.
There was more than 10 lines.
There's more than 10 lines.
And so like Jenny, Brian, like from the R world has like this talk about like code smells.
And it's like, that's like one of those like code smells of like, Hey, why does it look like this?
Or like, at least when you're working with data or in the PI data stack, usually you shouldn't have to write for loops in the sense of like, if you're trying to operate on a data frame, they should be an apply call to a function.
Even like sometimes when I see loops, it's like, yes, I will write them just because something broke.
And I'm just trying to figure out like where my data frame, like I have a bad value, but like the final result ends up being like an apply call or something.
Yeah.
It's interesting because a lot of the libraries, NumPy, Pandas and whatnot, can they do the looping?
They do it much faster and more efficient than you will in Python.
One of the cool things that I like teach during the data science part is like when we go over like applying functions, if you're doing numerical computations, like just the NumPy decorator for like vectorize or the number decorator for vectorize, like just wrap the decorator around your computation function.
It like pretty much for free gives you order of magnitude speed improvements.
And so it's like, it's way better than just you trying to like optimize this thing yourself.
Right.
And that's like one of the other programming things.
It's premature optimization is like the bane of all evil or whatever.
Just write the thing you want, especially if they're like loops.
Python has many mechanisms to like help you with that and make it faster pretty much for free.
That's definitely cool.
I love this idea of code smells.
I'm fascinated by it.
I want to come back to it.
But another thing I want to throw in that I kind of, I feel like is in this realm is like the idea of reusability.
You can write code so that it's easily reusable or that it's not so much.
So like I could write a function, but maybe I have a bunch of global variables that I'm still using and it makes the function like it moves the code away.
So I understand that it's like it's more compact and more readable, but it doesn't necessarily make it reusable.
So thinking about like how do I parameterize these things and make them something that I can use in other situations or once you solve this problem in this way, like I never have to think about this again.
I just now use this in the other part and that was rough, but that was Friday and I don't have to think about it ever again.
Like that's a pretty good principle, I think, here as well.
Yeah.
And even when you're writing your functions, you can write your function for your use case now.
And, you know, for example, it's like a function that is a regular expression parser for like a US telephone number, which is, if you try to write one of those, it's like way more complicated than ever it needs to be.
But it's like final exam in like regular expression 101 or something.
Like it's really like way worse than it should be.
Yeah.
You'll write your function with that in.
And like one of the things I end up doing is even if I have hard coded things within the function and then I realize later on like, oh, wait, I pretty much need to run that function again.
But instead of like the second index, I need like the fourth index or whatever.
You can make backwards compatible functions or code by like saying like, oh, I'm just going to create a default parameter in my function.
It's going to default to the one that already works.
But then now I can just reuse that function later on and like just change that value.
Simple things like that, that you don't have to rewrite the function just for your second use case.
I like, I talk about like, if you ever hit control C on your computer, you better be paying attention when and how many times you're hitting control V, right?
And if it's like more than three times, you're probably doing something wrong.
Yeah, for sure.
For sure.
One of the things I think would be nice, you talked about premature optimization and all these performance stuff.
What is your recommendation around like how you structure your code?
So a lot of times I imagine that the data science stuff has pretty much like there's a Jupyter notebook and most of the code, like the supporting functions are kind of the beginning.
And then later on, like they're kind of using them and so on.
When do you tell folks to break out like separate Python modules that you could load into your notebooks?
And like, what's the, how do you think about like different module files versus notebooks and things like you can apply refactoring tools really easily to a bunch of files using PyCharm or things like VS Code, not so easily in Jupyter, right?
So where's the balance there?
Yeah, so the thing with Jupyter notebooks is, yes, there was like a talk at JupyterCon about why Jupyter notebooks are bad.
And I have this love hate relationship with Jupyter notebooks.
But one of the things I can say, so Rachel Tappman from Kaggle, she gave like an Our Ladies Meetup talk in 2018 about like putting together a data science portfolio.
And one of the things in there is like the Jupyter notebook is great, but most of the time you probably are just interested in like the figures or tables that's being generated, especially if you're taking this into a meeting, right?
Like no one wants to like scroll forever to get to the bottom of the notebook because the first like three quarters is cleaning code.
Right.
I sort of like got into this sort of workflow of like I'll use the Jupyter notebook to like test things out in like data cleaning pipeline.
But the actual data cleaning stuff all go into like Python scripts.
So like what ends up at the end of the day, what happens in the Jupyter notebook is like pretty much load the libraries I want, load the data I want.
Maybe there's like a few functions that's specific to like the figures I need and then just the figures and tables I need.
So my Jupyter notebooks are pretty small and that down the line in terms of like other software engineering practices that just makes the diffs in through Git just way more manageable if I start making changes.
So if you end up with massive Jupyter notebooks that are a lot of it is just data cleaning code, you would think about like moving that out to other notebooks or other files just so you have more files.
I'm in the camp of pretty much in a lot of academic or scientific use cases, maybe not in like physics when they're working with like sensor data, but file IO is not that big of a bottleneck.
So like I will have more scripts and more files that just write out data just to have another script and file read it back in.
But that just breaks up my thought processes into smaller manageable pieces.
That's interesting.
It's like a little bit of a cache as well, right?
Like you can take the step N and go to N plus one and like iterate on how that happens without rerunning all the stuff, right?
Because you just reload that file that you save.
Yeah, yeah, exactly.
So like this goes down into like project template world where like I'll have a data folder in our data folder, you know, we'll have like an original data folder.
That is the data that we download stuff in, never make changes to your raw data.
And then everything else gets modified with a script.
I'll have like, for example, a script that reads in one of my original data sets.
I'll do my first set of processing.
Like maybe it's like, oh, fixing missing values.
And then I'll immediately write it out to somewhere in like under data and processing because it's now a process data set.
And I want to distinguish between data sets.
I can, I should just pretty much lock as read only versus things that I could like potentially modify and delete later on.
I'll have a whole series of these scripts that pretty much just like you'll see it.
I rarely these days have scripts that are like more than a hundred lines long because it's pretty much read in, do this one task, write it out.
And especially if you have like one step that just takes a really long time.
Yeah, it serves as pretty much as a cache where you just save out your temporary results and then you can deal with it later without like accidentally rerunning the part of your code that you didn't mean to run because now you're stuck for an hour.
And that's sort of like what happens with Jupyter Notebooks as well.
When we first started programming, like when I first started programming, it was just like, I just need this stuff to run.
So I'll run cell one and then jump to cell 10 and I'll run cell one again and then jump to cell 15.
And then I can like scroll all the way down and get my plot.
Right.
And then it's like, how am I supposed to run?
How do you document something like that?
Right.
And that's sort of one of the drawbacks with the Jupyter Notebook is, yeah, the execution order isn't guaranteed in what was written.
It's a little bit like a go-to.
Yeah.
It's pretty much like a go-to.
Yeah.
Which is kind of bad.
Except it's not even like documented, right?
Yeah.
At least it doesn't even say go to 20.
It's just like they went to 20.
Yeah.
And then when you execute it, it turns to 21, right?
So like it doesn't even, like you don't even know what 20 is, right?
So if you end up in a situation where you're running bits and pieces of a code all over the place, that's a sign of like, wait, let's fix this now.
It's pretty cheap to create a new file.
And let's do all the data cleaning or the parts I need for this figure.
Maybe that can just be in one thing.
And then more and more as you find pieces that need to be reused, you'll, oh, maybe I can turn this into a function.
Then you'll put that as a module.
And I would say like even if it's a module, just leave it in.
If the folder structure is pretty much you have a data folder and an analysis folder and an output folder where output is like your figures and stuff.
At first, it's okay.
You can have your modules in your analysis folder.
And so you can still say import something and it'll still import properly in that sense.
You don't have to like just go and make a Python package right away because at least in what I've seen is sometimes your analysis, it's not really going to be reused across projects.
You don't need the overhead of writing a Python package.
It's when you, for example, if you're querying, if you're doing some study on like code in GitHub, for example, and you write your own GitHub querying API call stuff, and then you realize this is part of one giant grant with many different analyses that need to happen.
Maybe like your GitHub querying code will turn into a package because you're actually reusing it.
You don't have to turn everything into a Python project.
You don't have to do that to do it like quote unquote correctly.
Yeah, and I feel like the value from going from like just some huge notebook or some huge script file and then moving that into modules that have functions you can import and run and whatever, that's like 85% of the way, right?
Whether or not you can pip install the thing, it doesn't matter.
You know, there's a lot of overhead to make something super reusable to make it documented.
Like maybe if you're in academics, maybe that's a cool project for like a senior undergraduate person.
Like, hey, you know what?
You know Python.
Why don't we take this and turn this into an open source project?
And that can be your project, right?
Like, I'm not sure it's a great research time and energy in general.
Yeah.
Well, so more and more, there's very recently PyOpenSci is an organization that sprung up and it's trying to mimic our OpenSci.
And it's essentially like supposed to be a repository of Python packages made towards making science better for some scientific use case.
And all of those are going to be reviewed by somebody and it fast tracks you for if you want to write a paper based off of that software package, it'll fast track you into Joss, which is a journal of open source software.
Yeah.
And I had them on the show as well.
Yeah.
So now you have at least like the incentives are more or less lined up, right?
Because before, like if you were just maintaining a software package, you know, what are your academic incentives?
Because a lot of that is still around publishing and grants.
So at least now there's the incentives are now lined up where like even though you are writing a software package, you can now write a paper about it.
Yeah.
It may generate a paper which might help you with your tenure and so on.
But I guess let me take a step back really quick on my statement.
Like it might not help you in your academic career directly to spend the software engineering time, but it may help you significantly in your research.
If you can publish something and then you get other researchers to start using it, right?
It becomes a package that you have more contributors to, right?
Maybe you have one student you could fund part time.
Now all of a sudden there's 20 institutions like all working.
Like that could be a huge benefit, but I think a lot of stuff is so specialized, so tied to your data and your particular problem.
Like you say, your first thought shouldn't be how do I open source this as a package?
It's like, how do I just like make this a decent software project?
Yeah.
And that's a pretty lofty first goal too.
Like how do I make this work properly for myself?
Right.
Because then that you go into the route of like, okay, I should write tests for this just to make sure it's like at least behaving correctly.
There's a bunch of incentives as well for just having an open source project and trying to get other people to play with it because you'll build out the functionality for the thing you built.
And as functionality expands, you'll sort of get more and more people in.
And it sort of ties back to like the Python community is great.
And so like now you are embracing the broader Python community and now you have more and more resources or people you've met to help you with your own project.
If you're at like PyCon or SciPy, you can have your own sprint for your software project just to have other people try this out.
You end up building your own community off of your little software project, which is, it makes you feel good.
And it's still also advancing science.
And a lot of science is also communication.
And you built this stuff to help other people.
So like you might as well try to make it easier for other people to help you as well.
Yeah.
It could definitely help your career as well.
I mean, people like Wes McKinney, Jake Vanderplass, Travis Oliphant, like folks like that, like they're legitimate big names in the whole Python space in general.
And a lot of that came from, you know, these academic projects and whatnot.
So that's pretty cool.
This portion of Talk Python to Me is brought to you by Rollbar.
Got a question for you.
Have you been outsourcing your bug discovery to your users?
Have you been making them send you bug reports?
You know, there's two problems with that.
You can't discover all the bugs this way.
And some users don't bother reporting bugs at all.
They just leave, sometimes forever.
The best software teams practice proactive error monitoring.
They detect all the errors in their production apps and services in real time and debug important errors in minutes or hours, sometimes before users even notice.
Teams from companies like Twilio, Instacart, and CircleCI use Rollbar to do this.
With Rollbar, you get a real-time feed of all the errors so you know exactly what's broken in production.
And Rollbar automatically collects all the relevant data and metadata you need to debug the errors so you don't have to sift through logs.
If you aren't using Rollbar yet, they have a special offer for you, and it's really awesome.
Sign up and install Rollbar at talkpython.fm/Rollbar, and Rollbar will send you a $100 gift card to use at the Open Collective, where you can donate to any of the 900-plus projects listed under the Open Source Collective or to the Women Who Code organization.
Get notified of errors in real time and make a difference in Open Source.
Visit talkpython.fm/Rollbar today.
Before we move off, I don't want to drop this idea of code smells because, first of all, I love this concept.
It's just such a good visualization of what can be wrong with software, but not broken with software.
Because a lot of times you think of, well, my code now works, but what should I do?
And I think the code smells is a very practical thing.
Just for folks listening, like, code smells, the idea is the code is working.
It's not broken, but when you look at it, you try to read it, like, your nose literally could kind of curl up.
You're like, ew, there's something wrong with this.
I guess it works, but I guess it's not good.
It's really not good, right?
Like a 300-line function, not good.
Like, it works, but there's something wrong.
And I knew this mostly from Martin Fowler's work back in 1999 when he wrote refactoring.
And this was sort of the introduction to, like, how do you know when to refactor?
Well, you look for the places that make your nose turn up.
You go, ew, what do we do with this, right?
Like, oh, there's a 300-line function.
That's bad.
What can we do about that?
Or here's a function taking 20 parameters.
That's really horrible.
You know, it's really easy to switch this integer for that integer.
And how do you know when that happens?
So what could you do to make that better?
And there's just a bunch of them.
But I only know this through the sort of software engineering side of things.
And this presentation that you talked about here, which was Jenny Bryan, right?
She has some really interesting tips from the data science perspective, right?
Yeah.
Yeah, so the first one is do not comment or uncomment sections of your code to alter behavior
because you want to try different stuff out.
Yeah, and that's, like, a very common thing, right?
Like, the easiest case where that happens is if you are in a collaboration environment,
you have five people.
You have five comments of data loading because everyone hardcoded, like, a data path, right?
And so, like, there's literally, like, you comment in your code just to, like, load the data set
across, like, depending on who you are, right?
And then, like, you end up, like, if you end up using, like, some kind of version control system,
like, the vast majority of your commits are just, like, it's my turn that ran it.
And you just have this one bit of these couple of lines that are just, like, committing.
Just cycling.
Just cycling back and forth.
Yeah, so, I mean, what is the fix, right?
The fix would be to do something where you have this proper structure, as you already talked about,
and then you use something like OS.path or pathlib, and you compute the relative path over to that,
and then you generate an absolute path.
That would work for everybody as long as they all check out the same general structure, which sounds like Git.
Yeah, and they dealt with this in the R world with these two packages called Rprojroot, like, for the root of an R project,
and here, here as in, like, find this file using here as, like, the root path or something.
And that's sort of, like, my contribution to all of this.
I tried to pretty much, I wrote a package called PyPrideRoot that tries to mimic, like, the same functionality as well,
because it works if you are working with scripts and stuff.
But the second you have, like, some kind of folder structure where you have a Jupyter notebook,
you'll sort of realize that, like, the Jupyter notebook doesn't care that you have a folder structure.
Like, the second you're in it, like, the working directory is now wherever the Jupyter notebook is,
not whatever folder structure you've, like, very carefully pieced together.
And so this was, like, an attempt.
It's not a very complicated function.
It literally takes, like, oh, what is your working directory?
And I'll recursively go up by its parent and checking for, like, special files like .git or a .here file.
And then I'll pre-pen that to whatever path, just so, like, you can now use relative paths in a Jupyter notebook,
just like you would in a script.
So you can avoid that problem as well, the commenting in and out.
Yeah, yeah, that's cool.
And I'll definitely link to that project that you built.
Tip two, use if and else in moderation, which seems pretty good.
Number three is pretty straightforward.
Use functions.
I mean, just do.
It's a good idea.
You should do this.
Yes, and, like, even when you're writing a function, it's okay to have a very complex function.
And even complex functions don't need to be written all in one go, right?
Like, you can break up your function, even though it does, like, a very complicated task.
There's probably small subtasks.
And your function can call other helper functions.
It's not just like, oh, this is a really complicated thing.
Let me just write a function for it.
As you're writing the function for it, like, that's one of the other code smells as well.
Like, if I have a hundred line function, like, that's kind of scary.
You couldn't break this down into smaller pieces?
Like, that's kind of weird.
And so, like, having helper functions that feed into, like, a larger function is also how you fix that code smell.
Yeah, absolutely.
And obviously, that makes testing way easier because you test little bits.
And then, you know, you test the kind of orchestration of them, and you're good.
Another one that I'm a huge fan of, it's like a serious pet peeve of mine,
is to have quick returns near the top or guarding clauses or guard clauses.
If you've got a function that's, like, indented, and then it's got a loop, and then it's got an if,
and then another if, and then another if, and it's just, like, way to the right.
If you're scrolling to the right, you're doing it wrong.
Yeah, yeah.
And during PyCon, I actually, like, just bought your entire encyclopedia of training.
And I forgot which one.
I think it was the how to write your Python code, like, an experience.
Pythonic code or something.
Yeah, yeah, that one, huh?
Yeah.
So, like, I remember that chapter.
Yeah, like, don't write nested if statements.
Like, essentially, write them inside out so, like, it's flat.
Yeah, exactly.
Do them backwards.
Yeah.
So, that was something that was just, like, that's what you should do.
It makes it so clear.
And, like, it's not very commonly taught, I don't believe.
So, these are called guarding clauses.
And the idea is instead of testing for a good condition and then another good condition and
another good condition and then doing the thing, which puts everything way on the inside, you
test for all the bad conditions first and you just bail out.
And then what you're left with is a non-indented simple bit of code, which is what you're actually
after.
So, it's really clear what you're testing against.
And then once you're past that, here's the simple thing we do.
I love it.
So, that was one of her tips as well.
It's a nice one.
Yeah.
She's got some great little examples there.
Some stuff on object orienting and so on.
But, yeah, these are really good.
I, you know, switch, which doesn't apply as much to Python.
I actually wrote a switch language extension for Python using the context management with
block.
That's pretty awesome.
But I'm not going to get into that because that's a whole different debate.
But I do think this idea of code smells is really interesting.
And you should think about them for data science because I'm sure there are different.
It sounds like, it looks like there are different data standout smells that are more common
than, say, standard software engineering.
If you're doing database programming or whatever, you get like a different style there.
Yeah.
And just for like other programming related things and how you can like structure your projects,
Jenny Bryan also has this talk about like, how do you name your files?
It's kind of interesting because like I, if you think about these common problems long enough,
everyone pretty much just converges to like the same set of solutions.
I remember like coming up with, yeah, I should just name things this way or like set up my
folder this way.
And then like all of a sudden, Jenny Bryan like gives a talk at like,
big R conference.
Like, wait, that was like, I feel validated that like I didn't come up with something like
nonsensical.
Other people as well, like they write packages sort of like a cookie cutter, just like set
up projects.
And it's pretty much like the same way.
And one of them is like, oh, how do you name your files?
Right.
Like, and especially in analytics, there's clearly an order you should run this stuff
in.
So one of the ways of like, how do you name your files is pre-pen a number to them.
Right.
So like you can say like one dash and then like the script and that's the order you write
it in.
If you want to do better, you say zero one.
So like 10 and one doesn't get sorted in properly.
Yeah.
And then if you really want to go one step further, I started this habit of like having
a three digit number.
So like zero one zero, and that gives you a buffer room to like insert something in
the middle.
Or if you like forget something or like you realize that.
That's like the 10, 20, 30 in basic.
Yeah.
Like, what if you got to put a line in between that?
You got to go to 30 still.
Well, you could do 19.
Yeah.
Whatever.
Yeah.
And I found that out because like, that's how sort of some of the files in Linux in the
order of like how it loads up like services or something.
It's like defined in like those three digit numbers.
And I was like, oh, this is interesting.
I should do that.
It just saves me from like renumbering like a whole bunch of stuff.
Yeah.
That's cool.
I mean, just thinking about the structure is quite interesting.
At the end of the day, even though you have all this structure for your analytics project,
because everything is like nice and in some kind of order, if you do, for example, want
to create a Python package, like it's already there for you, right?
Like you can create another folder.
That's the name of your module.
Put a setup that PY file.
You could have the ability to set that up.
And now you can like pip install dash E.
And then anytime you edit that file, like your analysis will still work.
And that's pretty cool.
The other thing with project structure related stuff, like if you have things numbered at
the end of the day, everything comes down to like a DAG compute system.
And so like, because you have your stuff in order and there's properly defined inputs and
outputs, you can use like a make file or like a simple script as like a poor man's make file.
But then you end up in like the situation like, oh, that's where Luigi and Airflow come into
play.
They're pretty much just DAG executors.
Like I said, at the very beginning, setting up your project is pretty much like the gateway
drug into like all of this other cool technology.
Cause like you've, you would have set everything up in such a way that you then use those tools
when you hit that point where you need it.
And it's like a nice way to like slowly improve, do self-improvement stuff.
And then you also like end up using all the cool stuff that you see at like these big conferences
as well.
Yeah, that's, that's really cool.
And of course the structure gets you just that much closer to trying it out.
Now, what do you think about Papermill and some of these concepts?
Are you familiar with Papermill?
Yeah.
Papermill is, I think that's the Netflix.
Yes.
It lets you basically turn a Jupyter notebook into something that can receive inputs and then
have outputs almost like a function or a module or something like that.
So I personally haven't used it.
That's mainly because when I was started working, like Papermill wasn't really a thing at the
point.
So like I had migrated out into like, let's just make everything a Python script because
that has no dependency and we can just execute things that way.
And then the notebook itself just becomes like, Hey, this is the report.
In some sense, I can see if I, for me, I guess like the next time I start an analysis project,
like I probably will use Papermill just because it's like, Oh, it's this cool technology.
And I've like set up my folder structures in such a way where like I can now use it.
Right.
So I've heard of it, but I personally haven't used it yet.
Yeah.
I haven't used it either, but it sounds pretty interesting.
Like it sounds like Netflix, like you said, is doing really interesting stuff to me.
One of the things that sounded special, it made me go, okay, well maybe that is worth considering,
even though it's like not necessarily my style, right?
is if you have a big, long sort of pipeline of operations and each one is its own Jupyter
notebook.
If it fails, you can save, you basically keep the notebook as it was computed laying around.
So you can just open it up and you have basically a history of what happened and then what failed,
which sounds like a pretty interesting way.
Cause if you switch it to scripts, which I'm all for, but you end up with, you know,
it exited without, with like not code zero.
Oh, that's bad.
Right.
Like, what does that mean?
Like, I forgot, I don't even have logging or any of these things, right?
Like what happened?
Like, why did it not work?
So I, I do think there's some interesting stuff happening around there, but I do also
feel like the software engineering tools you have apply really well to modules, right?
Like it's easy to run that through pytest.
It's easy to run that through a profiler, the refactoring tools work on those.
Not that you can't do some of that stuff with notebooks, but it's easier to use them on files.
Yeah.
And especially if you're checking things into version control, that's sort of like the one
thing.
My main gripe with the notebooks is like, every time I make a change, like I have no
idea what's going on in diff and it's just like, yeah, just add and commit.
Like, I think it's right.
Let's see.
Do you accept their changes or your changes?
Uh, my changes.
Or like, or like if I just want to open the notebook.
So there's this program called enter act, which at least is like a, a desktop version.
So I don't have to like open up fire a server and then open a notebook.
That way.
But yeah, like sometimes like, I just want to double click this thing just to see it.
I don't like want to open up a terminal and like launch everything just to see something.
So it was like little things like that, where I was like, I'll try to do as much as I can
in a script.
And then like everything else goes into a notebook.
And then in the notebook, I still save out the things I want just so like I have an easier
way to like access figures or tables without having to like look at the entire notebook.
Yeah.
I guess that is one of the challenges is the whole diff thing.
Maybe we could talk.
We're kind of getting long on time, but there's a lot of interesting stuff to cover.
So I'll ask you a few more questions.
Let's think a little bit about collaboration.
Like you talked about the anti-pattern of having like Sarah's path, Dan's path, Michael's path,
whatever, like, and just commenting them out which one is active at the moment.
But there's probably some other stuff for collaboration, like are you using Git?
Are you using some online shared notebook that's kind of like Google Docs?
Like what are your thoughts around that kind of stuff?
So Google has something called like the Co-Laboratory Notebook, which is essentially like Google Docs,
but gives you a Jupyter Notebook system.
That's pretty cool in the sense that like, yeah, we won't have this commenting out of like random
lines because everyone's really just working on the same place.
Like that's really nice for collaboration.
I still think that you need some form of version control.
Like that is, I think like at this day and age, like it's pretty much required, especially
when programs start to get more and more complex.
Like you need a way to fall back on.
The nicest feature I use in Git is like I write something, everything is broken and I just say
Git reset and I just pretend I never did that and I just start over.
Yes, exactly.
Like that was a really bad idea.
Please revert that.
Okay.
Now we're good.
And it lets you be more exploratory.
It lets you be more aggressive and trying to change it.
Like this might not work, but if it works, it's going to be awesome.
And try it.
Actually, that didn't work.
Revert.
Or, you know, maybe it's a little more forethought.
You create a feature branch to explore it.
You do it there.
And they're like, forget that.
That was a bad branch.
We're just going back here.
Like, let's not do that.
Right.
Yeah.
But it's a really great feature.
Yeah.
And like, just along the lines of like collaboration stuff, like make small incremental changes.
And that's like the actual stuff.
That's the code that will actually get reviewed.
Right.
Like no one will review a code base where you're like at the end of the paper, the entire like submission relies on this code base.
And you're like, I need someone to review this thing.
Right.
Like there's no way that's going to get a proper review.
And so just in general for like, doesn't even have to be in like research or science.
It's a good habit to like make small incremental changes.
And like, maybe that's what your weekly meeting is about.
It's just like, this is what I did this week.
Someone press the green button to merge this in because that will actually be reviewed.
And then you'll have a discussion around that point.
Like all of that stuff.
For me, I personally, I'm not in a managerial position.
So like, those are the types of meetings I find like productive where I can actually talk about.
This is why I did.
This was the implementation.
This is what I'm thinking about next.
And then have a conversation around that because it can still be productive and you can still have like talks about longer goals.
But like you also now have the benefit of like someone else looking at your work to make sure it doesn't have like a bad code smell.
You know, maybe like you, you, you're off by like a factor of 10 and no one's going to notice that in like 900 lines of code.
But they will if it's just like 20 lines of code, like a change like that is much easier to find.
Yeah, that's definitely good advice.
I definitely recommend working in small little, little bits and changes and, you know, make some small change.
Do a git commit.
Make another small change.
A little git commit, right?
Like don't wait until the end of the week or like until the end of the paper and like, all right, time to check it in.
Like, no, not a good idea.
One of the things I wish like exists more in academia is just having more resources to do pair programming.
Because usually people are assigned one project and there isn't like two people assigned to the exact same bit, which is what you really need pair programming for.
When I was co-instructing like the summer program in my previous lab, I would sit down next to students and I would pair program them through some kind of data related work.
And it's super valuable for them because they actually get to see how I'm thinking about like this problem.
And I'll say like, you're doing a join of two tables.
Yeah, make sure that like the keys don't have duplicates if you're expecting duplicates, right?
That's like one of those things of like, yeah, the code ran, so I'm just going to keep going, right?
And you don't realize that you just did, you just did a Cartesian product and now you have a million rows and you don't know why, but you're just going to keep going.
Why is it taking so long?
Yeah.
So pair programming, yeah, it's super valuable.
And even now during my internship, it's I'm on the receiving end of pair programming, but this is more on the software engineering side.
It's super valuable just to see like, oh yeah, this is how you write good code or like, this is how they're thinking about it.
And it's even stuff like I talk about, yeah, be careful where you're hitting like control V a bunch of times.
And it's like, oh yeah, like this is in two different places.
Like, let's just refactor this out.
And it's like, oh yeah, I didn't catch that.
And like, when you refactor it out, you can actually have more guarding clauses just to make this like an even better check.
That's one of the things I wish, like at least in research, like there was more budget and time for is just pair programming.
And that just makes collaboration easier because you're now just talking with a person back and forth.
It just makes that whole process like way nicer and smoother.
Yeah.
I mean, we certainly have the tools these days for it, right?
You talked about Google Collaboratory, which has like live multiple editor features, kind of like Google Docs.
You've got obviously screen sharing, you've got like VS Codes, ways to like watch somebody else's system on two sets of Visual Studio code.
And there's some really interesting options.
But yeah, it's got to, it's like also a cultural thing.
And also you've got to have people to collaborate with on that part, right?
Right.
And in the sense of, hey, maybe like when you, even though you're in this small world and you write your package, like now you have someone to collaborate with, right?
And that's sort of like socially motivating that you have other people using your stuff.
Yeah.
It definitely feels good to have someone looking at it, interacting with what you're building because building software completely in isolation just for yourself.
It's kind of a weird place to be.
It's not as much fun as it could be.
Yeah.
It's fun.
Like when you're just in the sense of like, I got to get something like that minimum viable product, like that's fun.
And then it's just like, as soon as you hit maintenance mode, it's like, who am I maintaining this for?
Yeah.
Or just all like a lot of the projects, you know, you're going to be working on it and you kind of get the happy path, mostly working and you feel like you're mostly done.
But then there's all these little loose ends, the documentation you got to write for the other people involved, all the little tests and the edge cases.
And just, it can just go on and on and on.
It feels like, I thought I was done a month ago with this and I'm still working on it.
How is this not still not done yet?
Like I've definitely had that feeling in software and I'm sure it's just the same, you know, that was actually in a semi-research context.
I'm thinking back to it.
Yeah.
Final thought on this collaboration bit.
What do you think about GitHub?
Like creating either a private or a public repo, using that for your work to share with people?
I love it right now.
Like pretty much if I have a thought, I just make a GitHub repo.
So like my personal GitHub account has a bunch of projects where like they're pretty much empty, but they have a name.
And it's just because like I thought of something one day and I just made a repo out of it.
It's even really good for simple stuff.
Like if you're at a conference and you just want a place to take notes, that doesn't matter what machine you're on.
I've taken just notes and markdown as a GitHub repository.
And then like during like a lightning talk, just be like, hey, I just started putting up my notes.
And then maybe some people will like add, hey, wait, this is my talk.
Let me put my talk in there.
And you end up collaborating on like some kind of notes for like a conference, which is pretty cool.
And for me, like I try to in lines of that 10% improvement, like every time, like originally, like I just made everything in Git just because I needed more practice with it.
And it was just like a nice safe place for me to like, oh yeah, like add and commit.
Like if you do it a couple of hundred times, that part doesn't become scary anymore.
And so that's right.
It just becomes so natural.
Like, oh yeah, when I first learned Git, it's like, why am I doing this?
This is so tedious.
And then it's like, now it's like, okay, whatever.
But then like you can do other stuff with Git, which is like super cool.
So GitHub is like a great way to practice using Git and then also gives you the ability to practice or get ready for collaboration.
Right.
So even for me, even if I'm working on personal projects, sometimes like I will do branches for myself, push branches to GitHub by myself, and I will submit pull requests to myself.
Just to document it and make it really clear.
Like this is the reason for it here.
The files that changed and all that.
Right.
And like, I was doing that for a couple of years.
And like now, like during my internship, like that has become so second nature that like I can actually do Git things and it doesn't hinder collaborating in like the real world.
Yeah.
So it was a lot of like just practice that like, I just thought it was cool.
Like, I didn't realize until now that was like, wait, like this is actually just like years of practicing on my own.
And so like, in that sense, like, and like Microsoft essentially saved GitHub and like, it's just as good as ever.
So like, yeah, plus plus one for GitHub all the way.
Yeah.
Awesome.
I totally agree.
Okay.
This is really interesting.
I think there's a lot of concrete advice here.
I'll link to the papers.
I'll link to your PyRoot project.
The code smells thing, all that.
We'll put all this up there and people can come back and definitely dig into the details if that's useful for them.
So before we get to the final bit of the show, though, I've got to ask you the two questions, Dan.
First of all, if you're going to write some Python code, what editor do you use?
So I used to use Emacs with LPy and now I am now a VS Code convert.
They've brought you over.
You know, I would say like the last four shows that I've had, everyone has said VS Code, which is pretty interesting.
Yeah.
I was pretty reluctant until like I had to write some Python code and I was on, I switched over to my Windows machine and I was like, I don't have any way to edit code right now.
Let's just try this thing.
And, you know, it worked.
And so like I was pretty happy with it.
So I sort of just hung around.
What's actually really cool is the screen sharing ability in VS Code that does pair programming.
Yes.
That live, I think it's called Live Share.
I've never had a good chance to use it, but I've seen it and it looks amazing.
Yeah, I've used it with one of the other interns and it's like, this is really cool.
And they also have like a voice communication mechanism.
So like yet another way to like do voice chat, but at least the screen, like the live coding part, like that was super cool.
Very nice.
Yeah.
Okay, great.
Definitely a good answer for the editor.
Packages, some notable ones.
The package that notable that I haven't heard on the show yet is one called Pie Janitor by Eric Ma.
And he works at Novartis.
And this is pretty much his consolidation of pretty common data cleaning stuff in pandas.
And that ties to another package by Zachary Saylor called Pandas Flavor, which is a wrapper around your ability to extend pandas.
And the benefit of that is, you know, if you want pandas to have a method that you don't already have, like you might think like, oh, let me create another class.
I'll inherit pandas and I'll release a package.
But no one's really going to use that because it's not a pandas data frame object.
It's like some weird class that you created yourself.
And so like this is sort of like a mechanism for you to inject your own methods into a pandas data frame object, but still have a pandas data frame object without having to re-extend the class.
So it's super cool.
Yeah, that's really great.
And yeah, the Pie Janitor, I really like that one.
It takes a whole bunch of imperative data frame operations and turns it into a really nice fluent API like data frame dot from dictionary dot remove columns dot drop not a number drop, you know, rename call and just boom, just flows it all together.
It's really nice.
I haven't covered on the show, but we did talk about it over on Python bytes that podcast.
So, yeah, it's definitely a cool one.
It's been on my radar as well.
Nice.
All right.
Well, final call to action.
People who are out there, maybe they're in science, data science.
It's something like that.
And they want to make their code take, you know, that 10% step you're talking about towards the more proper engineering structured world.
What do they do?
For me, like I was lucky enough to be in New York City, which is a big city.
So it was always like local meetups were always like a thing that were very busy and you learn a lot from there.
But even if you don't live in a very big city, you can either start one yourself because chances are you are not alone.
And the Python community is super supportive.
You can always if you say something on Twitter, someone will give you the ways of how to start something.
And if you're at a university, you can always have meetings in like a classroom or something.
So don't worry.
Right.
Maybe it has an interdisciplinary, right?
Like maybe there's not that many people in your department.
But if you go across, you could probably find a decent number of folks you want to attend.
Yeah.
And so meetups are a great way to like learn or meet other people or at least just like ask questions about stuff.
And if you can make it to like any of the Python conferences or like attend a sprint like that is probably like going to a sprint was like the fastest way that I've became a better Python programmer.
Or even if it was something as like editing a piece of documentation, like just seeing the mechanism of how other people collaborate on such a large scale and then still seeing your work like in one of these major projects like that's super motivating and like cool.
Yeah, that's really cool.
Yeah, it's a great opportunity.
And it's also a great opportunity to, you know, rub shoulders with really prominent people in something that you're working with, right?
The maintainers of this probably important project who are there and, you know, what better chance to get to know them a little bit than to sit down and like add a feature with them or spend a day in the room with them.
Something like that, right?
That really can build some connections that, you know, especially if you're in a small town somewhere and not meeting them in person, that could be a challenge.
Yeah, and a lot of people stay within Python because of the community.
So like, I guess my final call to action comes from Greg Wilson in his book called Teaching Tech Together.
He talks about the rules of teaching how to program or like building community.
And the first rule is be kind, all else is details.
Yeah, that's great.
Be kind to all else's details.
I agree.
It's definitely right up there is one of the most important ones.
All right, Dan, thank you for being on the show.
It's been really great to talk about these ideas with you.
I think there's a lot of good advice people can take away.
Yeah, it's been great talking with you, Michael, as well.
You bet.
Bye.
This has been another episode of Talk Python to Me.
Our guest on this episode was Daniel Chen and has been brought to you by Indeed and Rollbar.
With Indeed Prime, one application puts you in front of hundreds of companies like PayPal and VRBO in over 90 cities.
Get started at talkpython.fm/Indeed.
Rollbar takes the pain out of errors.
They give you the context and insight you need to quickly locate and fix errors that might have gone unnoticed until users complain, of course.
Track a ridiculous number of errors for free as Talk Python to Me listeners at talkpython.fm/rollbar.
Want to level up your Python?
If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
Or if you're looking for something more advanced, check out our new async course that digs into all the different types of async programming you can do in Python.
And of course, if you're interested in more than one of these, be sure to check out our Everything Bundle.
It's like a subscription that never expires.
Be sure to subscribe to the show.
Open your favorite podcatcher and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I'll see you next time.
Bye.