Tutorials and Stack Overflow code are super useful, until you stop understanding what they’re doing.
This happened to me this past week, and I spent an agonizing few hours debugging a relatively simple issue in my Django application.
Since I had copy-pasted from some authoritative sounding tutorials online, I didn’t understand what was happening when I ran into an error.
This quick post is my word of warning: If you’re copy-pasting code you don’t understand, then you’re in for a bad time.
Copying en masse
In my application, I wanted to implement basic user registration and sign-in, but enable customization of the forms and add email activation on registration.
The solution was to use a combination of Django’s built-in auth along with an open-source tool called django-authentication.
I glanced at the documentation for both and then started hacking toward the desired outcome. And I got really far with my own intuition and code samples online.
This applies to nearly any coding problem, not just Django. You’ll likely get most of the way there with tutorials and code samples, but those are dangerous waters if you’re copying too much or code that’s too complex.
Django NoReverseMatch: Reverse for ‘password_reset_confirm’ — my bug from hell
Unfortunately, I was copying from multiple sources, and eventually those sources conflicted to produce a bug:
Now, the bug in question doesn’t really matter for the sake of this post. It’s a concrete example we can talk about. But this post is about lessons I learned about debugging in general. They can apply to any bug.
By this point, I had copied so many templates, routes, and views from various sources, that I didn’t even know where to begin debugging.