DevMountain - Week Two

Last week was our only week on html and css. The first three lectures this week felt like excessively redundant reviews of the pre-course work material. (Just to be clear, I’m not saying that Trevor or Jake’s presentations were bad!) The exercises that accompanied those lesson were much more useful as refreshers.

But then we hit the callback homework and Saturday morning’s exercise!

A pupil from whom nothing is demanded which he cannot do will not achieve all he can.

My Challenges

Callbacks and .this

I’ve been studying JavaScript on my own for a few months, and had already run into callbacks. I’ve also done programming with procedural and object-oriented paradigms, so ironically, it’s taken me a while to understand them. At this point, I definitely get them - well, at least in theory - and think they’re pretty dang awesome!

So the callback introduction section of the reading was a breeze. But then I read about the interaction between callbacks and .this - man was I lost. Actually, the scoping part (i.e. the problem) seemed really easy to understand, it’s the solution that left me dazed and confused. I ended up reading that section at least half a dozen times and I’m still lost. The irony is that shortly after he describes the problem, and just before he shows example solution code he states’ “This sounds complex, but lets see how easy it is to use Apply or Call.” Not — oh so “NOT!” The example actually made the solution seem even more complex and illogical!

Needless to say, I was really looking forward to Tyler‘s presentation on Saturday, just so that I could get a different explanation and hopefully some more examples. Unfortunately, he had to leave early, so that’s been put off until Tuesday. :-(

Saturday Morning’s Exercise - War

With two exceptions, I loved Saturday Morning’s Exercise! We were given completed html and css files, along with a JavaScript file that provided a rough outline, for the card game ‘War’. Our job was to flesh out the JavaScript file. With one exception — that Tyler attributed to a hoisting problem in their rough outline — I didn’t have any real problems with this assignment. I did have my usual typos, and am really grateful that I was sitting next to Kelsey — our mistake styles seem to be polar opposite, so we’re really fast at spotting the other’s code faux pas!

One thing I really would have preferred is to have had a more test-driven approach during this exercise. (note to self: develop tests for ‘War’ exercise.) Another “nice-to-have” thing would have been a visual display of each players’ cards. (note to self: augment gui with player’s current hands.)

That said, I also would have preferred to have had exercises earlier this week along these lines!!!

Implementing Callbacks

Like last week, Saturday afternoon we had a week-end assessment. By and large, this was fairly simple. There was a critical typo in one of the exercises that threw me (and some others) for a loop (i.e. “Create a function…” is very different than “Create an object…”)! And then there was the callback exercise!

Because Tyler didn’t cover callbacks, we were told we didn’t need to do the callback exercise. But since I have theoretically grasped basic callbacks, I really wanted to play with some simple callback code.

I took a first stab at the first problem, but for the life of me, I couldn’t get it to work. I finally broke down and called my mentor, Paul, over. He initially thought the problem was one thing (how I was passing a parameter that the callback needed). After fixing that, the code still wouldn’t work. It was really clear that Paul thought it should!

Remembering that the earlier War exercise had a hoisting problem, I suggested that maybe that was also the issue here. We returned my code to a pre-Paul state, and then reordered the code. Sure enough, it had been a hoisting problem! Well, mostly a hoisting problem.

The problem Paul had picked up on early was also a problem. This one was indicative of one of my conceptual struggles with callbacks. So Paul and I went over the code and I definitely feel more comfortable with basic callbacks. Of course, I want more simple callback exercises, just to cement it before it fades into the intellectual ether!

While I was definitely slow on the second problem, I did manage to get it coded without assistance.

Arrays, null, and falseys

One of the few problems from earlier in the week, that really caused me to spin my wheels, dealt with removing falsey values from an array. I had tackled this problem with a simple loop. Despite my best efforts, it was clear that there was a null value that wasn’t being removed. It turns out to have been a challenging problem for more than a few people. Misery loves company; likewise, learners love knowing they’re not the only one struggling with a concept or implementation!

Summary

Most of this week felt like a review, and just when it felt like we were getting to some actual meaty material, we mostly didn’t. :-(

I am grateful that there was the small set of callback exercises and that Paul was there to help me get started, but I’m really looking forward to digging deeper into callbacks, and having some alternative descriptions and examples for the callback / .this issues!

Follow-up

2014-09-28

So the whole closure practice thing and closure/.this thing was really eating at me, so last night I started the Code School - JavaScript Road Trip 3 - Cold Closures Cove chapter. I spent a lot of time just trying to figure out their system constraints. For example, I kept getting an error message that I needed to watch my whitespace; it turned out to be a mismatch between how I had formated my alert message and how they wanted it formated.

Once I got past the system constraints, the first two sections (i.e., “Tracing, Building and Using Closures” and “Modifying Bound Values After Closure”) were actually pretty easy (with a perfect 3250 score; WOOT).

Then I started watching the video for “Dangers at the Moment of Closure”! Exhaustion prevented my brain from following any of it, so I called it a night. I watched the video twice this morning. The first time through was a straight ‘watch’. The second time I stopped and really examined the code, and started to wrap my head around the solutions. The first exercise was almost a joke. The second one was a real challenge, but I still got a perfect score for the course, so WOOT!


Level 2 on JavaScript Road Trip Part 3

And once I got started, I kinda wanted to keep going. Unfortunately, other obligations kept me from finishing all of JavaScript Road Trip Part 3, but I did successfully finish Forest of Function Expressions and Hoisting Hills.