My First time Reading Code, Sorta.

Source: debug.jpg (1968×1242) (geekflare.com)

I read code for the first time yesterday. Well, not exactly my first. I’ve contributed a bit to open source for the yearly hacktoberfest challenge. I also read code snippets whenever I need to solve a problem. This time, though, was the first time reading someone else’s code to solve a specific problem — somehow this makes less sense, but well, let’s continue.

How did this happen?

The Bug Fixing Process

The fact of the matter is: It was a bit daunting. Yes, this was unchartered territory and I honestly didn’t want to mess things up. I didn’t want to mess things up but I knew there was a nasty bug to fix. The only way, as the axiom states, is to move forward.

Problem Solving Approach

I looked through the HTML file and saw that an icon kit was being used — nice. I would have created the hamburger but why reinvent the wheel — that’s something I need to think about on my next project. The markup looked really okay to me, oh but one thing, there were ID attributes used liberally. I was quite shocked because I never use IDs at all. I feel the specificity issues that could result from them is not something I would want to deal with. Apart from that, everything else seemed okay.

Now on to the CSS and JS

The problem was mainly from the JS event Listeners and the corresponding classnames that were being toggled. I think the order of the statements that are supposed to execute when the hamburger menu was clicked was disordered. I struggled with it a lot, partly because I kept trying different solutions, trying to see if one thing would fix it. Note to future self: DO NOT DO THIS.

The better way is to read the code line by line and try to find the bug. If that doesn’t work, comment it out and refactor. Refactoring the code saved me a ton of time. I fixed the bugs in the JS and CSS files and Bob’s your uncle, everything worked. WOW! that was some hard work.

The most exciting part about this was using the devtools as well as git to add and then commit changes. I’d say: it was a refreshing experience and I look forward to doing more of this soon.

Thanks for reading.

I hope you have a nice day,

Kenny.

I write about stuff I like which includes tech, philosophy and the human experience.