D42: Eureka!

I’ve read a great deal about coding since I’ve started this journey, much of it very (maybe even a bit too) encouraging (“Anyone can code! Here’s how to go from novice to engineer in 6 months!”), but some of it more grounded in a realistic understanding of what it takes to actually make it in the field.

From what I’ve gathered, more than anything, you have to be willing to persevere, even when nothing makes any sense and you’re sure you’re just too thick to ever grasp the concept. Luckily for me, very little about my life makes much sense (so I’m used to it) and I’m VERY stubborn.

Plus, the high that hits you when you finally do get a handle on a tough concept: UNDEFEATED.

Today’s challenge (and yesterday’s if I’m being honest: Object-Oriented Programming. Specifically, how bracket notation is used to access an object property using a variable when the property’s name is collected dynamically during program execution.

That was gibberish to me the first time I read it (last night) and it wasn’t much clearer when I returned to it on this fateful night (and even though I understand it now, boy, is it all but designed to be tough to parse). But when I got it (it hit me while I was copying the above code into my notebook for future reference), I laughed at how simple it was. And it was the simplicity that made me overlook it.

The property we want to access is propName, which lives inside someObj. We’re then given a function called propPrefix, whose only job is to stick the word “prop” in front of whichever word its given. Then comes the variable called someProp, which is assigned that old one-hit-wonder, function propPrefix as a value. The joke is: the argument passed into propPrefix is “Name”. So, when the last line invokes the object titled someObj and passes in the someProp variable as the property to be accessed, function propPrefix does its one job and makes: “propName”. Which is how the program will then output the value of “John”.

The fact that I’m able to look at any code at all and understand what the computer is being asked to do remains a constant marvel, but the fact that I was able to stick with it and puzzle out something that made zero sense to me 24 hours earlier?

Priceless.

And that’s how I know I’m on the right path.

Leave a comment