Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67104 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64926 invoked from network); 21 Apr 2013 22:36:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Apr 2013 22:36:21 -0000 Authentication-Results: pb1.pair.com header.from=igor@wiedler.ch; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=igor@wiedler.ch; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain wiedler.ch from 217.26.49.183 cause and error) X-PHP-List-Original-Sender: igor@wiedler.ch X-Host-Fingerprint: 217.26.49.183 mxout004.mail.hostpoint.ch Received: from [217.26.49.183] ([217.26.49.183:53312] helo=mxout004.mail.hostpoint.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 58/43-46657-3E964715 for ; Sun, 21 Apr 2013 18:36:20 -0400 Received: from [10.0.2.10] (helo=asmtp001.mail.hostpoint.ch) by mxout004.mail.hostpoint.ch with esmtp (Exim 4.72 (FreeBSD)) (envelope-from ) id 1UU2ro-000BR5-JH for internals@lists.php.net; Mon, 22 Apr 2013 00:36:16 +0200 Received: from [84.73.218.139] (helo=[10.0.1.96]) by asmtp001.mail.hostpoint.ch with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.72 (FreeBSD)) (envelope-from ) id 1UU2ro-000KAx-Cj for internals@lists.php.net; Mon, 22 Apr 2013 00:36:16 +0200 X-Authenticated-Sender-Id: igor@wiedler.ch Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) In-Reply-To: Date: Mon, 22 Apr 2013 00:36:15 +0200 Content-Transfer-Encoding: quoted-printable Message-ID: References: <5170E1F8.9060203@sugarcrm.com> To: "internals@lists.php.net" X-Mailer: Apple Mail (2.1503) Subject: Re: [PHP-DEV] Importing namespaced functions From: igor@wiedler.ch (Igor Wiedler) Let me give you two specific cases where I think importing a function significantly improves the readability of code. A) Tiny libraries I recently released a "library" that really just consists of two = functions. Those functions are named compose() and pipeline(), and the library is = named "igorw/compose". I didn't want to risk conflicts in the global = namespace, so I just put them in the "igorw" namespace. Now users need to do this: $x =3D igorw\compose('foo', 'bar', 'baz'); It's distracting to have my vendor name in there every time they call = the function. They can alias it, but then they just need to come up with a = random word that makes no sense. compose\compose(...); c\compose(...); foo\compose(...); B) Domain specific languages I hope I'm not mis-using the term "DSL" here, so just let me explain = what I mean. When building some kind of representation of something, it can = sometimes be quite nice to have a set of functions representing the elements, and = nest those calls. An example of this could be building HTML (you can apply it to building workflows, business rules, graphs, configuration, etc). use html\div, html\p, html\em; $html =3D div(p('Some', em('Text'))); Having to prefix the namespace in either of these cases leads to a lot = of noise. Hopefully that gives you a better idea of where I'm coming from. Regards, Igor