Processing provides a number of
Library Methods (pre, draw, post etc.) that we can hook into with
register???(PApplet object).
Now if the method does not exist the sketch displays an error message and ends. That seems fair enough because if the programmer tried to register the pre method it obviously needed the pre method.
Processing also provides the
unregister???(PApplet object).
method to reverse this action.
This is where it gets interesting because if the programmer attempts to unregister a method that has not been previously registered then again the sketch displays an error message and ends. But why not just throw an exception (to be caught)? Why end the sketch? After all if there is no pre method then attempting to unregister it will not affect the program logic.
I suspect that most library creators this is not a problem but in G4P controls can hook into any or all of
pre
draw
keyEvent
mouseEvent
and the library allows the programmer to dispose of GUI controls no longer needed. In this case I want to unregister all the methods associated with the control and to do that safely each control tracks which methods it is currently registered for.
Now there could be a very good reason for the current logic of shutting down the sketch when attempting to unregister a non-registered library methods that I have failed to see. So I would be interested in hearing other arguments for and against.
register???(PApplet object).
Now if the method does not exist the sketch displays an error message and ends. That seems fair enough because if the programmer tried to register the pre method it obviously needed the pre method.
Processing also provides the
unregister???(PApplet object).
method to reverse this action.
This is where it gets interesting because if the programmer attempts to unregister a method that has not been previously registered then again the sketch displays an error message and ends. But why not just throw an exception (to be caught)? Why end the sketch? After all if there is no pre method then attempting to unregister it will not affect the program logic.
I suspect that most library creators this is not a problem but in G4P controls can hook into any or all of
pre
draw
keyEvent
mouseEvent
and the library allows the programmer to dispose of GUI controls no longer needed. In this case I want to unregister all the methods associated with the control and to do that safely each control tracks which methods it is currently registered for.
Now there could be a very good reason for the current logic of shutting down the sketch when attempting to unregister a non-registered library methods that I have failed to see. So I would be interested in hearing other arguments for and against.