10000 [Contracts/Deprecation] don't use assert(), rename to trigger_deprecation() by nicolas-grekas · Pull Request #35648 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Contracts/Deprecation] don't use assert(), rename to trigger_deprecation() #35648

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

Merged
merged 1 commit into from
Feb 8, 2020

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR is a follow up the discussion that happened in #35526.

I applied all the suggestions I received so far on this previous PR so that we can discuss them all together.

Here are the changes:

  • the most important change is to not use assert() anymore. This fixes the objection from @ostrolucky and @derrabus that deprecations and assert() should not be bound to each other. Instead, in order to still make the function a no-op when wanted, it is suggested that apps declare an empty function. This will be more flexible in practice I believe and keeps all the benefits we envisioned by using assert();
  • as suggested by @fabpot, the function is renamed trigger_deprecation() instead of deprecated(). Because the implementation is now not conditional anymore (from the package pov, since assert() is not used), my arguments to keep the previous name don't stand as strong as before to me so I'm fine renaming.
  • type hints are added back (requiring PHP 7.1 to use void). As mentioned in the 1st point, ppl that really want deprecations to be no-ops will redeclare the function as empty, thus not using any types, thus reclaiming all the perf diff. And for ppl that do want to catch deprecations, the overhead of types is negligible compared to any processing of the deprecations themselves.

WDYT?

All points can be discussed separately if needed of course. I'm personally fine with merging the PR as is, with all 3 changes.

Copy link
Contributor
@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

The example needs adjustment to remove the implicit cast. The rest of this is a great improvement in the implementation!

@nicolas-grekas nicolas-grekas changed the title [Contracts/Deprecation] dont use assert(), rename to trigger_deprecation() [Contracts/Deprecation] don't use assert(), rename to trigger_deprecation() Feb 8, 2020
Copy link
Contributor
@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Looks great!

@fabpot
Copy link
Member
fabpot commented Feb 8, 2020

Thank you for listening :)

@fabpot
Copy link
Member
fabpot commented Feb 8, 2020

Thank you @nicolas-grekas.

fabpot added a commit that referenced this pull request Feb 8, 2020
…trigger_deprecation() (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Contracts/Deprecation] don't use assert(), rename to trigger_deprecation()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR is a follow up the discussion that happened in #35526.

I applied all the suggestions I received so far on this previous PR so that we can discuss them all together.

Here are the changes:
- the most important change is to *not* use `assert()` anymore. This fixes the objection from @ostrolucky and @derrabus that deprecations and assert() should not be bound to each other. Instead, in order to still make the function a no-op when wanted, it is suggested that apps declare an empty function. This will be more flexible in practice I believe and keeps all the benefits we envisioned by using assert();
- as suggested by @fabpot, the function is renamed `trigger_deprecation()` instead of `deprecated()`. Because the implementation is now not conditional anymore (from the package pov, since assert() is not used), my arguments to keep the previous name don't stand as strong as before to me so I'm fine renaming.
- type hints are added back (requiring PHP 7.1 to use `void`). As mentioned in the 1st point, ppl that really want deprecations to be no-ops will redeclare the function as empty, thus not using any types, thus reclaiming all the perf diff. And for ppl that do want to catch deprecations, the overhead of types is negligible compared to any processing of the deprecations themselves.

WDYT?

All points can be discussed separately if needed of course. I'm personally fine with merging the PR as is, with all 3 changes.

Commits
-------

0032b2a [Contracts/Deprecation] don't use assert(), rename to trigger_deprecation()
@fabpot fabpot merged commit 0032b2a into symfony:master Feb 8, 2020
@nicolas-grekas nicolas-grekas deleted the deprec-no-assert branch February 8, 2020 13:46
@derrabus
Copy link
Member
derrabus commented Feb 8, 2020

Thank you very much! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0