My First Project - Part 2
My first tutorial
The project
As mentioned in My introduction, my first project using Python was a gaming website for a massively-multiplayer online role-play game (MMORPG). I had started a corporation in-game (a player group/guild) and was keen on providing the other members with some out-of-game tools that other larger groups did. The game developers (CCP Games) have a host of information that players can access from the game server through various API requests, some require authentication, some you can just grab. It was this sort of information that I wanted to be able to conveniently supply to my corporation members.
This series describes the journey from this initial idea to the deployment of my first full Python application.
- Part 1 - My first steps
- Part 2 - My first tutorial (this post)
- Part 3 - My first deployment
Miguel Grinberg’s ‘Flask Mega-Tutorial’
As described in the My first steps post, this was my first proper dive into a full Python project, and what a dive! The tutorial is fantastic and the level of detail in here is astounding. It’s done in a very logical and practical format that allowed me to both follow through but also use this as a roadmap for the website that I wanted to create.
The tutorial is broken up in to specific chapters and each descriptive enough to allow breaks and easy restarting if you don’t complete a whole chapter. What I like most though is that it’s not just a step by step; he explains a lot of background for the progressions AND provides explanation for why we are doing certain things. And, for me, that’s a winning combo. Just following through is one thing, but learning the ins and outs of why I’ve to do things in a certain way helps my learning immensely, and those were the bits that I personally got the most out of, other than the actual experience.
In addition to being incredibly well laid out and thorough, Miguel also saved the code for each chapter as a separate ‘release’ in GitHub, allowing me to check and compare with the master code for each step to find where I went wrong (I used this many times!).
If it wasn’t for this tutorial, I would be surprised if I would have made it this far. Hitting road blocks when doing something like this is very frustrating. There were many times, probably in arrogance, where I thought that I’d found a bug or something in either Miguel’s code, or the code of whatever library I was using. It was by going through something like that that I discovered one of the biggest lessons (for me) in programming: in the face of errors, first assume that I am wrong. At this level of programming it’s highly unlikely that you are discovering a bug or never-seen-before issue, so the first step is to walk back and try work out where you’ve gone wrong.
I’m never wrong
There were so many times where I hit the programming wall, and a large portion of those times I came to the conclusion that I was right! Me, beginner programming extraordinaire, was obviously not in the wrong. I’m hoping that this isn’t just arrogance or anything similar that caused me to conclude this, and it certainly wasn’t that I just PRESUMED that each error wasn’t my fault, I just mean that when trying something over and over, or trying to integrate some new module or piece of code, often it can seem like it just isn’t going to work.
Obviously, a lot of the time just taking a break and coming back to the error or issue later helps a lot. Sometimes I found working on a different project or tutorial also helped, seeing how others write code and what other modules or libraries are out there is a huge help. Again, it’s had to know what you don’t know, particularly in such a huge and rapidly evolving area as Python.
Full steam ahead
With the tutorial guiding me along (and the constant assistance of Stack Overflow), I progressed through the tutorial, learning about databases, web servers, JSON, html templates (I don’t think I can love Jinja any more than I already do!) and all the other nuggets of gold that it provided in my journey.
I worked through the tutorial over a number of time, always with the thought of how I would be able to reuse it to creating my own website down the line. I started to get a hang of the rough structure of the application, files and the different libraries being used. So much so, that I thought that I might be able to take what I’d learned already and start creating my Eve Online website. I mean, why not? That was the whole point of this process, learn enough that I might be able to apply it to my project.
So, after discovering that Chapters 8, 9 and 10 were for features that my own website would not be using, I committed! Why shouldn’t I take my expert level experience that I’d gained and turned my eye towards the prize.
Iceberg sighted
With the usual number of mistakes, rewriting, and slew of errors that I had become accustomed to facing, I got my own version of the website working locally and up to par with the tutorial. But that was it. I was stuck and alone in uncharted territory. What was the difference between deployment and production versions of a Flask web server, how did other people access it? I didn’t know where to go from here, no clue what the next steps were beyond the fog of Chapter 7, the last chapter that I had completed of Miguel’s tutorial.
So, I went back to my guiding light: the tutorial.
Sinking motivation
I skimmed through the parts that I had deemed not-required until I got to Chapter 15: A Better Application Structure. It was here that I (re)learned just HOW far I had to go. Not only had I considered my fledgling application suitable for the big, bad world of live websites, but I had essentially created a handful of loosely tied together scripts, rather than a complete application.
Chapter 15 became a bit of a turning point in my journey. This chapter detailed the restructuring the application into a more modular and professional format, utilising Flask’s Blueprints functionality. Now, I’m not going to go in to what Flask’s Blueprints are, but suffice to say, they bring a glorious organisation to your application and help you create one that is easier to fault find, clearer to understand and read, but only once you get your head around how they work. Like all things Flask, they give you the groundwork for you to build from yourself, rather than tell you the specific ways in what they are to be used.
So, upon realising just how much better my application could and should be, I went back to the tutorial and continued through, thoroughly humbled.
Recovery
Having been led back into the light, I continued to work through the Flask tutorial but I also kept my own application updated as well and applied what I learned at the end of each chapter. This meant that I was working on two projects at once. Looking back, and even at the time, this clearly wasn’t the best way of doing things, but it did feel almost like a mini practical-test at the end of a study period.
It was an interesting lesson to learn and something that I’ve taken onboard for my future learnings. Whenever working through a tutorial, project or course, I now try to focus wholly on the one thing at a time. This has helped reduce the distractions that (so frequently) try to drag me away from what I’m doing.
Lessons learned
Never assume, always check.
This probably comes a lot from my working life as well, but this part of the project definitely made get in to the habit of stopping and rechecking any errors to find out exactly what went wrong, rather than assuming that I knew what the error was.
Note
I realise that the Flask tutorial that I was working through wasn’t THE correct way of doing things and that a lot of the layout and things were recommendations only. However, with my limited knowledge, these became gospel for me. Eventually I was able understand why certain things were recommended in that way and I definitely have adapted a number of my own tweaks (for better or worse!) in to the layout of future projects.