# Types on the right or on the left

- Thread: https://externals.io/message/78577
- Original archive: https://news-web.php.net/php.internals/78577
- Started by Robert Stoll on 2014-11-03T15:07:41+00:00
- Messages: 46
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/78577.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #78577 — Robert Stoll — 2014-11-03T15:07:41+00:00

URL: https://externals.io/message/78577#78577

Heya,

Its seems to me that more and more RFC are proposed to augment PHP's syntax with some form of additional type hints.
The following RFC proposes to add a type hint for the return type of a function/method:
https://wiki.php.net/rfc/returntypehinting

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.

I think now is the time where we should decide what convention we want to stick to in the future (either left or right).
PHP 7 is the perfect time to make a change. I do not want to take sides because I am not yet sure what I prefer but
following some examples for both conventions:

function foo($a : Foo,  $b : array) : void {}   // types on the right
function void foo(Foo $a, array $b){}           // types on the left

Assuming PHP will introduce type hints for properties at some point

class A{ 
  private $f : Foo; //types on the right
  private Foo $f; //types on the left
}

Assuming PHP will introduce type hints for variables at some point 

$a : int = 1;  //types on the right
int $a = 1;   // types on the left

Assuming PHP will introduce generics and typed arrays at some point.  

function foo<T>($a : T,  $b : array<Bar>, $c : Foo[]) : callable<T, Car> {}  // types on the right
function callable<T, Car> foo<T>(T $a, array<Bar> $b, Foo[] $c){}             // types on the left

Thoughts?

Cheers,
Robert

---

## #78580 — Andrea Faulds — 2014-11-03T15:39:46+00:00

URL: https://externals.io/message/78577#78580 · In reply to: #78577

> 
> 
> 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/

---

## #78584 — Levi Morrison — 2014-11-03T18:53:49+00:00

URL: https://externals.io/message/78577#78584 · In reply to: #78577

> 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.

---

## #78585 — Stas Malyshev — 2014-11-03T19:28:09+00:00

URL: https://externals.io/message/78577#78585 · In reply to: #78580

Hi!

> 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.

Given that Hack is a different language, which was designed AFAIK with
little input from PHP community, I don't see how there would be any
confusion - it's like saying PHP and Perl or PHP and Java having
different syntaxes leads to segmenting the communities. In fact, there
are two different communities - though, of course, people can belong to
both - and two different languages. I do not think Hack syntax should
have much weight in decisions about what syntax to choose in PHP - it's
a different language, even though it has many similarities.

---

## #78586 — Andrea Faulds — 2014-11-03T19:42:21+00:00

URL: https://externals.io/message/78577#78586 · In reply to: #78585

> 
> 
> Hi!
> 
> > […]
> 
> Given that Hack is a different language, which was designed AFAIK with
> little input from PHP community, I don't see how there would be any
> confusion - it's like saying PHP and Perl or PHP and Java having
> different syntaxes leads to segmenting the communities.

This is an unfair comparison. Hack is a compatible superset of PHP, much like TypeScript is a compatible superset of JavaScript.

> In fact, there
> are two different communities - though, of course, people can belong to
> both - and two different languages. I do not think Hack syntax should
> have much weight in decisions about what syntax to choose in PHP - it's
> a different language, even though it has many similarities.

I’d rather there be less divergence between Hack and PHP, to limit the damage that it causes to the community.

--
Andrea Faulds
http://ajf.me/

---

## #78587 — Stas Malyshev — 2014-11-03T19:48:43+00:00

URL: https://externals.io/message/78577#78587 · In reply to: #78586

Hi!

> This is an unfair comparison. Hack is a compatible superset of PHP,
> much like TypeScript is a compatible superset of JavaScript.

So? PHP once borrowed Perl syntax, and Java syntax, and so on. Hack
borrowed PHP syntax, and that's great. But that doesn't mean what they
do in their own language should constraint what we do in PHP.

> I’d rather there be less divergence between Hack and PHP, to limit
> the damage that it causes to the community.

I don't see any damage to the community. How PHP not matching other
language's syntax does any damage to the community? What kind of damage
and where this damage comes from? Are we damaged because PHP arrays and
Perl arrays have different syntax, despite obvious Perl roots in PHP?
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #78588 — Andrea Faulds — 2014-11-03T19:59:12+00:00

