-
In the first screenshot I’m trying to process the line of code “: double 2 * ;” which is defining the function “double”. In the debugger supplied by Google Chrome’s dev tools I am tracking a few variables and objects using the “watch feature”. This is a pretty handy feature since it lets me hone in on variables and objects whose behavior I wish to see as I step through the program. I have also set a few breakpoints (all not seen in screenshot): one at the very start of process, one before process checks for the character “:”, and one before process checks for a “;”. Armed with these breakpoints and my watched variables I am able to see what my temporary_function_definition array (which holds the function defined between the : and ;) holds and how my user_words object (which shall hold the user defined functions for later calling) is updated after I step after the current line (which should push the first input after the : into my temporary_function_definition array). As you can see in the second screenshot the string “double” has been pushed into my tracked temporary_function_definition array which at the very least indicates that my program is starting to record my function in this temporary array. Also, you can notice in both screenshots that I have the vestige of my console.log approach to debugging which is much more tedious than the built in debugger.
-
Redoing the lab in JavaScript was definitely much quicker than the first time around in C++. I was able to neatly redo most of my C++ design in JavaScript. I ended up avoiding a lot of string manipulation and opting to use arrays which led to neater readable code (and less headaches dealing with string manipulation). JavaScripts lack of types is tricky. I was definitely more on edge in keeping track of whether I was working with a string or number. Overall, in this lab I did not have to worry about types too much since I was mostly dealing with numbers, so it was nice to not have to declare the types of every variable and the types of the map. I did however run into trouble with JavaScript’s scoping of local variables; for instance, I wanted a variable to be local, so I simply instantiated the variable without “var” in the location I wanted it; this instantiation made this variable global which was very confusing when I called the same portion of code with the variable and I was obtaining strange values. I used a map (i.e. a dictionary) in JavaScript which is essentially what everything in JavaScript is: an object. I realized how simple it is to make a dictionary and have key values be a string and values be functions (i.e. they became the “methods” of my dictionary. Dynamic typing made it much smoother to write my code since I did not have to update my code whenever I decided to change design; however, having to be forced to statically type did give me a better understanding of what my code was doing and why it was not working. I still am a bit fuzzy on the idea of what a closure is, but as far as I understand it, it has to do with having a local variable in on function which can be accessed and modified by functions called within the original function’s scope.
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.