Re: AW: [PHP-DEV] Types on the right or on the left

2014-11-04 Thread Stas Malyshev
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

2014-11-04 Thread Leigh
On 4 November 2014 08:51, Stas Malyshev smalys...@sugarcrm.com 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

2014-11-04 Thread Andrea Faulds

 On 4 Nov 2014, at 08:51, Stas Malyshev smalys...@sugarcrm.com 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

2014-11-04 Thread Chris Wright
On 4 November 2014 10:32, Andrea Faulds a...@ajf.me wrote:


  On 4 Nov 2014, at 08:51, Stas Malyshev smalys...@sugarcrm.com 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.


Re: AW: [PHP-DEV] Types on the right or on the left

2014-11-04 Thread Chris Wright
On 4 November 2014 12:17, Robert Stoll p...@tutteli.ch 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 a...@ajf.me wrote:
 
  
On 4 Nov 2014, at 08:51, Stas Malyshev smalys...@sugarcrm.com
 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.


Re: AW: [PHP-DEV] Types on the right or on the left

2014-11-04 Thread Stas Malyshev
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

2014-11-04 Thread 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.

 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

2014-11-04 Thread Stas Malyshev
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 Thread Jelle Zijlstra
2014-11-04 9:51 GMT-08:00 Stas Malyshev smalys...@sugarcrm.com:

 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