05 November 2018
Comedy. I love comedy in all of its forms. One of my favorite forms is the comic strip. Growing up I used to spend countless hours reading Garfield, and Calvin and Hobbs comic collections.
I stumbled across xkcd.com a few years ago, like you do on those sleepless nights trolling the internet. (Trolling in the fishing boat sense.)
I have been obsessed with it at times and I think I have read almost all of them and committed them to the internal memory of my brain and can recall them with almost perfect precision.
As part of my eventual transition from C#.NET developer to iOS developer I was searching for a project I could build that would show off a pretty complete set of skills. I settled on building an xkcd reader app. I looked on the App Store and there were already a few of them but they all seemed to be flawed in some way or another. So I decided to start the app.
They, (who is they right?), say that “A week of planning can save a month of coding”. In my case that would have been very true. After I had the app about 90% of the way built I noticed a fundamental problem. I was going to be fetching the comics from the APIs located here and here.
If you look closely at the second url: “http://xkcd.com/641/info.0.json” you can see that you have to supply the number of the comic you want to view. I thought, “No problem. I’ll just grab the most recent comic from the first url: ‘http://xkcd.com/info.0.json’ and then parse that to find the comic number and then use that upper bound in a loop to get every one of the comics.
Now the more experienced developers in the audience may have already noticed the flaw in this idea. In fact, as a junior developer I should have noticed and I probably would have had I sat down and planned for 20 minutes.
There are currently 1,880 comics on xkcd so in order to get all of them I would have to have a loop that runs 1800 times and makes 1800 requests. These are small requests but lets say there are 100 people using my app worldwide. That would be 18,000 requests every time they open the app, (barring any local storage of course).
This is the problem and as a solution I decided to use/hone some of my C#.NET chops and build a WebAPI project in ASP.NET Core 2.0 and host everything in Azure. It was a fun project but it was some of the toughest stuff I have done to date. Here is what I did:
I’m not going to talk much about the iOS side of my project here. It’s a pretty straight-forward TableView app with a detail page. I’m mostly going to focus on the difficulties I faced with this project from the .NET Core side.
I wanted to use the latest tech and design patterns and I wanted my code to be as tight as possible. I went with ASP.NET Core 2.0 that had just been released a few weeks before I started. I also made the decision at the start that I wanted to host everything in Azure.
I started with the Azure piece first because I thought that was going to be my biggest stumbling block. All in all it was easier than I expected it to be.
I setup the entire pipeline from start to finish. When I commit and push my code it goes to VSTS and once there the entire Continuous Delivery process kicks off. The app is built, load tested, deployed to a “staging” deployment slot and the previous deployment slot is swapped to production. The whole process takes about 20 minutes which is a little longer than I like but it’s acceptable.
The really cool thing is that I can always publish an emergency hot fix from Visual Studio in a few seconds.
After setting up the App Service in Azure I setup a Server and Database. Then I connected to the database via Sql Server Management Studio. Once I had that all up and running I was ready to start writing code.
I used all of the hot new design patterns. I used dependency injection, the repository pattern, etc. The only thing I neglected to do to make this a really robust project is writing unit tests. I know that this is heard all of the time but, “I plan on getting back to them eventually.”
I can honestly say that I learned a lot by doing this project. A lot of the code that I see on a daily basis at my day job didn’t really make sense to me. I know the steps when adding functionality to a project but for the first time I am starting to understand them.
This project was really hard for me. As a junior developer I spend a lot of time reading code, modifying code or copying existing code to add a new page or a new checkbox to a page. However, I rarely get an opportunity to write software from start to finish by myself.
That is part of the reason why I wanted to do this project. You can’t grow as a junior developer unless to get out of your comfort zone from time to time.
I realize that I haven’t really given a lot of information on what I did. If you were looking for a full tutorial, I’m Sorry. What I thought I would do though in this closing section is just highlight some of the difficulties I had. This whole project was straight-forward minus the few issues I encountered below:
Thanks for reading. If you would like to take a look at the project here is the link to the GitHub page where it is located.