From start to finish, the process of building my project was enjoyable and rewarding. I learned several valuable lessons that will let me save time and write better code in the future.
Fortunately, coming up with an idea for my project was straightforward. Because my thoughts have been hovering around Thanksgiving lately I thought it was a good idea to build an application around that. Cooking on Thanksgiving day is something I look forward to and I find browsing and selecting recipes to be fun so I built an application that lets a user search for a food item and pick recipes to build a menu for Thanksgiving.
Getting a barebones version of my app working did not take much time however I found that adding functionality to it wasn't always easy. For example, collecting and adding sub-recipe attributes to my recipe objects proved to be more difficult than it seemed at the start. To clarify, some recipes pages had header tags between ingredients or directions to describe what part of the recipe those ingredients/directions were for and my code did not include that. In order to include them and correctly attribute the ingredients or directions to those sub-recipes I had to change the way my code gathered ingredients and directions. Instead of just grabbing the whole list of ingredients or directions, I instead had to grab only the ingredients/directions in between headers. I did that by iterating through each html element, starting with the first ingredient, and checking whether the next element was also an ingredient/direction and if it was, add it to my list of ingredient/directions or if it wasn't (like in the case of it being a header), return the list. Even though it took a lot of work for something that doesn't make a huge difference, I felt good that I was able to do it and my program became more robust and useful because of it.
After going through all that trouble, I realized I was probably not going to be able to include everything I originally planned. Starting out, I had wanted to build multiple web-scrapers to find recipes from different websites but now adding another web-scraper seemed unnecessary and difficult, so I dropped the idea. More than that, I wanted to have my program print a list of all ingredients sorted by the ingredient name. However, separating units from the ingredient names seemed like an impossible task so I dropped that idea too. Even though my app didn't do everything I planned, I was still happy with all the functionality it did have.
Once I had everything working with all the functionality I could reasonably add, I realized my code was a mess. The last step before concluding my project was cleaning it up. To start with, I broke up larger functions into multiple smaller ones. After doing that, I noticed that I had a lot of repeating code. Some functions were almost identical with only a couple lines of code being different. I found that the best solution for this was to combine them and use an optional Boolean parameter and an if statement inside the function to have the same service as having two separate functions while only having one. Lastly, I reviewed each function and changed variable and function names so that they properly reflected what they were saving or doing. Doing this made my code notably more easy to understand, even for myself.
Building my first project was an experience that I will remember fondly. It taught me that some seemingly simple tasks can provide unexpectedly large challenges and that writing clean code to start will save time and prevent headaches in the future.
My project: https://github.com/nrymarz/ThanksgivingRecipes