Proposal: namespace the SPL

php.internals

Levi Morrison

5 years ago
Hello, everyone, There has been a lot of disagreement about namespacing, and people seem to have different viewpoints. I am not sure how to reconcile this broader discussion. However, there are certain names in the global namespace which I am hopeful we can revolve. For instance, `SplObserver`, `SplQueue`, `SplFixedArray`, etc all follow the `Spl` prefix. There is already an established "namespace" for these names. So here is my limited proposal: 1. We create names in the `Spl` namespace that are aliases to their equivalent types with the `Spl` prefix: `Spl\FixedArray` -> SplFixedArray `Spl\Queue` -> SplQueue a. The new names are the aliases so any code which uses `get_class($obj)` will not have the name change on them in a minor release (8.1). b. We may switch the direction of this alias in 9.0. 2. Any new types going into `ext/spl` use the `Spl` namespace. New types added to `ext/spl` should be either related to data structures or iterators, which is the bulk of what the SPL is. a. This rule is to help prevent the SPL from becoming the dumping grounds for new types. 3. We leave functions alone for now. Let me know what you think. I am hopeful this approach will work because: 1. It is focused on a specific area which already has an established "namespace", but in name-only (not technically). 2. It does not try to solve the larger problem, which has a lot of disagreement. 3. I will be proposing new types for ext/spl soon (`ReverseIterator` and an array iterator that is more efficient than `\ArrayIterator`), and Tyson Andre has already proposed `CachedIterable` and company which is in `ext/spl`, so this space has active development. Thank you for your time.

Mark Randall

5 years ago
On 11/02/2021 16:39, Levi Morrison wrote:
> Let me know what you think. I am hopeful this approach will work because: > 1. It is focused on a specific area which already has an established > "namespace", but in name-only (not technically). > 2. It does not try to solve the larger problem, which has a lot of > disagreement. > 3. I will be proposing new types for ext/spl soon (`ReverseIterator` > and an array iterator that is more efficient than `\ArrayIterator`), > and Tyson Andre has already proposed `CachedIterable` and company > which is in `ext/spl`, so this space has active development. > > Thank you for your time. >
Do you want a dumping ground? Because this is how you create a dumping ground :-) If we're going to start putting things into namespaces (and we should) then we should absolutely avoid repeating the mistakes of the past by dumping completely unrelated things together. If SPL\ is to exist (and personally I think SPL is so cancerous, it shouldn't) then IMO it must absolutely be SPL\iterators. Without that all we've done is swap one problem for another. The idea of putting data structures next to generic iterator helpers is, quite frankly, nuts. Mark Randall

Rowan Collins

5 years ago
On 11/02/2021 16:39, Levi Morrison wrote:
> 2. Any new types going into `ext/spl` use the `Spl` namespace. New > types added to `ext/spl` should be either related to data structures > or iterators, which is the bulk of what the SPL is. > a. This rule is to help prevent the SPL from becoming the dumping > grounds for new types.
I think having this rule mentioned and agreed somewhere at least is a good idea. We could perhaps in future look at moving those parts currently labelled as "spl" which *don't* fall into those categories somewhere else. It's weird that you can now _only_ use autoloading via a function prefixed "spl_", even though it's a language feature. Regards,
-- Rowan Tommins [IMSoP]

Unnamed Person

5 years ago
On Thu, Feb 11, 2021 at 9:39 AM Levi Morrison <levim@php.net> wrote:
> > Hello, everyone, > > There has been a lot of disagreement about namespacing, and people > seem to have different viewpoints. I am not sure how to reconcile this > broader discussion. > > However, there are certain names in the global namespace which I am > hopeful we can revolve. For instance, `SplObserver`, `SplQueue`, > `SplFixedArray`, etc all follow the `Spl` prefix. There is already an > established "namespace" for these names. > > So here is my limited proposal: > 1. We create names in the `Spl` namespace that are aliases to their > equivalent types with the `Spl` prefix: > `Spl\FixedArray` -> SplFixedArray > `Spl\Queue` -> SplQueue > a. The new names are the aliases so any code which uses > `get_class($obj)` will not have the name change on them in a minor > release (8.1). > b. We may switch the direction of this alias in 9.0. > 2. Any new types going into `ext/spl` use the `Spl` namespace. New > types added to `ext/spl` should be either related to data structures > or iterators, which is the bulk of what the SPL is. > a. This rule is to help prevent the SPL from becoming the dumping > grounds for new types. > 3. We leave functions alone for now. > > Let me know what you think. I am hopeful this approach will work because: > 1. It is focused on a specific area which already has an established > "namespace", but in name-only (not technically). > 2. It does not try to solve the larger problem, which has a lot of > disagreement. > 3. I will be proposing new types for ext/spl soon (`ReverseIterator` > and an array iterator that is more efficient than `\ArrayIterator`), > and Tyson Andre has already proposed `CachedIterable` and company > which is in `ext/spl`, so this space has active development. > > Thank you for your time. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >
There's been a lull in feedback, so let me steer it towards a specific point that was brought up: how do you feel about adding aliases from \Spl\Thing to \SplThing? https://strawpoll.com/22pcxh69p

Unnamed Person

5 years ago
On Thu, Feb 18, 2021 at 7:48 AM Levi Morrison <levi.morrison@datadoghq.com> wrote:
> > On Thu, Feb 11, 2021 at 9:39 AM Levi Morrison <levim@php.net> wrote: > > > > Hello, everyone, > > > > There has been a lot of disagreement about namespacing, and people > > seem to have different viewpoints. I am not sure how to reconcile this > > broader discussion. > > > > However, there are certain names in the global namespace which I am > > hopeful we can revolve. For instance, `SplObserver`, `SplQueue`, > > `SplFixedArray`, etc all follow the `Spl` prefix. There is already an > > established "namespace" for these names. > > > > So here is my limited proposal: > > 1. We create names in the `Spl` namespace that are aliases to their > > equivalent types with the `Spl` prefix: > > `Spl\FixedArray` -> SplFixedArray > > `Spl\Queue` -> SplQueue > > a. The new names are the aliases so any code which uses > > `get_class($obj)` will not have the name change on them in a minor > > release (8.1). > > b. We may switch the direction of this alias in 9.0. > > 2. Any new types going into `ext/spl` use the `Spl` namespace. New > > types added to `ext/spl` should be either related to data structures > > or iterators, which is the bulk of what the SPL is. > > a. This rule is to help prevent the SPL from becoming the dumping > > grounds for new types. > > 3. We leave functions alone for now. > > > > Let me know what you think. I am hopeful this approach will work because: > > 1. It is focused on a specific area which already has an established > > "namespace", but in name-only (not technically). > > 2. It does not try to solve the larger problem, which has a lot of > > disagreement. > > 3. I will be proposing new types for ext/spl soon (`ReverseIterator` > > and an array iterator that is more efficient than `\ArrayIterator`), > > and Tyson Andre has already proposed `CachedIterable` and company > > which is in `ext/spl`, so this space has active development. > > > > Thank you for your time. > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > There's been a lull in feedback, so let me steer it towards a specific > point that was brought up: how do you feel about adding aliases from > \Spl\Thing to \SplThing? > > https://strawpoll.com/22pcxh69p
It's been about a week. Current standings out of 33 total votes: "I think they are important to the proposal." => 16 votes (~48%) "I prefer them to not be aliased." => 11 votes (~33%) "I don't care about them." => 6 votes (~18%) I'll think more about the discussion so far and these results and then either adjust or drop the proposal.