URL: https://externals.io/message/78577#78588 · In reply to: #78587

> 
> 
> Hi!
> 
> > […]
> 
> So? PHP once borrowed Perl syntax, and Java syntax, and so on. Hack
> borrowed PHP syntax, and that's great. But that doesn't mean what they
> do in their own language should constraint what we do in PHP.

Again, an unfair comparison. Hack isn’t intended to be a completely separate language. It’s supposed to be an augmented PHP, which is compatible with PHP. PHP code can use Hack code (in HHVM, anyway) and Hack code can use PHP code. Hack is a superset of PHP. There are transitional modes, too.

> 
> > […]
> 
> I don't see any damage to the community. How PHP not matching other
> language's syntax does any damage to the community? What kind of damage
> and where this damage comes from? Are we damaged because PHP arrays and
> Perl arrays have different syntax, despite obvious Perl roots in PHP?

The damage is in fragmentation. Hack threatens to fragment the PHP community by making people jump ship to use its added features. While the whole Hack community can use PHP libraries, only some of the PHP community (HHVM users) can use Hack code. The consequences of this could be severe.

I’d rather there are less differences between PHP and Hack so there are less reasons to switch. Though I suppose the specific syntax of types is probably not a major issue.

--
Andrea Faulds
http://ajf.me/

---

## #78589 — Stas Malyshev — 2014-11-03T20:50:26+00:00

URL: https://externals.io/message/78577#78589 · In reply to: #78588

Hi!

> Again, an unfair comparison. Hack isn’t intended to be a completely

I'm not sure what you refer to by "fair". Hack is not "intended", but IS
a separate language - just read the manual and you will see, it is a new
language which borrows some syntax from PHP. Just read their own site:

Hack is a programming language for HHVM that interoperates seamlessly
with PHP.

I completely agree with this statement - Hack is a programming language
that is different from PHP but built in a way to interoperate with it.

> separate language. It’s supposed to be an augmented PHP, which is

The fact that you can run (some) PHP code in Hack is a feature of Hack,
the same way as if you craft Perl code I'm sure there is some code that
you can run with minimal modification in PHP. So what?
I'm not sure what you mean by "augmented" - you can claim C++ is an
"augmented assembly language" since you can insert assembly pieces into
C++ code and it would work. But that would make little sense, since C++
goes way beyond and is a separate language. That yes, with some
iterations, borrowed some things (one may say too many if so inclined)
from lower-level languages, but it does not mean it *is* any of those.

> compatible with PHP. PHP code can use Hack code (in HHVM, anyway) and

PHP code can use C, C++, Java or Lua code with suitable extensions. So
what?

> Hack code can use PHP code. Hack is a superset of PHP. There are
> transitional modes, too.

I'm not sure how this is relevant. Hack is a new language and a new
project, with its own design, its own rules, its own governorship, its
own community, its own everything. It's not something that is an
opinion, it's an obvious fact. Trying to present it as if it is some
part of PHP project just makes no sense to me.
Yes, it build on PHP and it is great for many practical and theoretical
reasons. But it does not change the plain fact of Hack being its own
project and its own language. I honestly do not understand why
recognition of this simple fact is such an issue.

> The damage is in fragmentation. Hack threatens to fragment the PHP
> community by making people jump ship to use its added features. While

I don't understand that "jump ship" mentality. In last couple of months,
I have used at least 6 different programming languages (not counting
stuff like config languages, shell scripts, etc.) Did I "jump ship"
every time? If I use PHP, am I somehow married to it and using another
language is somehow becomes "cheating"? Is it the case that once I use
Hack I somehow not allowed to use PHP again because I "jumped ship"?
What is that "jumping" thing?

I say - let people use Hack as much as they want. Let them use PHP as
much as they want. Let them use anything their heart likes as much as
they want. There's absolutely no "damage" or "threat" in that. PHP is
not diminished because somebody is using another language, even if that
language uses dollars before variable names. If PHP is ever diminished,
the only reason would be because PHP is not serving its community needs
well enough anymore. That what we should be thinking about - how to make
PHP better suited for its users, not how to prevent people from using
other languages.

> the whole Hack community can use PHP libraries, only some of the PHP
> community (HHVM users) can use Hack code. The consequences of this
> could be severe.

