240708 - Week 4 - Memory - Filter
- Elijah Donnelly
- Jul 9, 2024
- 2 min read
This week I have been working on the problem set “filter.” “Sepia” and “blur” gave me the most trouble this week.
Sepia took me several hours to realize that there was a simple problem with my syntax. (I felt stupid once I realized what the problem was.) When I ran check50, it showed that the first three lines of code were fine, but the last 6 lines of code had different outcomes than expected.
I tried utilizing the duck debugger. The duck will guide me in plain English and pseudocode which helps me better understand where to look. However, this time the duck didn’t seem to spot the issue. This was the first week I had to look outside the duck.
I turned to the CS50 discord and found it very helpful. I posted a snippet of my code and was suggested to implement debug50. Admittedly, I struggled to understand how to read debug50 but decided to give it a try.
As I dove into debug50 using the 3x3 pixel image provided in the discord, I noticed that my code was ending early. It was then I realized the simple, silly mistake of misplacing my “return” statement. The “return” function was placed in between the “for” loops of height and width. So, after my function would run through the height, it would exit out entirely. facepalms
“Blur” was a bit more difficult for me. Based on my recent success, I began looking at the issue with debug50. However, I wasn’t sure what to look for. After tinkering with my code (like changing ints to floats or changing where I initiated variables), I realized I needed to go back to the duck’s help.
The duck kept telling me that I should create a copy of the image before I initiated the blur part of my code. I moved “copy[i][j] = image[i][j]” to the start of my function, but every time I compiled, I was told that both the variables “i” and “j” were out of scope. I thought perhaps the duck might just be confused since I wasn’t able to show the code in its entirety.
After tinkering with my code some more and not having any results, I felt like giving up. I asked the duck one last time to see what was wrong with my code. It gave me the same suggestion, that I should initiate “copy[i][j] = image[i][j]” before I blurred the image. A question flashed through my mind. “What exactly does the duck mean by that?”
The duck explained that I needed to create a copy of every pixel before I began my blurring process. I asked a follow-up question “Does that mean I need to create another set of nested loops and create a copy of the image BEFORE the other set of nested loops?” Essentially, that’s exactly what I had to do. After implementing that advice, I finally got those coveted all-green smiley faces from check50.
In summary, this week’s troubles were mostly due to syntax errors and simple mistakes. I feel like I’m beginning to get a handle on coding.
Comments