Skip to content
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

Skip defined() checks, unnecessary multiplication #21

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

stevegrunwell
Copy link
Owner

In version 1.x, the constants were defined in the global namespace so it was responsible to explicitly check that, for instance, HOUR_IN_SECONDS was not already defined before attempting to define it.

Now that the constants are namespaced, this just adds unnecessary overhead: if someone else is defining constants in the TimeConstants namespace, there are bigger problems. Additionally, IDEs seem to trip over the defined() checks, not being sure that the constants exist. They do.

Similarly, while it was fun writing the intial constants in a way that they build upon each other, there's really no reason that this file should have to confirm (for example) that 24 hours * 60 minutes/hour = 1440 minutes/hour. These values do not change (hence constants), so save a little bit of basic multiplication by hard-coding the values.

In version 1.x, the constants were defined in the global namespace so it was responsible to explicitly check that, for instance, `HOUR_IN_SECONDS` was not already defined before attempting to define it.

Now that the constants are namespaced, this just adds unnecessary overhead: if someone else is defining constants in the `TimeConstants` namespace, there are bigger problems. Additionally, IDEs seem to trip over the `defined()` checks, not being sure that the constants exist. They do.

Similarly, while it was fun writing the intial constants in a way that they build upon each other, there's really no reason that this file should have to confirm (for example) that 24 hours * 60 minutes/hour = 1440 minutes/hour. These values do not change (hence *constants*), so save a little bit of basic multiplication by hard-coding the values.
@stevegrunwell stevegrunwell merged commit 2e000ae into develop Aug 22, 2024
3 checks passed
@stevegrunwell stevegrunwell deleted the feature/skip-defined-and-math branch August 22, 2024 21:02
@stevegrunwell stevegrunwell mentioned this pull request Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant