Howdy! I'm Al Sweigart. I was a software developer who wrote Python tutorials in my spare time, and eventually they ballooned in size so I started self-publishing them. In 2014 I quit my job to finish writing Automate the Boring Stuff with Python, published by No Starch Press. All of my books are released under Creative Commons licenses and are free to read on my website at http://inventwithpython.com/.

My latest book is Cracking Codes with Python a book on learning to code so you can write encryption programs for classic ciphers, as well as programs that can break these ciphers. It's the second edition of my previously-titled, self-published Hacking Secret Ciphers with Python, but published by No Starch Press with a professional editing job.

My other books include:

I'm working on a couple upcoming programming books, one which is a sequel to Automate and another covering recursion. I also create online courses on Udemy.

EDIT: Oh, I forgot to list Automate the Minecraft Stuff, which is a book that teaches kids to code using the programmable robots of the ComputerCraft plugin for Minecraft. This book uses Lua rather than Python. It should be out around April or so.

I've lived in San Francisco for the last decade, but grew up in Houston and went to UT Austin for computer science. I hate telling people the story of how I learned to program, but ask me about it anyway.

Ask Me Anything about writing tech books, learning to program, teaching others how to code, my cat Zophie, making online courses, why coding interviews are terrible, attending tech conferences (like PyCon!), getting started contributing to open source projects, using video games to lure children into the dark, seedy, world of programming, or whatever else you'd like to know!

EDIT (4:30pm Pacific) I've got to start moving, but I'll still be answering questions from my phone, though they'll probably be shorter responses.

Proof: https://twitter.com/AlSweigart/status/956641980670394368

EDIT: Okay, I'm signing off! Thanks for all your questions, and you can always email me at [email protected] or if you have a coding question post to /r/inventwithpython

Comments: 84 • Responses: 31  • Date: 

jairo416 karma

Hey Al, Automate the Boring Stuff is a great book and I'm very excited about the sequel. Any tentative date?

PS: Al, you are awesome!

AlSweigart23 karma

Probably sometime in early 2019. I wish I had started earlier on it, but I wasn't quite sure what should go into a sequel. I knew I wanted to create an intermediate level book, given that there's tons of content out there for complete beginners and experienced developers, but it's hard to pin down what "intermediate" is.

Fluent Python and Effective Python are great books for mastering the Python language, and Clean Code is a great book on good software development practices in general. I didn't want to create a poor imitation of those books, but I did want similar aspects to them.

Currently, the idea is that the reader is someone who knows basic programming concepts and syntax (not even necessarily Python) and has written some one-off scripts, but wants to put together complete applications for their niche needs.

I'm making a risky, experimental approach where I use the browser for the applications' GUI. GUI frameworks like Qt and wxWidgets are great, but I didn't want to get married to a particular framework. Then I thought, a lot of people know HTML & CSS, or at least those would be generally useful skills if the book taught them. So I'd use Flask to create "offline web apps", which are really just applications that use the browser & HTML for the user interface. These would be applications meant to run on localhost and not accessible by the internet. It's cross-platform, easy to expand upon later if they do want to learn more.

I kind of feel a sort of George RR Martin-syndrome where I want to write as fast as possible to get this book out as soon as possible, but it's looking like it'll be a lot of work that will take up my entire 2018 for the writing and editing. No Starch is really good about not rushing their writers, in my experience, and producing quality books because of it.

soniclettuce2 karma

Heh, I saw this thread and was going to ask if you had any recommendations for beyond-beginner but not really expert level devs. Guess the answer is "wait for my book" :P

AlSweigart4 karma

Heh, I also think Effective Python, Clean Code, and Python Cookbook are good next steps, and they aren't long books either.

keizerzilla10 karma

Hi Al. First I'd like to thank you for your books. I took your Udemy course and it was great.

I am from Brazil and education is not a priority right here. I want to help people get comfortable with science and programming, especially kids. I have a little bit of experience teaching to undergrad students while in college, but they already had a good basis of knowledge.

How do you approach teaching people with little experience/knowledge? Do you have some sort of flow you take in order to build confidence in the learning process?

Thank you so much!

AlSweigart9 karma

My teaching experience has been limited to a Saturday morning Scratch programming class I did for a few years at Oakland, CA's video game museum, The MADE. These were one-off classes (since we didn't know if students would return the next Saturday or how long they'd stick with it) so we concentrated on making small projects with Scratch.

These were 9 to 13 year olds, and our aim wasn't to teach them programming concepts per se, but make them think that programming was 1) cool and 2) something they were capable of.

I'd focus on small projects, and video games are a common gateway to programming as well. It's kind of tricky to do with Python, because "video game" makes kids think of 3D games like CoD or Minecraft, or at least colorful mobile games, and you won't make anything like that in a single 90 minute class.

But focus on small, accomplish-able results. Also, the lecture format is terrible for guiding a class through a programming project since you can only go as fast as the slowest student. I experimented with creating tutorials that were a series of animated GIFs, and this worked better than videos (which are a pain to constantly rewind) and lectures. This way teachers could float around and help kids at whatever point they were at, and kids could go at their own pace.

Oh yeah, and it will ALWAYS take longer than you think to explain and make students understand concepts. We easily forget how unnatural programming is to complete beginners.

markcoscos7 karma

Hi Al, I have read and learn a lot from the automate the boring stuff with python book :)

My question is: what would you say is the next step for someone trying to learn to program ?

AlSweigart19 karma

The common answer for this is "work on programming projects" which... is true but kind of unhelpful. Maybe you have ideas for putting together a project, but if you don't you're back to wondering what to do.

I wrote a blog post about simple video games you could clone, but if you aren't into making games, you could google for "programming project ideas".

The most important thing to keep in mind is keep the project simple. It's better to have one completed small project than half a dozen large but never finished projects. I usually make a list of features I want the project to have, but also a list of features the project won't have. This prevents feature creep and "hey, it'd be cool if the program did..."

Practice programming problems are good too. I'd recommend /r/dailyprogrammer and http://exercism.io/. Project Euler is recommended a lot, but the problems tend to be very mathy (which is fine if you're into it.)

hello_there2476 karma

Hi Al, thanks for taking the time to do this. I have a pretty basic question.

I have no knowledge in coding, at all. For someone like me who could devote say 10hrs a week to learning - how long do you think it could take someone who is a rather quick learner to learn a more basic coding language?

Thanks!

AlSweigart8 karma

I think you'd be able to start solving basic practice programming problems with in a few weeks or a couple of months at that rate. It'd still be at least a year or so to get to the point of getting a junior position as a software developer though. Also, remember that the ten-thousand hours is kind of a myth: it's not so much practice but choosing to practice difficult things instead of the same familiar thing over and over.

I kind of compare it to becoming fluent in a foreign language or learning a musical instrument: It'd probably only take a few months to carry on a basic conversation or not be bad enough to busk at a subway station. But you won't get hired as a translator or create a hit album any time soon.

Developer boot camps usually soak up your entire life to get job ready in about 14 or 16 weeks, which doesn't really work if you need to continue working or you have kids to raise. Even then, you're still green and might have some difficulty getting hired. But you'd definitely be on the right track.

As the Chinese proverb goes, "The best time to plant a tree is 20 years ago. The second best time is today."

roopsta5 karma

Hi Al, how good is your touch typing? I've been trying to learn to touch type alongside learning to code so I don't end up looking at the keyboard and instead be looking at the code only.

Much like coding, getting the basics down is pretty easy but getting proficient is taking me ages (in both).

No way can i keep up with you on Udemy. Are you hitting all the right numbers and special characters with the right fingers? Does it help?

AlSweigart10 karma

On a good day I can hit 90 or 100 wpm, and while I'd definitely learn to type (including practicing with typing software) I remember a post recently where someone claimed that bad typers can't be good programmers, which I completely disagree with.

I sometimes look down at the keyboard but mostly don't.

