Hi gjschmidt - is there a time where this IS a good idea? I have a lot of students creating a function that takes parameters such as id_name and event_name, and will have an onEvent function INSIDE the function they’ve created, which makes it so that they don’t have to create so many events for a project.
Just wondering if this is technically sound or not in the world of event driven programming. Thanks in advance!
Putting onEvent() inside another function is only useful when you want to add additional code to an event after some other event or stage in the program’s execution. However, you could just as easily add all the code and use if statements to control when the additional code starts to function. There is always another straight forward way to get that working.
Adding additional event handlers under program control makes the confusion of event driven programming even more confusing. You can do it. It works. But from a good practices point of view there is never a good enough reason to do that.
There is one time I might consider onEvent inside other code. That would be if I wanted to create screen elements in some variable way. For example, if I was creating a spreadsheet program and wanted to have the number of cells across and down be set at the top of the program.