Programming Concept onEvent

A kludge is not language specific. Kludgy is a property of code that works but we don’t like the way it works. I find that code kludgy because it has extra logic that could cause problems. Like if you forget and create a button with the wrong name.

One of the big things Javascript gives us is a way to interact with the DOM (Document Object Model.) The DOM is created by parsing the HTML code creating a hierarchy of elements (or as us out to pasture programmers call them widgets.) There is a missed opportunity to use that hierarchy to remove unnecessary logic from your code. We can attach an event listener to each button that doesn’t need to test if a button was pressed. You already know when the callback fires why it has fired.

From a purely App Lab point of view, there is an issue that can occur when you code onEvent without an actual element name. It is discussed here Bug - unit 5 lesson 8 - #2 by jdonwells Basically if you use a variable instead of an element name the dropdown for the event type isn’t specific to that element type and you can choose an event that throws a run time error.

Javascript and hence App Lab support 3 programming paradigms. Namely procedural, functional, and object oriented. AP CSP really stresses the procedural portion of Javascript. But Javascript was really created to stress the functional paradigm. If you find yourself teaching AP CS A you will learn object oriented till you scream. But, to learn more about functional programming in App Lab I would read Javascript Allonge. Read JavaScript Allongé (ES5) | Leanpub This is a link to the ES5 version which is the version of App Lab.

If you want me to take a look at that project and tell you the good, bad, and ugly I can do that. It will take a couple days.

1 Like