Defensive Programming: Difference between revisions

From Resonite Wiki
Created a page for defensive programming in resonite.
 
Added a section on spamming impulses and how to prevent it.
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


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|world]]. These unexpected occurrences may lead to your code breaking, revealing sensitive information, or some other unfavorable event or action.
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|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 ==
== Strategies ==
Line 10: Line 12:


To check against that, using the [[ProtoFlux:Parse|Parse]] node's <code>IsParsed</code> field to check if that user's input is correctly parsed. Also using the [[ProtoFlux:Is Digit|Is Digit]] node can be just as effective when checking.
To check against that, using the [[ProtoFlux:Parse|Parse]] node's <code>IsParsed</code> field to check if that user's input is correctly parsed. Also using the [[ProtoFlux:Is Digit|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 [[Impulses|impulse]] in ProtoFlux, using the [[ProtoFlux:Local Impulse Timeout|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 [[ProtoFlux:One Per Frame|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 ==
== See Also ==
* [https://en.wikipedia.org/wiki/Defensive_programming Defensive Programming]
* [https://en.wikipedia.org/wiki/Defensive_programming Defensive Programming]

Latest revision as of 10:44, 17 July 2024

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