Chris Steipp submitted a patch add namespaces to the OAuth extension [0] in order to fix a compatibility issue with HHVM [1]. This change led to a bit of bikeshedding on the proper namespace to use for the extension. Chris initially chose `MWOAuth` but later amended to use `MediaWiki\Extensions\OAuth` at my suggestion.
There is some discussion in gerrit, but my primary arguments were made in irc (and in an unlogged channel no less), so I thought this topic would be worth dragging out in front of everyone for a little debate. I don't know of anyone who is actively trying to change MediaWiki core to use namespaces, but extensions are using them. This leads me to think that we should think as a group about the "right way" to use namespaces and how to chose namespaces.
I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me. PSR-4 [2] is very opinionated about namespaces. It requires a top-level (or vendor) namespace. I chose "MediaWiki" because ... MediaWiki. Beyond that sub-namespaces are optional, but the file system path from the base directory to the php file must match. Assuming that $IP is the base directory led me to suggest MediaWiki\Extensions\OAuth.
The loudest argument I've heard here (and elsewhere) about using namespaces like MediaWiki\Extensions\OAuth is that there are too many characters to type. This, in my opinion, is really a we-fear-change argument. With full PSR-4 namespacing, the longest fully qualified class name would be "MediaWiki\Extensions\OAuth\Frontend\SpecialPages\SpecialMWOAuthConsumerRegistration.php" [3]. I will give no argument that this is a short string. I will say however that I spent enough of my career working in java [4] on a codebase with fully qualified class names like "org.accessidaho.apps.itd.dlr.common.pLAZma_RestrictionModel" [5] to find out two things: you typically type a fully qualified class name once per file at most, and any reasonable editor can be configured to have tab completion and/or macro expansion for commonly typed strings.
[0]: https://gerrit.wikimedia.org/r/#/c/141608/ [1]: https://bugzilla.wikimedia.org/show_bug.cgi?id=66929 [2]: http://www.php-fig.org/psr/psr-4/ [3]: This could be shortened a bit by removing the embedded pseudo-namespacing [4]: "A witch! Burn him!" [5]: Not meant as an example of a good classname
Bryan
On Wed, Jun 25, 2014 at 12:30 AM, Bryan Davis bd808@wikimedia.org wrote:
Chris initially chose `MWOAuth` but later amended to use `MediaWiki\Extensions\OAuth` at my suggestion.
[...] I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me.
+2. Abbreviations are mostly annoying and not suited for class (or namespace) names. There's always the risk someone else already picked your two or three-letter abbreviation, which would eventually cause some issues for everyone involved, whereas there's only one "MediaWiki" out there.
The loudest argument I've heard here (and elsewhere) about using namespaces like MediaWiki\Extensions\OAuth is that there are too many characters to type.
That could then be used as an argument against the supermajority of our well-estabilished coding conventions. Why call a variable $enableEditing when $e (or $ee) requires far less typing? Let's just name variables from $a to $z and once we run out of valid single-letter vars, let's just use $aa, $bb, and so on, because it requires far less typing! (And produces far more messy and unreadable code. Oops!)
you typically type a fully qualified class name once per file at most, and any reasonable editor can be configured to have tab completion and/or macro expansion for commonly typed strings.
Ctrl+C and Ctrl+V have been a thing for quite a while, no?
Regards, -- Jack Phoenix MediaWiki developer
On 25/06/14 07:30, Bryan Davis wrote:
I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me. PSR-4 [2] is very opinionated about namespaces. It requires a top-level (or vendor) namespace. I chose "MediaWiki" because ... MediaWiki. Beyond that sub-namespaces are optional, but the file system path from the base directory to the php file must match. Assuming that $IP is the base directory led me to suggest MediaWiki\Extensions\OAuth.
I think it's fine.
In some cases, the vendor will be the extension name, which I think is fine also. For example, Packagist has a "wikibase" vendor and a "data-values" vendor, both created by Jeroen/WMDE, and they do already use Wikibase and DataValues respectively as their root namespaces, in accordance with their Packagist vendor names.
Along the same lines, one can also imagine a phpBB integration plugin for MediaWiki being phpBB\MediaWiki rather than MediaWiki\Extensions\phpBB.
-- Tim Starling
On Tue, Jun 24, 2014 at 2:30 PM, Bryan Davis bd808@wikimedia.org wrote:
I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me. PSR-4 [2] is very opinionated about namespaces. It requires a top-level (or vendor) namespace. I chose "MediaWiki" because ... MediaWiki. Beyond that sub-namespaces are optional, but the file system path from the base directory to the php file must match.
That's not quite accurate: PSR-4 fully qualified classnames have a namespace prefix corresponding to a base directory, but that prefix can have any number of components. So a class could be called, say, Wikimedia\CSteipp\OAuthExtension\Frontend\SpecialPages\ SpecialMWOAuthConsumerRegistration, the autoloader would be configured with 'Wikimedia\CSteipp\OAuthExtension' => "$IP/extensions/OAuth", and the file would be loaded from $IP/extensions/OAuth/Frontend/SpecialPages/ SpecialMWOAuthConsumerRegistration.php
(I am not disagreeing that MediaWiki\Extensions<extensionname> is the obvious choice, just noting that nothing in PSR-4 requires this.)
Le 24/06/2014 23:30, Bryan Davis a écrit :
I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me. PSR-4 [2] is very opinionated about namespaces. It requires a top-level (or vendor) namespace. I chose "MediaWiki" because ... MediaWiki. Beyond that sub-namespaces are optional, but the file system path from the base directory to the php file must match. Assuming that $IP is the base directory led me to suggest MediaWiki\Extensions\OAuth.
Hello,
Looks good to me =)
I don’t think there’s any need to impose a naming requirement for extension namespaces. Some vendors may choose to use their own namespace scheme.
In the end, as long as the namespace chosen is PSR-4 compliant, it should not matter. -- Tyler Romeo 0xC86B42DF
From: Antoine Musso hashar+wmf@free.fr Reply: Wikimedia developers wikitech-l@lists.wikimedia.org> Date: June 25, 2014 at 4:16:38 To: wikitech-l@lists.wikimedia.org wikitech-l@lists.wikimedia.org> Subject: Re: [Wikitech-l] What namespaces should we use when we use them
Le 24/06/2014 23:30, Bryan Davis a écrit :
I suggested MediaWiki\Extensions\OAuth because it seems like the most natural naming to me. PSR-4 [2] is very opinionated about namespaces. It requires a top-level (or vendor) namespace. I chose "MediaWiki" because ... MediaWiki. Beyond that sub-namespaces are optional, but the file system path from the base directory to the php file must match. Assuming that $IP is the base directory led me to suggest MediaWiki\Extensions\OAuth.
Hello,
Looks good to me =)
-- Antoine "hashar" Musso
_______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org