Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67965 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84441 invoked from network); 27 Jun 2013 15:57:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 15:57:13 -0000 Authentication-Results: pb1.pair.com header.from=neclimdul@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=neclimdul@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.169 as permitted sender) X-PHP-List-Original-Sender: neclimdul@gmail.com X-Host-Fingerprint: 74.125.82.169 mail-we0-f169.google.com Received: from [74.125.82.169] ([74.125.82.169:34187] helo=mail-we0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/8A-34034-7D06CC15 for ; Thu, 27 Jun 2013 11:57:12 -0400 Received: by mail-we0-f169.google.com with SMTP id n57so727990wev.0 for ; Thu, 27 Jun 2013 08:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=FOvoXlXFL3gUrsoY5DPyKCR2DcXHhtP57qbeyZq3j10=; b=ukstna2Vi+NNMZpUW9x8rMSnEvRd2H3D5cyS52Z1SqOP0whMHYJkbE+MrwcN6GSL9J adnxnVXNW0KEMmxJ30nXf8cFUKsFae1vaip0gfFiu1KvZZl6ZolYTKf1st8sCFtO96vk 3pHrBZ6AKnYzccMtyN87IkEPi92+Kk/AKWITYOxtv3sVhJUeosL2UShoqorpYZ6OVutX ufp6zNKT87e7+/pSW18hGJE0PaNmm06OVAs5gkPe10Re9yfulvafARhCmKM3HwUz7Iyz SZKv2R0/MS7vHTcK4BTjbsoXgdx8KCtRUx/HuiRiwqa5YRmBV4/x9X3XJW/0aSEyq0zk TUqQ== MIME-Version: 1.0 X-Received: by 10.180.106.163 with SMTP id gv3mr6370172wib.53.1372348628982; Thu, 27 Jun 2013 08:57:08 -0700 (PDT) Received: by 10.194.56.65 with HTTP; Thu, 27 Jun 2013 08:57:08 -0700 (PDT) In-Reply-To: References: <51C9FA9C.8050403@sugarcrm.com> <51CA1C93.6080500@sugarcrm.com> <51CA24C5.9090505@sugarcrm.com> Date: Thu, 27 Jun 2013 10:57:08 -0500 Message-ID: To: Florin Patan Cc: Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f3ba52589e6cd04e024d0a9 Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: neclimdul@gmail.com (James Gilliland) --e89a8f3ba52589e6cd04e024d0a9 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Jun 27, 2013 at 10:50 AM, Florin Patan wrote: > On Wed, Jun 26, 2013 at 5:02 PM, Anthony Ferrara > wrote: > > Florin > > > >> Could you please point out what happened in the past 5 months in PHP > >> that changed the landscape so drastically as you say? And don't > >> mention folks reinventing the wheel in OOP because that's not news :) > > > > > > The point was that "best practice" is volatile and temporal, and changes > > depending on who you talk to. Therefore, it becomes a very poor criteria > to > > judge a language change by... > > > >> > >> And could you also please answer this question: what happens when this > >> code: > >> > >> // Third party Mighty Logger Library > >> interface Logger { > >> public function log($argument); > >> } > >> > >> // My beloved implementation > >> class Demo { > >> public function log($argument) {} > >> } > >> > >> class UseMe { > >> public function shazam( $logger) { > >> $logger->log('shazam'); > >> } > >> } > >> > >> $demo = new Demo(); > >> $useMe = new UseMe(); > >> > >> $useMe->shazam($demo); > >> > >> becomes > >> > >> // Third party Mighty Logger Library > >> interface Logger { > >> public function log($argument); > >> public function unlog($argument); > >> } > >> > >> // My beloved implementation > >> class Demo { > >> public function log($argument) {} > >> } > >> > >> class UseMe { > >> public function shazam( $logger) { > >> $logger->log('shazam'); > >> } > >> > >> // New method written by different enthusiastic programmer > >> public function kazam( $logger) { > >> $logger->unlog('kazam'); > >> } > >> } > >> > >> $demo = new Demo(); > >> $useMe = new UseMe(); > >> > >> $useMe->shazam($demo); > >> $useMe->kazam($demo); > >> > >> > >> How would IDE be able to provide any useful information in this case, > >> like they do now with type hints? > > > > > > The IDE would behave identically as it does now. The only way that the > IDE > > could provide you meaningful information today would be to track the > `$demo` > > variable from creation to being passed to those two methods. If the IDE > can > > track that and give you an error today, it can still give you the same > error > > tomorrow. Sure, if you implement the logger interface on Demo it can find > > the error, and there's nothing stopping you from doing that. The key is > that > > it's not *required*... > > Yeah, but you just made me to implement the interface in my class > which I don't want do, because of this feature. > And more often that not, I'm using third party libraries which will > have deeper implications. > > > And the key here is to realize that this feature is designed to decouple. > > And that comes at a cost (reducing the ability for static analysis). But > you > > gain a very significant amount of flexility by it. And that's worth it > IMHO. > > If you don't program that way, I completely understand. But it is a valid > > approach that's currently being used. > > Again, can you explain what is this decoupling you are talking about? > Sorry, I'm a bit confused. The fact that you have a interface from > another package in your implementation? And you depend on having that > package as well in your code? Or the fact that once you've written > implements PSR3LoggerInterface you'll have to implement all those > additional methods? (see below for the continuation) > > >> > >> Yes, it's a nice academic feature, but if I'm doing a code review, > >> when I see that a class implements a certain interface or a parameter > >> has a certain type-hint then I can be sure that I won't need to review > >> the interface and the implementation to match all the possible methods > >> in that class and if I'm using a third party app review that as well > >> to make sure that the guy who's using this 'weak type-hinting' aka > >> protocol type hinting as you call it won't mess up. > > > > > > In theory this sounds like a great argument. In practice, I don't think > it > > holds up. The main reason is that look at other languages. Look at Perl. > > Look at JavaScript Look at Python. Look at Ruby. Look at Go. Look at C. > Look > > at C++. None of them have the contract based typing that PHP does. But > all > > of them get by just fine. And 2 of them use structural typing like this > (Go > > and C++). > > But they are not PHP programmers :) Granted you will still have the > average Joe or intern Joey in there as well but C. C++ and GO are > compiled, last time I've checked. And don't even try to say that, the > bundle off mess which even its creators regret doing it like that, > Javascript is OO :) > > I think this only mattered if there was some sort of maybe performance reason not to do it which i think Anthony has successfully to this point proven there isn't. We use tons... no really we basically stole everything from other languages. > See the point above... > > > >> > >> Can you please address these issues? > > > > > > Other than pointing out that these issues don't really exist in general > > (they are just a perspective based on an approach, rather than inherent > to > > the concept), I'm not sure how... You have a different approach to code > than > > I do. That doesn't mean either of us is wrong. It just means we value > > different things. And that's ok... > > > > Anthony > > Seriously? (for measuring contest) lease look at my LinkedIn profile, > I'm working with PHP for 7 years or so in various companies of > different sizes, clients, domains and most of all, I'm using stuff > that you can find in PEAR/packagist and phpclasses. > Maybe I wasn't clear. PLEASE STOP THIS! We're a freaking open source community. Measure this on merit. > Best regards > ---- > Florin Patan > https://github.com/dlsniper > http://www.linkedin.com/in/florinpatan > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --e89a8f3ba52589e6cd04e024d0a9--