I do not see any "severe" consequences on that at all. If there are Hack
libraries that are so awesome PHP community wants them, they'll be
ported or interfaced - as happened to number of other libraries.

> I’d rather there are less differences between PHP and Hack so there
> are less reasons to switch. Though I suppose the specific syntax of
> types is probably not a major issue.

If you need Hack, by all means use Hack. There's absolutely no problem
and no threat in this. If you need PHP, use PHP. I think our work here
is to make PHP better, not somehow prevent people from using Hack or
change PHP in a way that would make people less inclined to use Hack.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #78614 — Robert Stoll — 2014-11-04T08:37:37+00:00

URL: https://externals.io/message/78577#78614 · In reply to: #78584

> -----Ursprüngliche Nachricht-----
> Von: morrison.levi@gmail.com [mailto:morrison.levi@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
> 
> > […]
> 
> 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.

---

## #78617 — Robert Stoll — 2014-11-04T08:47:46+00:00

URL: https://externals.io/message/78577#78617 · In reply to: #78580

> -----Ursprüngliche Nachricht-----
> Von: Andrea Faulds [mailto:ajf@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
> 
> 
> > […]
> 
> 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 <b>but</b>)...
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).

---

## #78618 — Stas Malyshev — 2014-11-04T08:51:11+00:00

URL: https://externals.io/message/78577#78618 · In reply to: #78614

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/

---

## #78622 — Leigh — 2014-11-04T10:24:42+00:00

URL: https://externals.io/message/78577#78622 · In reply to: #78618

> 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

---

## #78624 — Andrea Faulds — 2014-11-04T10:32:41+00:00

URL: https://externals.io/message/78577#78624 · In reply to: #78618

> 
> 
> 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/

---

## #78629 — Chris Wright — 2014-11-04T11:50:33+00:00

URL: https://externals.io/message/78577#78629 · In reply to: #78624

>
> > […]
>
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.

---

## #78630 — Robert Stoll — 2014-11-04T12:17:32+00:00

URL: https://externals.io/message/78577#78630 · In reply to: #78629

