Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20463 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 752 invoked by uid 1010); 25 Nov 2005 23:12:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 737 invoked from network); 25 Nov 2005 23:12:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Nov 2005 23:12:36 -0000 X-Host-Fingerprint: 65.9.87.49 adsl-9-87-49.mia.bellsouth.net Received: from ([65.9.87.49:21215] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 6B/D8-56276-36A97834 for ; Fri, 25 Nov 2005 18:12:35 -0500 To: internals@lists.php.net,Sara Golemon Message-ID: <43879A60.30704@gmail.com> Date: Fri, 25 Nov 2005 18:12:32 -0500 User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <7.0.0.16.2.20051124161240.0573e640@zend.com> <90.0E.56276.6D207834@pb1.pair.com> <200511251419.56809.pookey@pookey.co.uk> <57.B8.56276.65B27834@pb1.pair.com> <73998811.20051125204046@marcus-boerger.de> <438782C6.80008@gmail.com> <43878626.5060300@lerdorf.com> <512771162.20051125225926@marcus-boerger.de> <43878C41.4030205@gmail.com> <43878D08.4020105@lerdorf.com> <013901c5f20f$631a5af0$7d051fac@stumpy> In-Reply-To: <013901c5f20f$631a5af0$7d051fac@stumpy> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 65.9.87.49 Subject: Re: [PHP-DEV] Re: PHP 5.1 (Or How to break tousands of apps out there) From: jrhernandez05@gmail.com (Jessie Hernandez) Hi Sara, Sara Golemon wrote: >> Forcing whitespace here isn't an option. It is completely >> inconsistent with the rest of PHP. >> > It's also a conversation that was had before PHP5.0 was ever released > (when namespaces were first being attempted). > > Anyone remember the term "syntactic sugar"? You may be suprised by me saying this, but in a sense, yes, all of this is just syntactic sugar. When you type "namespace ns{ class class1{} }", all I'm doing is registering the class as "ns:class1". The user can easily just name their class ns_class1 and the same effect can be achieved. If you use full class names all the time, then I agree, there is no difference between ns:class1 and ns_class1. Even when you have two identically named classes in two different namespaces and you import them (with different aliases, of course) this still can be considered "syntactic sugar", as the writers of both classes were wise enough to namespace them in the first place (they are wise enough to simply prefix them too!). The difference is actually in the following (off the top of my head): 1) "Enterprise-readiness" perception - Having no "namespace support" in the language makes it look crappy to people who want to use the language, especially for people who come from the Java world (please, no flame wars, I am NOT comparing PHP to Java, I am merely mentioning this perception). 2) Encouraging users to prefix their own classes - When you start writing in Java, you immediately notice that all classes, even the language-default ones, are inside a namespace. The convention of a reverse-domain name is even mentioned when you learn the language. This encourages users to namespace their own classes, as it makes their code look more organized. The language's Date class is inside java.util. If you wanted to write your own Date class, you will naturally place it inside your own package. Even if you put it under no package, there still would be no conflict! This is what I see happening for PHP: all core classes would go under a php namespace, so we'd have php:Date and PEAR:Date, for example. 3) Aliasing - Right now you're stuck with whatever name the class has. Consider this scenario: I am building a page and I am using HTML_QuickForm. Inside the form I want to have multiple multi-select boxes. My code would look like this: $a = new HTML_QuickForm_advmultiselect(...); $b = new HTML_QuickForm_advmultiselect(...); This is a lot of typing. The following looks much cleaner: import class HTML:QuickForm:advmulitselect as multiselect; $a = new multiselect(...); $b = new multiselect(...); Simply put, namespaces makes code look cleaner, even though internally the same prefixing is being used to accomplish this. Since the prefixing is done by the engine itself, and we have aliasing, I wouldn't call this "sugar", I'd prefer to call it syntactic "complex carbs" ;-). Regards, Jessie