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

Clarify in docs that zero is not considered a positive-int #8060

Merged
merged 3 commits into from Jun 6, 2022

Conversation

bdsl
Copy link
Contributor

@bdsl bdsl commented Jun 6, 2022

I wasn't sure from reading the docs whether or not Psalm consider zero to be positive.

I wasn't sure from reading the docs whether or not Psalm consider zero to be positive.
@AndrolGenhald
Copy link
Collaborator

Idk, "positive" has always had a clear well established meaning to me 🤷

If we're going to bother changing it though, I would say:

positive-int only allows positive integers (equivalent to int<1, max>)

which provides the same information but also points people to the newer int range feature which is much more useful.

Speaking of, int ranges should probably be documented there as well, and we should make sure there aren't any other scalar types missing documentation.

@AndrolGenhald AndrolGenhald added release:docs The PR will be included in 'Docs' section of the release notes PR: Need review labels Jun 6, 2022
@bdsl
Copy link
Contributor Author

bdsl commented Jun 6, 2022

I like your version @AndrolGenhald. The way I was taught in school, 'positive' means >= 0, and 'strictly positive' means > 0. But in informal usages positive could mean either one.

@bdsl
Copy link
Contributor Author

bdsl commented Jun 6, 2022

Wikipedia gives both definitions of positive: https://en.wikipedia.org/wiki/Sign_(mathematics)#Terminology_for_signs

@AndrolGenhald
Copy link
Collaborator

Wow, I never realized there was differing terminology there, I've only ever known [non-]positive and [non-]negative!

@bdsl
Copy link
Contributor Author

bdsl commented Jun 6, 2022

btw the type I was actually looking for was the int<0,max> one. Probably a lot of use cases for that, counts of things, prices etc that can be zero or positive. Maybe worth a separate PR to create a non-negative-int type as an alias of that.

Probably not enough use cases for negative-int or non-positive-int to justify them going in, unless it's just to make the system more symmetrical.

@bdsl
Copy link
Contributor Author

bdsl commented Jun 6, 2022

at least with integers there's only one zero! Float has +0 and -0 of course.

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jun 6, 2022

Personally I've just moved to using int ranges everywhere, it's shorter and easier to understand. Before int ranges were introduced there were a lot of 0|positive-int around which also works fine, so I don't think there's really much need for new types here.

Edit: @orklah mentions here that apparently PHPStan supports negative-int, so in that case it might be worth adding just for feature parity, however unnecessary I think it is. There's also #7769 which was closed as soon as OP learned about int ranges (which should be documented better... I opened #8061 to make sure it doesn't get forgotten).

@@ -12,7 +12,7 @@ The type `scalar` is the supertype of all scalar types.

### positive-int

`positive-int` allows only positive integers
`positive-int` allows only positive integers (equivalent to int<1, max>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight nitpick: use backticks for int<1, max>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

@orklah
Copy link
Collaborator

orklah commented Jun 6, 2022

Oh, I thought I already added negative-int but I guess not. It should be easy to do if someone wants to add that

@orklah orklah merged commit d55988a into vimeo:4.x Jun 6, 2022
@orklah
Copy link
Collaborator

orklah commented Jun 6, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Need review release:docs The PR will be included in 'Docs' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants