-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add assertions throughout the code to provide guarantees (not just comments) #706
Comments
The main issue I have with this is I believe |
If asserts can be placed in macros then to some extent, the asserts can be automatic in places where the assembly code makes assumptions about order / value. Trust me, you do not want to be debugging an issue where an order or value assumption changes, it can be completely invisible in the code. |
I think obvious "none" constants don't need any assert. It should be obvious that But there are many cases where a constant is 0 because it's simply the first field of a struct or the first element in an enum, and those might be worth asserting. |
I agree that zero constants are generally obvious, like (For example, Anyway,
Suggestion:
Suggestion:
Suggestion:
Suggestion:
Suggestion: |
Assertions are also ideal for code that was optimized by assuming certain conditions. pokecrystal itself never uses any
|
Another: zero constants are generally obvious, one constants less so.
Suggestion: |
Assertions can also be used for sanity checks of macro arguments, and to give better error messages.
|
Macros should definitely be checked for value ranges, but that's a pain that nobody's bothered to do yet. |
Good idea for Speaking of offsets, there might be some others which are currently defined as plain |
Another bank assertion: |
The radio random pointer tables that have size 16 and thus don't use a rejection sampling loop could also use assertions. |
Most of the assertions discussed here have been added in PR #776. There are probably opportunities for more, and the ones added should be reviewed. |
One place where assertions would be helpful is for wild data. Each map requires exactly the right amount of entries, and too many/few will corrupt that map and all subsequent ones. Consider refactoring this:
into this:
|
Other assertions could be added at the end of various data tables. For example, in data/maps/roofs.asm,
This could be generalized to |
Regarding general-purpose table macros:
|
Some code is written assuming that a constant has a certain value; or is divisible by some quantity; or that one struct field is a certain offset from another; or that two maps are in the same group; or two graphics in the same bank; and so on. These can be documented with
assert
better than with comments.The text was updated successfully, but these errors were encountered: