Use 'do' prefix to designate methods used as part of internal class hierarchy delegation pattern

Created on 7 June 2013, over 11 years ago
Updated 12 August 2024, 5 months ago

Symfony follows a somewhat established pattern when creating class hierarchy-internal APIs - typically, interactions between a base class that implements an interface, and subclasses of that base class that extend the base implementation provided - see, for example, the EventDispatcher:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Eve...
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Eve...

We've had a few debates around this kind of thing before. Example: prepending an underscore used to be in vogue, but was criticized at least for being a PHP4 convention as it was used to indicate a method was private - that became redundant with the native language support for visibility. IMO, there's no really ideal word to put there, but 'do' is at least nice because it's short, and actually does describe what's often happening: the base class is delegating the actual *doing* of the work to a subclass by calling this internally-agreed-upon method.

So I figure, this seems like another Symfony convention that it wouldn't hurt us to adopt. I've started by patching block plugins because I know we tried to achieve this same pattern by prepending the public interface method with 'block'. I'd argue that not only does 'do' make more sense for the block plugin case in particular, but there is good reason to adopt this as a convention even in cases where it may make a bit less sense: a consistent prefix helps to identify a consistent design pattern that *is* the exact same across all these different use cases. That is, were we to adopt this convention and I had never seen block plugins before, but I was aware of the convention, then by simply skimming the method list I would immediately know that this type of pattern is at play, and I could reasonably infer the relationship between the do-prefixed methods, the corresponding prefix-less methods, and the public interface.

There might be other examples of it, though, and if so then we should fix em all together at once.

...assuming we can agree that this is a good idea. :)

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States sdboyer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    This could be something to decide in the Coding Standards project and there is merit in consistency. But then, it has been 11 years and there aren't other comments here in support of this renaming. And now, the renaming would also have to be backwards compatible which add more work.

    Does anyone support this work?

    I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024