Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33717 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98669 invoked by uid 1010); 5 Dec 2007 06:50:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 98654 invoked from network); 5 Dec 2007 06:50:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Dec 2007 06:50:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=nlgordon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nlgordon@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.189 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: nlgordon@gmail.com X-Host-Fingerprint: 209.85.198.189 rv-out-0910.google.com Received: from [209.85.198.189] ([209.85.198.189:65359] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/40-29996-A2A46574 for ; Wed, 05 Dec 2007 01:50:19 -0500 Received: by rv-out-0910.google.com with SMTP id k15so3758213rvb for ; Tue, 04 Dec 2007 22:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=dTPpjduvAiTUNU5rMeWoIm6MMHDjxPK1xp3eadjqkOQ=; b=oNuAD7vwJYGGqd8LcVybNCSH0mjNw3gKzW2Loaz+/as8RteC2VA/NnuIArzvcyrz0ejt9l5bcDrZG08HRpidKT+gHgK/WfTfCJ0fSgljp8RBFwWVQu2s1WnxK5XwJf5YmHr5rE68WrfCyFxr7eAL0Pr7fY6d3+i5kbOyrwiK+Gs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=eqhnSUOw95lyTXg/6wSuI17i/SfquJyj8jtpAd4JCZCIBWPfyu7Kkd0DgIBi9Ngh1sVHw91g+tJ5D3QPr6EVd304wPx92VtpVYjV9VGRT+lAhTSIsKOaPavZgCWZSzf7442nrIKR1KPo2lF/DYk5WstcUuDJapz7UQ8CjHzbtv8= Received: by 10.140.139.3 with SMTP id m3mr937501rvd.1196837416121; Tue, 04 Dec 2007 22:50:16 -0800 (PST) Received: by 10.140.225.6 with HTTP; Tue, 4 Dec 2007 22:50:16 -0800 (PST) Message-ID: Date: Wed, 5 Dec 2007 00:50:16 -0600 To: "Robert Cummings" Cc: internals@lists.php.net In-Reply-To: <1196829384.14915.6.camel@blobule> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200712042226.08192.larry@garfieldtech.com> <1196829384.14915.6.camel@blobule> Subject: Re: [PHP-DEV] RFC: Dropping Namespace From: nlgordon@gmail.com ("Nate Gordon") On Dec 4, 2007 10:36 PM, Robert Cummings wrote: > > On Tue, 2007-12-04 at 22:26 -0600, Larry Garfield wrote: > > On Tuesday 04 December 2007, Derick Rethans wrote: > > > > > 4. What is wrong with simple prefixes in the first place? Both PEAR_*, > > > Zend_*, ezc*, and ezp* are perfectly acceptable markers for different > > > 'namespaces'. We could optionally create a registry on php.net for > > > this to avoid conflicts. > > > > Although most people on the list seem to be coming at this problem assuming > > classes, I want to offer a counter-example that is all functions. > > > > In Drupal, our plugin architecture is based on function naming. When a given > > event "omg" occurs, something akin to the following frequently happens (a bit > > simplified): > > > > $hook = 'omg'; > > foreach ($modules_that_are_loaded as $module) { > > $function = $module .'_'. $hook; > > if (function_exists($function)) { > > $return[] = $function(); > > } > > } > > return $return; > > > > It's a very powerful mechanism, and quite flexible. The one thing it doesn't > > offer is, given a function name, determine what module and hook/event it is > > for. That's because we use PHP core coding standards, which say to use > > function_name for all functions. So given this function name: > > > > views_do_stuff() > > > > Is that the "do stuff" hook from the "views" module/plugin, or the "stuff" > > hook from the "views_do" module? Excellent question, and one that cannot be > > reliably solved. (There is a module called "views", but nothing is stopping > > anyone from writing a "views_do" module and declaring their own "stuff" > > hook.) > > > $hook = 'omg'; > foreach ($modules_that_are_loaded as $module) > { > $function = $module .'__'. $hook; > if (function_exists($function)) > { > $return[] = $function(); > } > } > return $return; > > ?> > > There ye have it! > > > list( $module, $hook ) = explode( '__', $function ); > > ?> > > Namespace support is for people who didn't name their classes/functions > properly. I'm not for or against it. To paint namespaces with such a broad brush isn't terribly fair. I see other languages such as Java/Perl/C++ using packages/namespace foo in much the same way I see some people wanting to use it here. As a way to shorten really long class names while reducing conflicts. This isn't a new feature to programming in general. The problem I see going on here is the desire by some to make it do everything _and_ wash the dishes. While noble and probably well intentioned, does feature X really serve the greater good? It can't solve every problem and still be something that people want to use. Php already has a ton of stuff in the global namespace, so I don't know that namespaces can fix collisions/BC overnight. Once namespaces have a foothold then people can start looking at how to migrate all the stuff in the global namespace outwards without causing major problems. While PHP::Time::DateSpan might seem silly to some, it seems fairly normal in the other languages I program in (Java, Perl). I would also be perfectly fine with php core laying claim to Time::*. Its just a fact of life that the global namespace has a limited amout of real estate and people can't just go snatching up all the good names just because they were there first. I vote for starting small. Add namespaces. Allow people to do basic use statements. I would even be in favor of multiple namespaces per file, but would prefer if they were wrapped in {} (it seems more consistent and easier to mentally parse) otherwise I don't care. From reading emails today I hope this might be some sort of middle ground that might prevent completely tossing out this feature. Having said all of that, you can't stop bad programmers from doing at least something wrong. Especially not in a language like PHP where you are given so much freedom to do what you want. -- -Nathan Gordon If the database server goes down and there is no code to hear it, does it really go down? :wq