Day 10 & 12: A Class on the Method for the Perfect Hash Brown

Matt Edwards: 82 Days
6 min readApr 26, 2021

--

A rounding up of week 2 left me tired, in a good way. The type of tired you don’t mind being, feeling good about your personal progress. The kind that lets you switch off for the weekend without feeling too guilty. Yeah, that type. However to get to this point, everything didn’t go as planned and I stumbled plenty. Thank goodness I wasn’t alone in all this. The support given by my cohort is invaluable, and the coaches are incredibly nice. I’ve not always liked my teachers. In fact I could count on both hands the ones that left a positive impression on me and these coaches have easily gotten on the list.

Week 2 was Module 2. Working through the quiz chapters, covering various topics such as control flow, Arrays, Methods, Classes and Hashes. It wasn’t alwasy straightforward. Actually it was rarely straightforward and each task exposed flaws and gaps within our own knowledge, presenting the opportunity for growth and learning.

Lets highlight the one I struggled with the most.

Put it all on black, Jack.

The task was straightforward enough. Create a singleplayer game of Blackjack using methods. Sounds simple enough until you start typing. This was one of the tasks where the uses of pseudo code come in hand. Sometimes you have no idea where to begin tackling a problem until you break it down nicely into chunks or tasks. I wish I could say that I did this before I start, but that wasn’t the case. I have a bad habit of jumping head first into these problems and sort of ‘feel it out’. As you can tell, that’s not a plan. After I had felt like I had finished, the logic working as intended with no bugs as far as I could tell, I put it through the test to see what would happen. It failed. ‘Strange’ was the word that came to mind. I looked to see what the test said was wrong and apparently everything was!

I have the luxury of hindsight now, but I spent hours looking and debugging the code to see why the tests were failing, but the code was working as I thought intended. I mean that’s what matters the most right? Well after the help from a member of my cohort,we didn’t exactly fix all the bugs I had, but I did find that I ended up misnaming a method completely. That’s kind of important given that this whole chapter was all about methods and working with them.

To prevent a whole essay on this part alone, the problem seemed to be my reading of the task itself. Through this exercise I had misread parts of the task completely and ended up doing something else entirely. Words are important when you are given a task it seems! The main culprits were my score method and the input method. From all the previous tasks the inputs were predetermined and would be predicable. This alone made me think that input checks weren’t important. Spoiler alert — they were.

The score method was where I was mainly going wrong. I was meant to take an array or cards as an input and convert them to a score. I wasn’t doing that at all before and ended up just taking in an integer, adding that to a random card value and spitting it out. I found this out through looking at what the output of the tests were asking of me. An example being: ‘input [‘four’], expected 4, got 17.

Through much code refactoring, I managed to pass the tests that destroyed me for hours. Thank goodness we take time out for meditation in the day or I probably wouldn’t have been clear headed enough to fix this by the end of the day.

Through this particular challenge, I learnt enough to be able to meaningfully help others with the same one and also as a nice bonus, see how others approach the same problem. Thankfully it wasn’t just me who found this particular task hard, but many others too. Thankfully we all made it through by the end of the week.

Classes, Methods, Hashes and Arrays

I used to fear Classes. I used to absolutely avoid Arrays. I still think Hashes are Array’s angry cousin. Methods are fine I guess, but I’ve come to terms with the rest of them! As it turns out, practice is essential to learning. The reason I used to think classes and arrays were scary, was like any other fear: not being understood. We fear the things we don’t understand, so the best way to get to know something is to practice, pay more attention and being okay with the fact that this is all somewhat new and all very strange and scary. Practicing got me to expose my own flaws in my understanding about these things, and through this, I could work on what I was struggling with.

I still kinda think Hashes are an angry Array, but I don’t fear it anymore. In fact, I’m looking forward to using one again soon to get to better grips with it! It’s always a great feeling looking back and seeing you learned something really useful! Or anything for that matter.

There is always more to learn though. My code isn’t perfect and I may take longer routes than is necessary and I get lost in my own writing at times.

I mean look at what’s next to me. I wrote this last week and I can’t for the life of me at a glance tell you what’s happening. I have to line by line process what is happening to even jump back in and add anything else. I pitty those who have to go through this to see what’s happening, because at least I have a small clue being the one who wrote it, but you know what this thing needs? Comments.

Something so simple yet incredibly powerful. I clearly don’t use it enough in my own work. It’s not in the least bit user friendly to read right now and I can easily have changed that by adding comments, telling others or better yet myself what is happening where. With something as simple as this, I could save time and headache in the future for anyone who needs to go over this for any reason.

Isn’t this way better? Besides the appearance of the colour, this at least adds a little clarity to what each section achieves and you don’t need to do any mental gymnastics to find any specific part going forward. Of course things can still be improved such as conciseness, but overall it has managed its main objective by adding human friendly readable text, to an otherwise cryptic page of text, symbols and logic.

Looking forward, there is a lot to learn and there will be many pitfalls ahead. At times I’ll feel like things are too tough, that maybe I’m not suited for this at all. But no matter how I’m feeling at the time, as long as I keep at it I’ll eventually succeed. Move from a fixed mindset to a growth mindset: instead of: ‘I can’t do this.’, I’m going to try saying: ‘I can’t do this.. yet.

Perseverance and the will to keep going will be enough.

--

--

Matt Edwards: 82 Days
0 Followers

Apprentice Software Engineer, DWP, Team: Digital Hub maintanence, retraining as a Software Engineer to better delevelop my skills and start a meaningful career.