Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52088 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39494 invoked from network); 29 Apr 2011 18:04:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2011 18:04:30 -0000 Authentication-Results: pb1.pair.com header.from=peter.e.lind@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=peter.e.lind@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: peter.e.lind@gmail.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:60119] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/A0-31324-CADFABD4 for ; Fri, 29 Apr 2011 14:04:28 -0400 Received: by ywh1 with SMTP id 1so1790392ywh.29 for ; Fri, 29 Apr 2011 11:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=dtQyynIe3/pjK7+LW2mBt3axnAxuQSMktdSmuOM8whM=; b=kHOoSj1CGxmSOB6O/lCMdTWnmXoTGpWI/lhKbvYbyoSlp3lin5ech48r4tY2djd4qp EyQ5mLoic2IzjtF71pHfUghMIYIoAvsFFk93zVrTZsbPul1EMP3TMd+lbFKB19TIn8Uo mGLSwxCdKqE3Asv2cI33WTJkgMGgmeChxV1wo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=hVapV6i7Wt5FlT39/afkg0LmBI6cw9YfadNcwvRJeVaj8FvkdYZoiULszMFQ2VmOPU 8p/J1Edj1haau33kRbCMIOrDPs/dulipgnB+dtq5OelhyDnAmUUm8qieybZcfpvYeDPI bmeXqvyt8n9ShWMp0Fx9z99gF7zavGsZIUGa8= MIME-Version: 1.0 Received: by 10.91.207.19 with SMTP id j19mr4608329agq.83.1304100265518; Fri, 29 Apr 2011 11:04:25 -0700 (PDT) Received: by 10.90.34.20 with HTTP; Fri, 29 Apr 2011 11:04:24 -0700 (PDT) Received: by 10.90.34.20 with HTTP; Fri, 29 Apr 2011 11:04:24 -0700 (PDT) In-Reply-To: References: <4DB923E6.3020307@sugarcrm.com> <4DB9A7BE.6010307@sugarcrm.com> <1304016828.1561.103.camel@guybrush> Date: Fri, 29 Apr 2011 20:04:24 +0200 Message-ID: To: Martin Scotta Cc: =?UTF-8?Q?Johannes_Schl=C3=BCter?= , internals , Felipe Pena , Stas Malyshev , Ferenc Kovacs Content-Type: multipart/alternative; boundary=0016367657e013f65c04a2128126 Subject: Re: [PHP-DEV] [RFC] Return type-hint From: peter.e.lind@gmail.com (Peter Lind) --0016367657e013f65c04a2128126 Content-Type: text/plain; charset=UTF-8 On Apr 29, 2011 4:47 PM, "Martin Scotta" wrote: > > > Martin Scotta > > > On Thu, Apr 28, 2011 at 5:15 PM, Peter Lind wrote: >> >> 2011/4/28 Martin Scotta : >> >> * snip * >> >> > IMHO I would not trust on any return value, as PHP did not ensure anything >> > about them. >> > Even more, I do not write code that depend on return values, I prefer to >> > use input/output parameters, >> >> I cannot help but wonder why PHP is your language of choice. I mean no >> disrespect, but PHP does not have strict typing (for a reason) and >> forcing it upon PHP seems strange to me. Seeing as a) you'll either >> have to implement the return type hinting yourself in which case you'd >> know anyway what the return value is or b) you'd have to have others >> implement it in their libraries in which case you'd have to wait years >> for any noticeable effect, the feature seems useful only in edge cases >> (such as Hiphop, which I think one can question the mainstream >> usefulness of, currently). > > > I understand why PHP does not have strict typing as much as I understand why PHP do not have good-qualities third-party libraries. > I'm not saying that there aren't good libraries, but the language has many holes that makes almost impossible to build solid library (ie: include) I have come across good php libraries. In fact, I haven't used ant really bad ones. Again, maybe its a question of different environments - but I cannot see any reason why building a library should be inherently harder in php than strictly-typed languages. > All the strictness of ppp, typehint and the like are not restrict things, they are meant as boundaries for client code, to ensure the correct and well defined behavior. There's a very big difference between ppp and typehinting. As Stas noted, they serve very different purposes - and while ppp typically goes with oop (though not in every language), strict typing is not in any way necessary to do oop. That should be obvious given the large amount of working oop code out there. > It's ok if you write all you code as procedural, or you don't like to write classes, but IMHO the language should provide a solid foundation for them, this way you can rely on libraries for common task and make your procedural code even simpler, shorter and safer. My background was assembler before languages like php. To me, strict typing makes it harder, not easier, to make or use a good library. That's not to say that strict typing is bad - just that what you need depends on your experience. I've never had a need for strict typing in php, I don't find myself making the errors that strict typing solves in, say c#. > I'm not sure if return typehint will be a good idea, but I'm not against it. > I believe the language has to deal with other "pending" stuff prior to this. PHP has many blind areas, whenever you call something, you don't know if you will return or it will just die in a non-sense Fatal error. Honestly, I've never had this problem, and I'd like to hear mire of your dev environment to see what leads to them :) Regards Peter >> >> Personally, I read code if I'm not sure what a given function/method >> will return - or just test. I actually thought unit tests took care of >> issues like this. I don't think having a list of possible return >> values would make things simpler than the good old "try it and see" - >> which is one of the greatest assets of PHP. >> >> > This is the safer way I've found to achieve the same behavior >> > >> > function no_return(ReturnStatus $returnStatus) { >> > doSomething(); >> > >> > if ( itWasOk() ) >> > { >> > $returnStatus->setReturnValue( new Foo ); // return type hint >> > $returnStatus->success(); // return status >> > } >> > elseif ( isWasCritical() ) >> > { >> > $returnStatus->setException( new RuntimeException ); >> > $returnStatus->exception(); // return status >> > } >> > else >> > { >> > $returnStatus->fail(); // return status >> > } >> > } >> > >> > Of course I don't write all functions like this. >> > This is pattern I use when I need to ensure that the type returned is valid. >> >> I just return what I need to from the function/method or throw an >> exception. Indicating that you want to throw an exception instead of >> actually throwing one seems ... overly polite, at best. As far as I >> can tell, you'd have to check the ReturnStatus object anyway, so I >> don't see how you're any safer (PHP has functions for checking null >> values, false values, try/catch blocks and other things too). But >> maybe we're dealing with very different development environments and I >> just cannot see the usefulness of the suggested as it wouldn't make a >> positive difference in mine. >> >> Just a perspective from a typical webdev. >> Regards >> Peter >> >> -- >> >> WWW: plphp.dk / plind.dk >> LinkedIn: plind >> BeWelcome/Couchsurfing: Fake51 >> Twitter: kafe15 >> > > --0016367657e013f65c04a2128126--