Re: PEAR2 package naming standards (namespace usage)

From: Date: Wed, 27 Aug 2008 22:20:47 +0000
Subject: Re: PEAR2 package naming standards (namespace usage)
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-50663@lists.php.net to get a copy of this message
Unless my point was made wrong this is how I fealt as well. I wanted the structure to be either: PEAR2::Services::Shipping PEAR2::Services::Shipping::XML Obviously with casing varying on this discussion. Sorry if this reply is in haste, still catching up on the mailing list, so I might reply again about this shortly. On Wed, Aug 27, 2008 at 12:01 PM, David Jean Louis <izimobil@gmail.com>wrote: > Joshua Eichorn a écrit : > >> Trimming to point out a major misunderstanding of namespaces. >> > > *sigh*, thanks Josh but I know what namespaces are, I used them *way* > before php5. > > David Jean Louis wrote: >> >>> Hey there, >>> >>> I really prefer the initial proposal (replace all _ with ::), IMHO the >>> svn:externals problem should not dictate the namespace naming decision. >>> >>> With the current proposal, what if I want to do the following ? >>> >>> <?php >>> // my script want to use Console_CommandLine *and* Console_Color >>> use PEAR2::Console; >>> >>> $commandline = new CommandLine(); >>> $color = new Color(); >>> >>> // etc... >>> ?> >>> >> Namespaces have no relation to one another, each and every class has to be >> brought in with a use line. >> > > No, this is just plain wrong: > > 1. namespaces *have* a relation in the sense they share the same root: > in my example "PEAR2::Console", so (even if my example is bad chosen) I > want to be able to do: > > <?php > use PEAR2::Console; > $a = new Console::CommandLine(); > $b = new Console::Color(); > ?> > (sorry, Console:: prefix was missing in my previous mail). > > ok ? > > 2. the real benefit of the "use" keyword is to work inside a namespace > without having to type the "path" each time you want to use something that > lives under it. > If, as you say, "each and every class has to be brought in with a use > line", well... what's the point of this "use" keyword ?! > > >> so it would be >> >> use pear2::console_commandline::CommandLine; >> use pear2::console_color::Color >> >> There is no benefit to deep trees, these aren't Java packages or anything >> hugely useful. They are a method to type shorter class names in code and >> thats it. >> >> Hmm... see my "drivers" or "adapters" example in my previous mail. > I don't want to type the same path every time, and I don't want to have a > "use" statement for each class I instanciate... > > Let's take the example of Services_Shipping: > > In reply to Kristopher, you mention the namespaces would be: > pear2::services_shipping_ups::Driver > pear2::services_shipping_dhl::Driver > > IMO this is wrong (and even cause a conflict if you want to instanciate the > two drivers, unless you use the "as" construct). > > to me: > > <?php > use pear2::services::shipping::driver; > $ups = new driver::UPS(); > $dhl = new driver::DHL(); > ?> > > is way better than: > > <?php > use pear2::services_shipping_ups::Driver as UPSDriver; > use pear2::services_shipping_dhl::Driver as DHLDriver; > $ups = new UPSDriver(); > $dhl = new DHLDriver(); > ?> > > > Now I even more prefer the initial proposal (s/_/::/) :p > > -- > David > > > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.pear.dev (#50663) next »