AW: [PHP-DEV] Types on the right or on the left
> -Ursprüngliche Nachricht- > Von: morrison.l...@gmail.com [mailto:morrison.l...@gmail.com] Im Auftrag von > Levi Morrison > Gesendet: Montag, 3. November 2014 19:54 > An: Robert Stoll > Cc: PHP Internals > Betreff: Re: [PHP-DEV] Types on the right or on the left > > > Thoughts? > > I think you didn't follow the mailing list or read the return types RFC > carefully if you think putting the return type before the > function name is good at all. Also, why are you starting this conversation > now instead of months ago or even a couple > weeks ago when I asked for feedback on the latest return types RFC? > > Lastly, I want to say that compatibility with Hack is only one consideration > of all things considered. Please don't let that > guide your thoughts too far one way or the other. > You obviously took it the wrong way, I did not intend to attack your RFC. Besides, I wrote an email to you in private mentioning that it is an inconsistency, but that this should not stop your RFC (and thus I have written it in private and did not mention it on the list). The discussion I wanted to start is not about your RFC, it is about what direction PHP wants to go when it comes down to further type hints, put types only on the right, or only on the left or mix it. I followed the return type RFC and thus know that many people think it has to be on the left hand side. Fair enough, I do not have anything against such a decision. I also have nothing against putting the type on the right hand side. What merely bothers me is that it would be another inconsistency in the language design. It's not very intuitive for a user if a type hint is once on the right hand side and once on the left hand side. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
AW: [PHP-DEV] Types on the right or on the left
> -Ursprüngliche Nachricht- > Von: Andrea Faulds [mailto:a...@ajf.me] > Gesendet: Montag, 3. November 2014 16:40 > An: Robert Stoll > Cc: PHP Internals > Betreff: Re: [PHP-DEV] Types on the right or on the left > > > > On 3 Nov 2014, at 15:07, Robert Stoll wrote: > > > > It adds the type hint on the right hand side of the function (of the > > identifier). In contrast to parameters where the type hint is placed on the > > left hand side of the identifier. > > Mixing both, having some types on the left and others on the right, > > seems like another inconsistency in the language design to me. > > These inconsistencies exist for two reasons: > > - Opposition to doing it the other way > - Hack already doing it this way > > I don’t think `function void foo();` will happen, since that’s been > previously rejected as it breaks gripping for “function foo”. > Similarly, I don’t think `public $foo: Foo;` will happen, given Hack does it > as `public Foo $foo;`. > > PHP doesn’t need more inconsistency, sure, but we must be practical here. It > is bad if PHP and Hack have the same feature > with different syntax, it will cause developer confusion and further segment > the communities. It is bad if we don’t get > return type hinting because the “consistent” syntax would upset some people. > > -- > Andrea Faulds > http://ajf.me/ > I agree with you to a certain degree, PHP and Hack should not diverge but (kind of but)... IMO Hack made a wrong language design decision and I do not see why PHP should make the same mistake. And I am sure, Hack would catch up quickly if PHP would decide to put all types on the right (as in the return type hint RFC - just as an example). -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
AW: [PHP-DEV] Types on the right or on the left
I would like to pick up this discussion again - now that the return type hint RFC has passed, congratulations :) As a quick reminder, this discussion should not be whether we want to put the return types on the left or on the right but mainly if we want to have consistency (I do not want to downgrade the return type hint RFC either, that is the reason why I have waited till the vote was closed). Once agreed upon that consistency should be key when it comes down to the place of type hints, we can then discuss what approach PHP shall take in the future (all left or all right). The more I think about it the more I am in favour of putting types on the right hand side. I think it is more readable and less ambiguous. Consider the following: class A{ private Foo $a; //is "Foo" a modifier as well? private static $b; //or is "static" a type? } vs. class A{ private $a : Foo; private static $b; } Assuming we will introduce parameter modifiers such as final or similar in the future, then it is also less ambiguous for parameter type hints: function foo(final A $a, final $b){} vs function foo(final $a : A, final $b){} I am sure people will tell me that such a change (all types on the right, parameter type hints as well) is huge BC and unfeasible. I would agree that it is a huge BC but I would claim it is necessary and manageable. Code could be migrated automatically with an appropriate tool and it does not need to happen for PHP 7 but maybe for PHP 8. Besides, pretty much the same impact has the return type RFC now, because the manual should be updated accordingly to reflect the new syntax IMO. Sounds like lot of work but it should be possible to migrate the docs with a tool. And it needs to be done IMO otherwise the WTF/minute measurement will increase when using PHP (due to lot of "WTF! In the docs the return types are on the left and in code they are on the right hand side") - but maybe I am wrong. Anyway, I am primarily in favour of consistency - regardless if all left or all right - and mixing both styles is a very bad idea IMO - do you know any language which has taken a mixed approach (besides Hack)? Cheers, Robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
Hi! > put types only on the right, or only on the left or mix it. I > followed the return type RFC and thus know that many people think it > has to be on the left hand side. Fair enough, I do not have anything > against such a decision. I also have nothing against putting the type > on the right hand side. What merely bothers me is that it would be > another inconsistency in the language design. It's not very intuitive > for a user if a type hint is once on the right hand side and once on > the left hand side. I agree, this is not a very good situation. It would be much better to take a systematic approach to this, but this is impossible since there is no systematic approach to strict typing in PHP, just some pieces here and there. I think this is not right, but obviously many people here disagree and are happy to have the inconsistent syntax. I don't see why "public Foo function bar()" would be so much worse than "public function bar() : Foo" but for some reason this possibility wasn't even considered as far as I can see. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
On 4 November 2014 08:51, Stas Malyshev wrote: > I don't see why > "public Foo function bar()" would be so much worse than "public function > bar() : Foo" Because when you grep for "function bar", in future you'd have to know the return type too. I like to think of it as: function bar(): Type $hiddenTmpVar -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
> On 4 Nov 2014, at 08:51, Stas Malyshev wrote: > > I agree, this is not a very good situation. It would be much better to > take a systematic approach to this, but this is impossible since there > is no systematic approach to strict typing in PHP, just some pieces here > and there. I think this is not right, but obviously many people here > disagree and are happy to have the inconsistent syntax. I don't see why > "public Foo function bar()" would be so much worse than "public function > bar() : Foo" but for some reason this possibility wasn't even > considered as far as I can see. I thought it was inconsistent, but after discussions on StackOverflow, I don't think it actually is. Return types describe the return type of a function, not the type of a function. So there's no reason they have to go before the function name like parameter types do. Also, it's worth bearing in mind that `public Foo function` was rejected previously. -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
On 4 November 2014 10:32, Andrea Faulds wrote: > > > On 4 Nov 2014, at 08:51, Stas Malyshev wrote: > > > > I agree, this is not a very good situation. It would be much better to > > take a systematic approach to this, but this is impossible since there > > is no systematic approach to strict typing in PHP, just some pieces here > > and there. I think this is not right, but obviously many people here > > disagree and are happy to have the inconsistent syntax. I don't see why > > "public Foo function bar()" would be so much worse than "public function > > bar() : Foo" but for some reason this possibility wasn't even > > considered as far as I can see. > I thought it was inconsistent, but after discussions on StackOverflow, I > don't think it actually is. Return types describe the return type of a > function, not the type of a function. So there's no reason they have to go > before the function name like parameter types do. > > So, in a sentence: In PHP, input types go on the left and output types go on the right. This sounds like a convention that could be established and followed, and no-one could reasonably call it inconsistent if it was adhered to.
AW: AW: [PHP-DEV] Types on the right or on the left
> -Ursprüngliche Nachricht- > Von: are.you.winn...@gmail.com [mailto:are.you.winn...@gmail.com] Im Auftrag > von Chris Wright > Gesendet: Dienstag, 4. November 2014 12:51 > An: Andrea Faulds > Cc: Stas Malyshev; Robert Stoll; PHP Internals > Betreff: Re: AW: [PHP-DEV] Types on the right or on the left > > On 4 November 2014 10:32, Andrea Faulds wrote: > > > > > > On 4 Nov 2014, at 08:51, Stas Malyshev wrote: > > > > > > I agree, this is not a very good situation. It would be much better > > > to take a systematic approach to this, but this is impossible since > > > there is no systematic approach to strict typing in PHP, just some > > > pieces here and there. I think this is not right, but obviously many > > > people here disagree and are happy to have the inconsistent syntax. > > > I don't see why "public Foo function bar()" would be so much worse > > > than "public function > > > bar() : Foo" but for some reason this possibility wasn't even > > > considered as far as I can see. > > > I thought it was inconsistent, but after discussions on StackOverflow, I > > don't think it actually is. Return types describe the return type of a > > function, not the type of a function. So there's no reason they have > > to go before the function name like parameter types do. > > > > > So, in a sentence: > > In PHP, input types go on the left and output types go on the right. > > This sounds like a convention that could be established and followed, and > no-one could reasonably call it inconsistent if it > was adhered to. That is an interesting thought. Yet, where would you put the type of an out parameter then? Nevertheless, you could phrase your convention differently so it makes more sense and well.. in the end we can do whatever we like in PHP and call it xy-convention and the user will have to pick it up and learn it (quite similar to array functions where usually the first argument is array and suddenly it is not the first parameter as with array_key_exists, array_map or array_search). Sure it is no big deal, the user should be able to pick up the convention quickly but we could facilitate it, make it easier for the user, more intuitive, in order that the user has a steeper learning curve. And the time to decide what direction PHP should take is now with PHP 7. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
On 4 November 2014 12:17, Robert Stoll wrote: > > > -Ursprüngliche Nachricht- > > Von: are.you.winn...@gmail.com [mailto:are.you.winn...@gmail.com] Im > Auftrag von Chris Wright > > Gesendet: Dienstag, 4. November 2014 12:51 > > An: Andrea Faulds > > Cc: Stas Malyshev; Robert Stoll; PHP Internals > > Betreff: Re: AW: [PHP-DEV] Types on the right or on the left > > > > On 4 November 2014 10:32, Andrea Faulds wrote: > > > > > > > > > On 4 Nov 2014, at 08:51, Stas Malyshev > wrote: > > > > > > > > I agree, this is not a very good situation. It would be much better > > > > to take a systematic approach to this, but this is impossible since > > > > there is no systematic approach to strict typing in PHP, just some > > > > pieces here and there. I think this is not right, but obviously many > > > > people here disagree and are happy to have the inconsistent syntax. > > > > I don't see why "public Foo function bar()" would be so much worse > > > > than "public function > > > > bar() : Foo" but for some reason this possibility wasn't even > > > > considered as far as I can see. > > > > > I thought it was inconsistent, but after discussions on StackOverflow, I > > > don't think it actually is. Return types describe the return type of a > > > function, not the type of a function. So there's no reason they have > > > to go before the function name like parameter types do. > > > > > > > > So, in a sentence: > > > > In PHP, input types go on the left and output types go on the right. > > > > This sounds like a convention that could be established and followed, > and no-one could reasonably call it inconsistent if it > > was adhered to. > > That is an interesting thought. Yet, where would you put the type of an > out parameter then? I wouldn't, because this wouldn't ever make sense in PHP. I'm not a fan of out parameters in general in PHP, but enforcing the output type of a variable can't ever make sense in PHP from an implementation perspective without sacrificing some dynamic features that won't ever disappear - I'm sure it could be done, but not without a huge and unacceptable performance penalty. > Nevertheless, you could phrase your convention differently so it makes > more sense and well.. in the end we can do whatever we like in PHP and > call it xy-convention and the user will have to pick it up and learn it > (quite similar to array functions where usually the first argument is array > and suddenly it is not the first parameter as with array_key_exists, > array_map or array_search). Sure it is no big deal, the user should be able > to pick up the convention quickly but we could facilitate it, make it > easier for the user, more intuitive, in order that the user has a steeper > learning curve. And the time to decide what direction PHP should take is > now with PHP 7. > Please remember that PHP 7 is not the last major version of PHP. The things we do now are set in stone, but they do not mean that something else cannot be done in the future to build on top of them, as long as they do not conflict. I guess it's worth noting that my *personal* opinion is that I'd also rather have the function return type declaration on the left (I'd also like to drop the requirement for the "function" keyword in method declarations), but since there are a number of reasons why this no longer makes sense, and will never make sense again, I didn't hesitate to vote in favour of the current proposal because more than anything else I think the feature is what is important, and I know how much work has been put in to ensuring that the proposal satisfies as many concerns as possible. There will never be a better proposal than this.
AW: AW: [PHP-DEV] Types on the right or on the left
> I guess it's worth noting that my *personal* opinion is that I'd also rather > have the function return type declaration on the > left (I'd also like to drop the requirement for the "function" keyword in > method declarations), but since there are a number > of reasons why this no longer makes sense, and will never make sense again, I > didn't hesitate to vote in favour of the > current proposal because more than anything else I think the feature is what > is important, and I know how much work has > been put in to ensuring that the proposal satisfies as many concerns as > possible. There will never be a better proposal than > this. To be clear, I would vote yes for the return type RFC if I had voting rights. I'll continue this discussion after the return type RFC's voting phase ended. I do not want to cast a damning light on the RFC. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
Hi! >> "public Foo function bar()" would be so much worse than "public function >> bar() : Foo" > > Because when you grep for "function bar", in future you'd have to know > the return type too. Sorry, I do not understand - why to grep for "function bar" you'd have to know the type? Just grep for "function bar" as you did before. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
Hi! > I thought it was inconsistent, but after discussions on > StackOverflow, I don't think it actually is. If you specify the type once as "Foo something" and once as "something: Foo" then I don't see how there's even a place for discussions that it's inconsistent. > Return types describe the return type of a function, not the type of > a function. Given that in PHP functions do not have types, not being objects of the language, this seems to be argument invented just to ignore the inconsistency. Moreover, in languages where functions do have types - e.g. ML for example - the return of the function is specified in exactly the same manner as parameter type, and type of the function itself is never specified explicitly, but if needed, it is referred to with different syntax (->). See: https://en.wikipedia.org/wiki/Standard_ML Same situation with ActionScript: https://en.wikipedia.org/wiki/ActionScript both parameters and return type use ":" and nobody thinks that specifies type of the function - as, again, nobody ever specifies type of the function as such. In fact, I can remember no language that would specify type of the function (as opposed to parameters + returns) when declaring a function, even among languages with first class functions. > Also, it's worth bearing in mind that `public Foo function` was > rejected previously. Many things were rejected previously, but the RFC does not bring any argument about it and never even mentions it as far as I can see. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
Hi! > In PHP, input types go on the left and output types go on the right. What is the "output type"? If I wanted to type a variable - is it input or output? -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP-DEV] Types on the right or on the left
2014-11-04 9:51 GMT-08:00 Stas Malyshev : > Hi! > > > I thought it was inconsistent, but after discussions on > > StackOverflow, I don't think it actually is. > > If you specify the type once as "Foo something" and once as "something: > Foo" then I don't see how there's even a place for discussions that it's > inconsistent. > > > Return types describe the return type of a function, not the type of > > a function. > > Given that in PHP functions do not have types, not being objects of the > language, this seems to be argument invented just to ignore the > inconsistency. > > Moreover, in languages where functions do have types - e.g. ML for > example - the return of the function is specified in exactly the same > manner as parameter type, and type of the function itself is never > specified explicitly, but if needed, it is referred to with different > syntax (->). See: https://en.wikipedia.org/wiki/Standard_ML > > Same situation with ActionScript: > https://en.wikipedia.org/wiki/ActionScript > both parameters and return type use ":" and nobody thinks that specifies > type of the function - as, again, nobody ever specifies type of the > function as such. In fact, I can remember no language that would specify > type of the function (as opposed to parameters + returns) when declaring > a function, even among languages with first class functions. > > Haskell does: length :: [a] -> Int length [] = 0 length (_:xs) = 1 + length xs > > Also, it's worth bearing in mind that `public Foo function` was > > rejected previously. > > Many things were rejected previously, but the RFC does not bring any > argument about it and never even mentions it as far as I can see. > > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >