Now, I know the posts about me programming are a bit dull since I’m still very much a beginner, but since I didn’t have any activities scheduled this weekend and no work stuff to take care of, I felt like I was finally able to make some significant growth in my programming powers. Admittedly, compared to anyone who is even remotely competent, I’m still a babbling baby, but still, it’s pretty cool to go back to something I made about a month ago from going along with a webmonkey post to going through and making it my own AND more easy to read, change, and follow along with. I think the combination of those two things are something I really love about coding. You can look up just about anything online (at least for the kinds of problems my beginner butt is running into), and then you can recreate bits of what you find with other knowledge you have to make them more simplistic or elegant.
CS vocabulary has been a bit new to me. There are a lot of words I know in completely different contexts that have a very different definition in CS. I’ve been trying to track new words I learn as I read about them and trying to see if I can understand them without my brain hurting while looking it up. Sometimes I’m completely able to get it, and other times I sort of brain fart and feel like a toddler again. So, for example, I read an article about a person who was working as a recruiter for a company. This company was concerned about gender/racial bias interfering with its interview process, so together with the recruiter decided to do the programming portion of the interview with the candidates completely anonymously online. Aside from written language (which one might argue could give some of this information away), he never saw or spoke with the candidates. He gave them a refactoring challenge where they were to identify code smells. When I read through the rest of the article, I was completely and utterly confused about exactly what it was he was having them do, but from what I could guess at the time he was having them look for hints of something being inefficient or problematic in the code then restructuring it. Thanks to some quality time with my overlord Google, this turned out to mostly seem accurate.
Refactoring is when you alter the internal structure of the code without changing its external behavior. When I wrote the first draft of my slideshow code I hadn’t any experience with objects or events, so when the site I followed along with pointed out different events, I just sort of rolled with it without really fully understanding what was going on beyond that when something was clicked, I told it to execute a function. I also used global variables quite liberally, because that was the only way I really knew how to get some of the work done that I needed. Even after I switched out all my functions to be methods instead, this hasn’t really changed too terribly much if I’m honest, but the beginning value of the variables is all easily accessible at the beginning of the method object.
Now, with the original script I had made a slight change to it. I had added a while loop to create the imageArray since typing them in individual was not on my future desires list. At the time I felt slightly successful being able to make that change, but ultimately I had mostly ended up with code very similar to the article as I wrote it after reading what needed to be done, and then I compared to what they had with functionality. Not a great strategy, but again, the event handlers were a bit over my head at the time.
When I went through it to refactor, I renamed some variables to names that made more sense to me. I added comments. I restructured it to have the functions sorted as methods in objects and all the variables within objects as well. None of what I did was really ground breaking, and a lot of it was work I honestly will probably change again as I continue learning in the next few weeks, but it helped me practice the skills I have learned and apply them, which is always helpful for retaining information and being able to use those skills creatively in the future.
You can go to my GitHub account to check out the code and the revision in a Gist.
Next: to improve the Battleship game.