Defensive Programming

From Resonite Wiki

Defensive Programming is the abstract concept of writing code to prevent bugs from happening and preventing security breaches from what a user would input. This is in reference to an article on Defensive Programming on Wikipedia, but is implemented differently in a Resonite context.

When using ProtoFlux for your projects, you may run into an issue where something unexpected will happen when another user tries to use your created item, object, or world. These unexpected occurrences may lead to your code breaking, revealing sensitive information, or some other unfavorable event or action.

These provided strategies will help you in cases where unexpected or unknown problems may happen when developing your projects.

Strategies

User Input Checking

Using strings in a text field may give any user a chance to put in wrong information into the field (i.e. Typing a letter instead of a number in a text field, which may break code that only wants a number).

To check against that, using the Parse node's IsParsed field to check if that user's input is correctly parsed. Also using the Is Digit node can be just as effective when checking.

Spam Prevention

When a user is presented with a button, there is always the chance of them spamming the button to see what happens. This could overflow with a lot of data, bandwidth, or effects which could lead to breakages or crashes.

To prevent the spam of an impulse in ProtoFlux, using the Local Impulse Timeout node and setting the amount of time to wait before allowing another pulse to go through, will limit the frequency of that connected pulse wire.

Similarly, the One Per Frame node only sends out a pulse once per frame, preventing the spam of impulses that would be fired multiple times within that frame.

See Also