Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41955 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44107 invoked from network); 17 Nov 2008 07:40:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2008 07:40:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=christopher.vogt@rwth-aachen.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=christopher.vogt@rwth-aachen.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain rwth-aachen.de from 134.130.7.73 cause and error) X-PHP-List-Original-Sender: christopher.vogt@rwth-aachen.de X-Host-Fingerprint: 134.130.7.73 mta-2.ms.rz.RWTH-Aachen.DE Solaris 10 (beta) Received: from [134.130.7.73] ([134.130.7.73:40342] helo=mta-2.ms.rz.rwth-aachen.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/5D-39815-FEF11294 for ; Mon, 17 Nov 2008 02:40:33 -0500 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; charset=ISO-8859-1 Received: from ironport-out-1.rz.rwth-aachen.de ([134.130.5.40]) by mta-2.ms.rz.RWTH-Aachen.de (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTP id <0KAG00IK1VZHRM00@mta-2.ms.rz.RWTH-Aachen.de> for internals@lists.php.net; Mon, 17 Nov 2008 08:40:29 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.33,617,1220220000"; d="scan'208";a="90617246" Received: from zelos.rz.rwth-aachen.de (HELO relay-auth.rwth-aachen.de) ([134.130.3.23]) by ironport-in-1.rz.rwth-aachen.de with ESMTP; Mon, 17 Nov 2008 08:40:29 +0100 Received: from [192.168.1.127] (alania-134-130-78-10.una.RWTH-Aachen.DE [134.130.78.10] (may be forged)) (authenticated bits=0) by relay-auth.rwth-aachen.de (8.13.8/8.13.1/1) with ESMTP id mAH7eSuH013493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 17 Nov 2008 08:40:28 +0100 Message-ID: <49211FED.3020302@rwth-aachen.de> Date: Mon, 17 Nov 2008 08:40:29 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666 To: php@stefan-marr.de Cc: internals@lists.php.net References: <002b01c92d67$ae92fdc0$0bb8f940$@de> <79.C8.07308.CDE4C194@pb1.pair.com> <49203DF2.1020006@stefan-marr.de> In-reply-to: <49203DF2.1020006@stefan-marr.de> X-Enigmail-Version: 0.95.7 OpenPGP: Subject: Re: [PHP-DEV] Grafts, Traits, horizontal reuse From: christopher.vogt@rwth-aachen.de (Christopher Vogt) Hej, >> I really liked to see the Grafts proposal. > Well, I'm still in love with the more powerful (because they are > interweaveable(breakable)) Traits ;) I don't think there has to be a choice between Grafts and Traits. They serve different purposes and I don't see a reason they shouldn't co-exit. Traits implement code reuse. Code is merged. This is very powerful but can break code. Grafts implement delegation. This is less powerful, but can't break, which makes it preferable, whenever possible. > Actually I think this could be a problem for the conciseness of the > language. Introducing syntactic sugar for special situations has to be > done carefully. In my eyes (well-chosen) syntactic sugar contributes a lot to language conciseness. And every language decision should be done carefully, right? > from my perspective forwarding (aka > delegation) is a very common concept in OOP which would be worth to be > supported by a special syntax. I strongly think so. > I like this idea, but there are still some problems to be solved. The > major problem with grafts is still the initialization of objects. What > to do with constructors which require parameter? Good point. My new suggestion at the end covers it. > An other issue I see is the question of introducing to much additional > syntax. It could be reduced to something like: > > private $counter : Counter [use] { //with or without use? > public current(); > public reset(); > } I don't see the above having less syntax than my suggestion. "as" or ":" is both syntax. I doubt, I would rather stick to a keyword already in the language in similar semantics. For Comparison, my suggestion was: >> use Counter as private $counter{ >> public current(); >> public reset(); >> } > But now anonymous grafts aren't possible anymore and actually, Grafts > had been design without an identity own their own. Yes and I don't think anonymous Grafts would be a good idea. They would make access to grafts complicated and significantly limited including valid use cases. Being explicit instead of implicit helps here in my eyes. > On the other hand, > this notation could introduce the possibility for advanced initialization: > > private $cntInitValue; > public function __construct($cntValue) { > $this->cntInitValue = $cntValue; > } > > private $counter : Counter(cntInitValue) { > public current(); > public reset(); > } I don't think that's a good idea. I admit it's very close to my suggestion, but now it reached a point, where it does something very familiar, namely creating an new object, using a very unfamiliar way and also new syntax. So I make a new suggestion that puts everything much closer to present PHP: > class QueueTicketPrinter{ > private $counter { > public current(); > public restart() from reset(); > }; > > public function __construct($cntValue) { > $this->counter = new Counter( $cntValue ); > } > > public function takeNumber(){ > print 'your number is ".$this->current(); > $this->counter->inc(); > } > } And two syntax variants: Variant 1: > private $counter use { > public current(); > reset() as public restart(); > }; Variant 2: > private $counter delegate { > public current(); > public restart() to reset(); > }; This suggestion requires a new runtime Error/Exception for cases when a method of QueueTicketPrinter is called that is delegated to a method that $counter does not implement. > Every time you just like to compose a class from different kinds of > behaviors Traits are superior. More powerful yes, superior no. Delegation and inheritance (counting traits as a variant of inheritance) both allow functionality re-use but both also resemble a trade-off between flexibility and "breakability". Inheritance is more flexible, but can easily break, especially when inheritance structures grow. Delegation is less flexible, but can't break (from reuse), even in large structures. So both are justified. Best regards Christopher P.S. I should mention that I do not have any insight of the actual implementation of PHP. So if I suggest something insensibly hard to implement, just shout :).