> -----Ursprüngliche Nachricht-----
> Von: are.you.winning@gmail.com [mailto:are.you.winning@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
> 
> 
> 
> > […]
> I thought it was inconsistent, but after discussions on StackOverflow, I
> > […]
> 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.

---

## #78632 — Chris Wright — 2014-11-04T12:46:23+00:00

URL: https://externals.io/message/78577#78632 · In reply to: #78630

>
> > […]
> Auftrag von Chris Wright
> > […]
> wrote:
> > […]
> and no-one could reasonably call it inconsistent if it
> > […]
>
> 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.

---

## #78636 — Robert Stoll — 2014-11-04T13:20:10+00:00

URL: https://externals.io/message/78577#78636 · In reply to: #78632

> 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.

---

## #78647 — Andrea Faulds — 2014-11-04T16:28:56+00:00

URL: https://externals.io/message/78577#78647 · In reply to: #78629

> 
> 
> 
> 
> > […]
> 
> 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’s not quite what I meant, but I’d also agree with that convention.

For parameters, the type is of the thing itself:

    function foo(Foo $foo, Bar $bar);

Here, $foo is of the type Foo, and $bar is of the type Bar.

But say if we were to add return types like this:

    function FooBar qux();

The type of qux isn’t a FooBar, it’s a function (more accurately, an argument-less, return-anything function). FooBar isn’t what qux is, it’s not qux’s type, merely what it returns. In a sense, I’d say there’s already a type here: `function`.

Compare it to this:

    function qux(): FooBar;

FooBar is what qux returns, `function` is what qux is.

If we were to hypothetically add typed properties with the same syntax Hack has, they’d look like this:

    public Foo $foo;

This would be consistent with parameters. And I think it goes along well with return types at the end:

    public Foo $foo;
    public function foobar(): FooBar;

Here, it’s clear the second item is a function, and the previous item is a property of type Foo.

…but hey, I could be wrong. Does this make sense to anyone?

--
Andrea Faulds
http://ajf.me/

---

## #78653 — Stas Malyshev — 2014-11-04T17:46:25+00:00

URL: https://externals.io/message/78577#78653 · In reply to: #78622

Hi!

> > […]
> 
> 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/

---

## #78654 — Stas Malyshev — 2014-11-04T17:51:45+00:00

URL: https://externals.io/message/78577#78654 · In reply to: #78624

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/

---

## #78655 — Stas Malyshev — 2014-11-04T17:59:42+00:00

URL: https://externals.io/message/78577#78655 · In reply to: #78629

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/

---

## #78656 — Andrea Faulds — 2014-11-04T18:08:15+00:00

URL: https://externals.io/message/78577#78656 · In reply to: #78653

> 
> 
> Hi!
> 
> > […]
> 
> 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.

Because if that function has a return type, e.g.:

    public function Foo bar()

Then you couldn’t grep for “function bar” because of the Foo.

If we used this syntax instead, which wouldn’t disrupt grep:

    public Foo function bar();

It’d be inconsistent with normal function declarations which would have to have Foo after function.

--
Andrea Faulds
http://ajf.me/

---

## #78660 — Rasmus Lerdorf — 2014-11-04T18:14:58+00:00

URL: https://externals.io/message/78577#78660 · In reply to: #78656

> 
> > […]
> 
> Because if that function has a return type, e.g.:
> 
>     public function Foo bar()
> 
> Then you couldn’t grep for “function bar” because of the Foo.
> 
> If we used this syntax instead, which wouldn’t disrupt grep:
> 
>     public Foo function bar();
> 
> It’d be inconsistent with normal function declarations which would have to have Foo after function.

I don't understand that inconsistency.

   public Foo function bar() { }

looks perfectly sane to me. PHP's syntax was very heavily influenced by
C from day 1. In C you have:

   static int bar() { }

In PHP the 'function' keyword indicates what follows is a function.
Putting something in between the function keyword and the name of the
function would confuse me. To me "function bar()" is inseparable and is
equivalent to "bar()" in C which makes the above examples consistent
with each other.

-Rasmus

---

## #78662 — Christoph Becker — 2014-11-04T18:23:28+00:00

URL: https://externals.io/message/78577#78662 · In reply to: #78647

Andrea Faulds wrote:

> For parameters, the type is of the thing itself:
> 
>     function foo(Foo $foo, Bar $bar);
> 
> Here, $foo is of the type Foo, and $bar is of the type Bar.
> 
> But say if we were to add return types like this:
> 
>     function FooBar qux();
> 
> The type of qux isn’t a FooBar, it’s a function (more accurately, an argument-less, return-anything function). FooBar isn’t what qux is, it’s not qux’s type, merely what it returns. In a sense, I’d say there’s already a type here: `function`.
> 
> Compare it to this:
> 
>     function qux(): FooBar;
> 
> FooBar is what qux returns, `function` is what qux is.
> 
> If we were to hypothetically add typed properties with the same syntax Hack has, they’d look like this:
> 
>     public Foo $foo;
> 
> This would be consistent with parameters. And I think it goes along well with return types at the end:
> 
>     public Foo $foo;
>     public function foobar(): FooBar;
> 
> Here, it’s clear the second item is a function, and the previous item is a property of type Foo.
> 
> …but hey, I could be wrong. Does this make sense to anyone?

To me it makes sense.  However

  Foo function foo(Bar bar) {}

also makes sense, as the type of bar would be "Foo function(Bar)".

-- 
Christoph M. Becker

---

## #78665 — Stas Malyshev — 2014-11-04T18:33:19+00:00

URL: https://externals.io/message/78577#78665 · In reply to: #78656

Hi!

> Because if that function has a return type, e.g.:
> 
>     public function Foo bar()
> 
> Then you couldn’t grep for “function bar” because of the Foo.

And that's not what I have proposed. Would anybody actually *read* what
I am proposing? Or reading is optional for discussion now?

> If we used this syntax instead, which wouldn’t disrupt grep:
> 
>     public Foo function bar();
> 
> It’d be inconsistent with normal function declarations which would have to have Foo after function.

What's "normal function" and why it would have to have "Foo" after
function? What's wrong with "Foo function bar()"? It reads nicely (at
least in English, where the natural word order is adjective-noun, not
noun-adjective), it does not disrupt any searches, what exactly is wrong
with it?
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

Next page: https://externals.io/message/78577.md?page=2
