Skip to content

Remove senseless spec.#1140

Merged
andrykonchin merged 1 commit intomasterfrom
remove_senseless_spec
Mar 11, 2024
Merged

Remove senseless spec.#1140
andrykonchin merged 1 commit intomasterfrom
remove_senseless_spec

Conversation

@marcandre
Copy link
Copy Markdown
Member

@marcandre marcandre commented Mar 5, 2024

A negative size makes no sense at all, -infinity even less so. It is indeed the case that Ruby currently returns -infinity (even if you take the product of two of these senseless enumerables), but that doesn't make it a valid spec. Ruby does this because it is simpler to test for ±infinity than it is to test for +infinity...

Other alternative implementations should not attempt to mimick such behaviour.

One could argue it is a bug (and nil should be returned maybe, but that would be the case for any negative size), or that the current result is acceptable because "garbage in garbage out", but nobody in their right mind would rely on this behavior and clearly returning nil or raising an exception are better results than returning - infinity.

This PR leaves this uninteresting and ill-defined corner case as implementation dependent.

Ref: marcandre/backports#192

marcandre added a commit to headius/backports that referenced this pull request Mar 5, 2024
Let's not go out of our way to return senseless results.
See ruby/spec#1140
A negative `size` makes no sense at all, -infinity even less so. It is indeed the case that Ruby currently returns `-infinity` (even if you take the product of two of these senseless enumerables), but that doesn't make it a _valid spec_. Ruby does this because it is simpler to test for ±infinity than it is to test for +infinity...

Other alternative implementations should _not_ attempt to mimick such behaviour.

One could argue it is a bug (and `nil` should be returned maybe, but that would be the case for any negative `size`), or that the current result is acceptable because  "garbage in garbage out", but nobody in their right mind would rely on this behavior and clearly returning `nil` or raising an exception are better results than returning - infinity.

This PR leaves this uninteresting and ill-defined corner case as implementation dependent.
@marcandre marcandre force-pushed the remove_senseless_spec branch from a736652 to 8fd23da Compare March 5, 2024 20:18
@andrykonchin
Copy link
Copy Markdown
Member

Agree!

Wondering if it makes sense to have means to specify explicitly in specs that some case has undefined behaviour or implementation-specific one? In case a CRuby behaviour is considered as not accurate?

@andrykonchin andrykonchin merged commit f23d158 into master Mar 11, 2024
@andrykonchin andrykonchin deleted the remove_senseless_spec branch March 11, 2024 11:19
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.

2 participants