Typing is really the least important part of programming, though it helps to be able to output your coding ideas at the same rate you have them.

AlSweigart6 karma

I hadn't seen that post before.

This wouldn't be the first time Jeff Atwood is totally wrong about something. :)

raithlok5 karma

Al,

Thank you for all you do. I bought, read & went through "automate the boring stuff" and still refer to it at least 5 times a week at my job, which has nothing to do with programming, but it helps me immensely. I saw your post this week regarding ciphers & I'm working through it as well, already on chapter 7 of Cracking Codes.

Aside from what you've outlined in ATBS, what other concepts and good practices should coders be working on?

AlSweigart10 karma

Learning source control is great idea, and getting a github.com account will get you to practice committing changes (and writing good commit messages) as well as putting your code out there for the public. A lot of people worry because they don't want others to see their terrible code, but this isn't really a big deal. For one, nobody is going to read your code. I put a "if you are reading this, put the word 'walrus' in the subject line of your email" and all but a couple cold emails I get from recruiters fail to do this. So I know they aren't actually looking at my github account.

The book Clean Code has a lot of useful tips for good software engineering practices and is a short book, and Code Complete has good engineering practice and is a very very long book.

These sorts of "programming best practices" (which is a good set of terms to google) is something that I'm planning on putting into the Automate the Boring Stuff sequel.

DynamicMetaFlow5 karma

Hi Al, I'm a high school technology teacher in the Boston area and a CS graduate student at a local university. I teach CS in both Spanish and English to my students. I love No Starch and particularly your books.

One of my difficulties in teaching is to find interactive resources other than documentation for high school students and I have to manually create the content.

Any suggestions you have for creating content that is accessible and interactive to explain CS concepts for varying levels of language ability?

AlSweigart4 karma

Bret Victor has a great talk called Inventing on Principle about creating these kinds of interactive demos, but unfortunately I haven't been able to find a lot of actual demos that teachers could use. Nicky Case & Vi Hart's Parable of the Polygons is awesome, but again it's more of "the kind of stuff I'd like to see" than the actual stuff that teachers can use.

In 2015 I spent a month backpacking in Europe, and the main takeaway I had was "Whoa. Not everyone speaks English." And this is obvious but I never actually gave it much thought. I've started a project to get Python's turtle module's variable and function names into other languages (though it's been on the back burner while I work on other projects), but I feel like there's a better solution.

I've long had a dream of putting together a programming guide that was like an IKEA or Lego instruction manual, that taught programming while using a minimum amount of actual words. I still don't quite know how to go about doing this, but maybe in 2019 I'll have time to delve into it more. I can't find this one web comic that had no dialogue at all, but was about two strangers who discover a ghost city that suffered a Vesuvius-like eruption (it'd be great if someone knows what I'm talking about). They did a great job conveying a lot of meaning with no language.

RedditBeginAgain4 karma

Is writing tech books a viable 21st Century occupation, or is it that you enjoy spreading knowledge and are willing to do it for less than a developer salary?

AlSweigart5 karma

Honestly, I keep wondering about this. I've joked that at least books have a pretty good battery life.

There's a lot of great stuff you can do with interactive online examples (Nicky Case & Vi Hart's Parable of the Polygons is awesome., and having it online means students can show off their work to friends. (This is something I think is a killer feature for the Scratch 2.0 editor .)

I myself create online video courses, but even these I feel aren't maximizing the potential of the medium. It turns out automating what a human teacher does is really hard to do.

For now, at least, books still sell. I wouldn't encourage anyone to quit their job to write tech books (my experience has been a lot of luck), but I don't think it will go away entirely any time soon.

justscottaustin4 karma

Hi, Al.

How long did you, personally, curse when "print 'foo'" no longer worked in Py3?

AlSweigart9 karma

Heh, nah, that was easy to stop doing. I actually made the switch to Python 3 early on, and really encourage others to do the same. The "modules don't support Python 3" really hasn't been true for years at this point, so unless you're working with a large existing code base, there's no point in sticking with Python 2.

And Python 3 at this point has a lot of great features, but I've always maintained that having proper Unicode strings makes Python 3 worth it. Before then, it's really easy to write code that just falls apart if someone adds a letter with an accent mark in it. Ned Batchelder has an absolutely amazing and accessible talk on Unicode here: https://www.youtube.com/watch?v=sgHbC6udIqc

Itsthejoker4 karma

Hi, Al! I met you last year at PyCon; are you planning on being there again this year?

AlSweigart4 karma

Most definitely! Also, I'm giving one of the keynotes at PyCon Philippines in a month!

Phoenix_Trite4 karma

Hi Mr. Sweigart. I have tried over and over again to learn how to program, and every single time I lost interest. I like the idea of programming but I don't think I actually like the act of programming. I can't seem to find any projects that excite me, or hold my interest for very long. How can I find a way to enjoy programming and find and make, or contribute to, a project I will enjoy?

Also I have browsed r/learn programming and I am immediately hit with choice paralysis. I just want one or two books instead of a bazillion options. If I could only buy one book to learn how to program what should I buy?

Finally, I have learned that learning how to program is like learning how to scissor or how to glue. I want to develop this skill but I don't have anything I really want to make. How can I find a reason to want to program?

AlSweigart3 karma

I don't think this is necessarily a programming thing, but a general motivation thing. /r/motivation has great tips, but in general: Pomodoro technique for working on something, getting a "gym buddy" to learn coding with, etc.

But also, if you choose a programming project to work on, make sure it's small. It's better to finish a small project than have several half-complete ones.

yallrcunts3 karma

If you were going to learn programming from scratch, where would you start?

AlSweigart8 karma

:D

Have I got the book for you! :)

My most popular book is Automate the Boring Stuff with Python, at https://automatetheboringstuff.com

It's for complete beginners, and kind of "programming for office workers" and focused on practical tasks, rather than calculating Fibonacci numbers.

HybridRxN2 karma

Hi Al, as an aspiring programmer getting back into Python after having taken a class in college, your book has been extremely helpful in teaching popular libraries to get up to speed with what one can currently do with the language. In addition, I heard about the book, but it was really the course that has pushed me farther so I really want to thank you for making that! Although I am still learning, I have also come across javascript and have been impressed (maybe naively?) with the cross-platform nature of javascript i.e you can write a program to use the phones tilt sensors to put a ball in a hole or write really beautiful/elegant visualizations, something I have kind of envied because I don't really know how that is best implemented in python. Yet it's a bit confusing at this point how to break in given the rapidly changing landscape of javascript and the dependencies, so without saying a book like yours for javascript would be awesome. But doubt, that that's your focus, so do you know any similar style books to yours that can get a beginner who knows no javascript, or little html/css to building cool cross platform apps? Also, what are your thoughts about making cool tutorials with what I heard is a promising app builder: toga from pybeeware?

AlSweigart1 karma

Oh man, I love PyBeeware's projects, and Russ is a really great guy. I've been meaning to get more involved in their projects but I haven't had the time.

Unfortunately I don't really know of books like Automate for other languages, though it'd be nice if someone wrote some.

HybridRxN1 karma

Awesome! I highly recommend this video from Russ: https://m.youtube.com/watch?v=xezYYBL7nk0

He deploys a Fahrenheit to Celsius converter app made with pure python to six different platforms in 20 minutes!

AlSweigart1 karma

Nice!

coryrenton2 karma

Among paying customers have you noticed any weird trends (like an upsurge in people learning to program in order to make minecraft plugins etc...)?

AlSweigart4 karma

I really don't have access to that level of information about my readers (though it'd be a really good idea for me to collect that info, I should do that).

From my Udemy course on Automate the Boring Stuff, I can see that only about 8% of people (who both paid and got it for free) actually complete most or all of the course. Which, out of 95,000 people, still makes me feel giddy that I've probably helped over 10,000 people to learn to code between the course and my books.

This ability to scale is why I like writing books and distributing them for free on the internet. I'll probably go into corporate training for the steady paycheck when I run out of book and online course ideas, but I've been saying that for the last few years.

There's something about being able to scale like that that just... elates me. Like, I love writing code that does some huge task and watching it run, knowing that it would take me literally years to do it with pencil-and-paper or typing-and-clicking. Then I figured I could scale even more if instead of coding I taught other people to code.

I'm also interested in putting together some kind of curriculum package that could help teachers teach people to code. * INCEPTION SOUND BRRRRRRRAAAAAWWWWRWRRRMRMRMMRMRMMMMM *

(EDIT: Are Inception memes still cool?)

coryrenton1 karma

Which subjects do you find draw the most paid users vs the most free users?

AlSweigart2 karma

I'm not sure if it can be really broken down like that. Subjects are either appealing to people or not, in my experience.

I check Amazon's rankings for programming books on a regular basis. Python titles take up about half of all the top programming books, where all the other languages combined make up the other half. And there's also a lot of books for beginners and also data science/machine learning/web apps. So if you wanted to create your own content, those would probably be the best subjects to write/talk about.

I think this (along with being available online for free under a CC license) is what propelled a lot of the popularity of Automate the Boring Stuff with Python.

ultrasupergenius2 karma

Hi Al - really excited to see you here on an AMA. I bought "Automate the boring Stuff with Python" a while back, and it sat on my shelf until a few weeks ago. Going through the first few chapters has got me excited about development again. You have a great writing style - and the book is well balanced with a lot of examples and exercises to work through. I particularly enjoyed your style of illustrating double negatives in python with a plain English example of multiple tiers of negatives cancelling each other out. Great stuff.

I have been looking for a solution that will allow me to run python and idle on a mobile platform, so that I can take advantage of the 2.5 hour a day commute, much of which has no internet access. I find all the interpreters for iOS require an internet connection to work. Can you recommend an IDE for mobile platforms (phones or kindles) that would work for commuter code learners?

AlSweigart1 karma

Python Anywhere has a service that lets you enter Python code through the browser and then let's you see the results.

ben-tyl2 karma

What’s your favourite thing you’ve ever coded?

AlSweigart6 karma

Without a doubt, this: https://twitter.com/yhoboshavedogs

It's a twitter bot that scans twitter for people asking (basically), "Why do homeless people have dogs?" Because if you aren't homeless, it doesn't make sense: you can't afford to take care of yourself so why take on a pet? And so a lot of people think homeless people have dogs to get sympathy and money out of people.

The bot replies to them, "Homeless people have dogs because a dog will love you even if you're homeless."

p.s. Of course there are exceptions, but homeless people are great dog owners: they make sure their dogs are fed even before them, they're with the dogs constantly so they get attention and love and aren't left at home by themselves all day, and the dog and dog owner provide security for each other.

yoelopio2 karma

Can you please tell me which is the specific Creative Commons license for each of your books?

AlSweigart4 karma

I copy/pasted this from Automate the Boring Stuff:

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/

I have the Non-Commercial clause and encourage others to use it too. My main concern isn't people pirating the book to read it as much as other people taking the book and trying to sell boot leg copies. For one, this book should be free, and two, if it is sold I'd like to be the one getting the revenue from it. I remember the moral panics around Napster and bittorrent, but as a content creator that's the form of copyright infringement I'm most concerned about.

mrTang55442 karma

Can you do one for Android?

AlSweigart5 karma

Maybe in 2019. I took a look at Kotlin a few months ago and got excited about it's potential to unseat Java, particularly for Android development. Also, I like using video games to get kids into coding, and today that means mobile games more than BASIC-era text adventures.

I've been meaning to take a look at Kivy though, which uses Python to produce mobile and desktop apps.

mrTang55442 karma

I agree, the current "hello world" of android is usually creating some static page with an image background and some text. I feel like kids would get bored with that very soon

AlSweigart4 karma

And not just that, it takes like ten million steps and XML files to just get to that point. I can see why the toolchain is like that, but I keep thinking "There's gotta be a better way."

floridawhiteguy2 karma

How difficult was it to teach Zophie to code? ;-)

Seriously, IYO what's the worst part of coding interviews? I've always hated how some HR drone expects me to create a fully functional script to solve their critical business problem in 5 minutes on a whiteboard.

AlSweigart6 karma

She still struggles to type. And she thinks significant indentation is weird, but most beginners get over that pretty quickly.

VortexKirito1 karma

Hey, I’m a beginner, and for the life of me I can’t figure out how to actually run the code I’m making. I’m using a textbook called “Python Crash Course.” and it’s had me download the Sublime Text text editor. So, I download it, I download Python 3, and then the book tells me to configure Sublime Text for Python 3. It says go to “Tools > Build System > New Build System” and then enter this:

{ “cmd”: [“/usr/local/bin/Python3”, “-u”, “$file”], }

I entered it, and that’s great, but after that I can’t figure out how to make the editor run that code I entered. Do you have any advice on how I can get this code to run, or maybe just another way I can configure the text editor to Python 3?

Edit: also, sorry this isn’t really a question towards you in particular, I’m just having trouble starting to learn how to code since I can’t figure out how to get the editor to go into Python.

AlSweigart2 karma

I think this video is a good guide, and you'll also set up a Python REPL inside Sublime Text. https://www.youtube.com/watch?v=wM2LbXCkLDI

salvage_di_macaroni1 karma

Hi Al, What do you think will be the most used and important languages in 5 years? What should everyone know and in what depth?

Thanks

AlSweigart2 karma

I'm terrible at predicting the future. Back around 2000, when cell phones were becoming more common in the US, I heard that in Japan cell phones were way advanced and all had cameras in them and I was like, "Pffft, that's dumb. Why would you want a camera in your phone?"

But I'll take a guess: Things will be pretty much the same, except Kotlin will start taking over Java's share of developer interest. I'm a fan of it.

I have no clue how Go or Rust will fair. Maybe they become more popular, maybe they don't.

AustinMtG1 karma

Hi Al! Thank you so much for your contributions to our body of knowledge! When I first learned python it was a breath of fresh air, and no other language has struck me in quite the same way.

Do you have a language you know that has struck you in a similar way? If so, what are its beautiful qualities, and how did you come to find it?

AlSweigart3 karma

Heh, I worry that I've become too much of a Python fanboy, but most of the time when I look at a new language I think "this would be better if it were more like Python". I kind of worry that going deep into Python is keeping me from going wide into other programming languages.

I first heard about Kotlin last year and am really excited about it's potential as a Java-killer. It's basically Java except with a lot of the best practices and workarounds built into the language itself. It also compiles to JVM bytecode or even into Java source code, so it's backwards compatible (giving a great migration path for existing code bases).

Python has basically eaten up a lot of areas: web apps, scripting, academic number crunching, machine learning, data science, etc. But it still isn't widely used in games (the GIL prevents use of multiple cores, which is important for gaming), front end web apps (JavaScript is still king here), and mobile development. I'd really like to see something like Kotlin unseat Java for mobile, and writing a beginners programming book on Kotlin would be great. (Maybe in 2019?) Especially since I want to get kids into programming, and making games is a great way to do this but kids think of Angry Birds when they think of games, not text adventures.

But more than the language syntax, I think a language's community and ecosystem are the most important thing. Python's great for both of these: lots of friendly people and lots of modules and documentation. It doesn't matter how great or "elegant" your language is if nobody uses it.

27E181 karma

Have you (or are planning to) do any books on Haskell?

AlSweigart1 karma

Heh, I started reading through The Little Schemer earlier this week because I'm writing a book on recursion. I don't want to say this too loudly, but I'm really disappointed with it. If you're in the 5% of the population that loves manipulating abstract symbols for the sake of manipulating abstract symbols, then you'll love it. Its format provides a great sense of discovery an the people you like it really, really like it. But for everyone else, it's confusing, easy to lose your train of thought with, and I'm not sure how pedagogically sound it is. It really needed a heavy-handed editor.

I'm only 3/4 the way through it, but I have a huge pile of notes with how I'd rewrite it so it's more accessible, especially to people who have general math phobia. But my 2018 is going to be full with other writing projects, so I don't think I'd be able to get to a book on a functional programming language.

Also, I'm not entirely sold on functional programming. Lots of FP ideas are fantastic: reducing or eliminating side effects, functions as first class objects, etc. But, just like I think Java goes to far with OOP (no top-level functions, final classes like java.lang.Math instead of modules, etc), I don't think a pure functional language like Haskell is necessarily a practical way to write software. (Learning a FP language like Haskell is something I think every programmer should do, though.)

And , while I'm not entirely swayed by market demand, I do want to make things that will have the biggest impact. I'm not sure Haskell is any more popular now than it was when I first heard of it 15 years ago. If I was going to create materials for a functional language, it'd probably be Scala. But if I'm going to write about a JVM language, it'd probably be Kotlin (which I think has a lot of potential). But my 2018 is already packed with the Automate sequel, and maybe I'll come up with other projects before then. So a Haskell book probably isn't in my future, unfortunately.

Subjunctive__Bot1 karma

[removed]

alpha_hxCR81 karma

Hi Al,

Thanks for creating pyautogui and for writing the Automate the Boring stuff book.. I saw your youtube video at Pycon 2016/2017, which introduced me to pyautogui and have been using it a lot to automate some stuff.

I have been coding for a few months, working on a side project trying to automate a lot of things that are pretty mundane but need to be done manually. It has gradually got pretty complex, and now I have intermittent bugs, which I can’t necessarily track down. I have been reading Code Complete and gradually implementing more Object oriented programming structure, writing better specifications, and deciding the architecture before I start coding, thinking of writing unit-tests. Because of the intermittent bugs, which I can’t track down, somebody suggested that I put my windows application in a Docker container.

Questions

It seems to me that all of the above strategies: OO, writing unit-tests, specification, requirements, source control, Docker/pyenv/virtualenv are designed as a defense mechanism against complexity of a program. So we can work with the smallest chunk.

I know that my code base can be improved a lot using the above strategies. But I dont necessarily know which one of these I should implement first.

  1. Say you were given an unknown codebase, which was partially OO, didn’t have unit-tests, didn’t have requirements/specifications, didn’t use Docker/pyenv. How would you think about prioritizing which one of these strategies to use to improve the code base?

  2. I also have some plans to extend the codebase urgently to some other activities, but because of the intermittent bugs, I am wondering if its better instead to stop and make the current code base more OO, have unit-tests, write out specifications, use some kind of environmental variable control/Docker, before I write new code. In your opinion, is it better to make the current code base more robust using the above strategies, before writing new code?

AlSweigart1 karma

How would you think about prioritizing which one of these strategies to use to improve the code base?

Definitely unit tests. Adding unit tests should be done before you do changes, because any time you change the code (either to fix bugs or add features) you could break some existing thing. Unit tests are how you know that a change hasn't broken some existing feature.

In your opinion, is it better to make the current code base more robust using the above strategies, before writing new code?

I don't really have a firm answer for this. This kind of gets to the heart of "technical debt". Technical debt is a lot like Tetris. Sometimes to solve a more pressing problem you have let it pile up a little, but you can't just keep doing this forever. And while you can put off refactoring code to make it nicer to work with, I'd say you should fix outright bugs before writing new code.

CHUCK297251 karma

What are some of your recent personal coding projects?

AlSweigart2 karma

I've been writing a book with the working title "Automate the Minecraft Stuff", which teaches Lua programming using this mod called ComputerCraft that adds programmable robots to Minecraft. So I had to write a bunch of programs for that. I've also been using Django and Bootstrap to create a website for the book where people can share their CC programs: https://turtleappstore.com/

More recently, I've been writing a lot of demo recursive programs for a book on recursion.