Day 15: Meetings galore

Today was filled with meetings. I had the daily, the “Blindspot” meeting with Alvaro and his whole group of people of which he’s the PPM (not sure what to call this group), a meeting with Ugurcan concerning the setup of the Heartbeat project on my machine, a meeting with Wolfram, and my one-on-one with Alvaro. As a result, my Haskell book has collected (virtual) dust.

I spent a lot of my non-meeting time with the Elevator Saga again. I was having a problem where I was creating an event listener for each floor object (for the event where a person presses the up button or down button) in a for-loop. Each of these event listeners would then add the current floor to a set of floors called upButtonFloors and downButtonFloors, respectively. The problem with the following code is that, if there are 5 floors, the value of floorNum that was always being added to the sets is 5.

for (floorNum = 0; floorNum < floors.length; floorNum++) {
   floors[floorNum].on(“up_button_pressed”, function() {
       upButtonFloors.add(floorNum);
   });
   floors[floorNum].on(“down_button_pressed”, function() {
       downButtonFloors.add(floorNum);
   });
}

This question turned my meeting with Wolfram into a JavaScript Closure meeting (instead of a meeting about ways to have the Heartbeat monitors rotate between different URLs). Wolfram taught me about the call stack and what happens with asynchronous instructions. We worked through a more general example in TDD bin that asynchronously added values to an array. We went over what works (and why) and what doesn’t (and why). It was a lot to digest, but going through this example made everything a lot clearer. In the end, we learned that simply adding a “let” will reduce the scope of floorNum to just the body of the for loop, so when an event happens, the handler calls a function with the intended value. Though I know this is not a complete answer to “why this works.”

If I were a more seasoned JavaScript programmer, I would have added the let in the first place and therefore would not have run into this problem. But I’m glad I did because it led me to ask Wolfram, which led to an in depth explanation of what is happening under the hood and how to fix it. If I had added the let, I would have no real understanding of the call stack, what happens when we call setTimeout(), and how asynchronous instructions are handled in JavaScript (which is single threaded, which I’m sure most of you know).

Regarding the Heartbeat monitors, there are quite a few chrome extensions that rotate between different URLs (one has the name “Rotisserie,” which kind of displeases me because it makes me think of chicken) which, as of now, seems like the route I will take. The cool thing about this is that anyone who wants to add a feature may create their own application and add the link to the list of URLs on rotate. Alvaro was saying how this would be good for future apprentices/interns to contribute to as well. It would be an interesting why to learn how to create a web application while also adding value to the company!

So, my day flew by and it has come to an end. Next week I will move on to Haskell lists 😄.

And the sun is finally out 😎


Last updated: