Re: [PHP-DEV] [RFC] Short-match

2020-12-21 Thread Mike Schinkel
> On Dec 16, 2020, at 12:49 PM, Ben Ramsey wrote: > >> On Dec 16, 2020, at 10:54, Mike Schinkel wrote: >> >> If we allow "switch {...}" to represent "switch (true){...}" then the value >> switch compares will be hidden and less obvious to a developer if they are >> forgetting to consider

Re: [PHP-DEV] [RFC] Short-match

2020-12-20 Thread Olle Härstedt
On Sat, 19 Dec 2020, 02:48 Larry Garfield, wrote: > On Fri, Dec 18, 2020, at 1:40 PM, Olle Härstedt wrote: > > What about matching on a variable's type? > > > > ``` > > match { > > $var: string => "is a string" > > $var: array => "something else" > > } > > ``` > > > > This could be used with

Re: [PHP-DEV] [RFC] Short-match

2020-12-18 Thread Larry Garfield
On Fri, Dec 18, 2020, at 1:40 PM, Olle Härstedt wrote: > What about matching on a variable's type? > > ``` > match { > $var: string => "is a string" > $var: array => "something else" > } > ``` > > This could be used with flow-sensitive typing, e.g. assume the type of $var > being string in th

Re: [PHP-DEV] [RFC] Short-match

2020-12-18 Thread Olle Härstedt
What about matching on a variable's type? ``` match { $var: string => "is a string" $var: array => "something else" } ``` This could be used with flow-sensitive typing, e.g. assume the type of $var being string in the string block. Psalm works like this for if-statements. Also consider the ca

Re: [PHP-DEV] [RFC] Short-match

2020-12-17 Thread Larry Garfield
On Thu, Dec 17, 2020, at 10:23 AM, Sara Golemon wrote: > On Wed, Dec 16, 2020 at 6:50 PM someniatko wrote: > > > > `match` is an expression, where as if-else construction is not. This > > allows for combining it with a potential future feature of single line > > functions and methods. For example

Re: [PHP-DEV] [RFC] Short-match

2020-12-17 Thread Claude Pache
> Le 17 déc. 2020 à 17:23, Sara Golemon a écrit : > > On Wed, Dec 16, 2020 at 6:50 PM someniatko wrote: >> >> `match` is an expression, where as if-else construction is not. This >> allows for combining it with a potential future feature of single line >> functions and methods. For example (

Re: [PHP-DEV] [RFC] Short-match

2020-12-17 Thread Sara Golemon
On Wed, Dec 16, 2020 at 6:50 PM someniatko wrote: > > `match` is an expression, where as if-else construction is not. This > allows for combining it with a potential future feature of single line > functions and methods. For example (hypothetical syntax is used): > > ``` > $getNumber = fn(int $num

Re: [PHP-DEV] [RFC] Short-match

2020-12-17 Thread Larry Garfield
On Wed, Dec 16, 2020, at 6:49 PM, someniatko wrote: > `match` is an expression, where as if-else construction is not. This > allows for combining it with a potential future feature of single line > functions and methods. For example (hypothetical syntax is used): > > ``` > function getNumberKind(i

RE: [PHP-DEV] [RFC] Short-match

2020-12-16 Thread someniatko
`match` is an expression, where as if-else construction is not. This allows for combining it with a potential future feature of single line functions and methods. For example (hypothetical syntax is used): ``` function getNumberKind(int $number) => match { $number > 0 => NumberKind::POSITIVE,

Re: [PHP-DEV] [RFC] Short-match

2020-12-16 Thread Ben Ramsey
> On Dec 16, 2020, at 10:54, Mike Schinkel wrote: > > If we allow "switch {...}" to represent "switch (true){...}" then the value > switch compares will be hidden and less obvious to a developer if they are > forgetting to consider switch's evaluation behavior. For some people this > would in

Re: [PHP-DEV] [RFC] Short-match

2020-12-16 Thread Mike Schinkel
> On Dec 15, 2020, at 12:18 PM, Larry Garfield wrote: > > On Tue, Dec 15, 2020, at 3:00 AM, Nikita Popov wrote: >> On Mon, Dec 14, 2020 at 6:34 PM Larry Garfield >> wrote: >> >>> I present to Internals this tiny RFC to follow up on the match() >>> expression RFC from earlier in the year. There

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Sara Golemon
On Tue, Dec 15, 2020 at 1:37 PM Andreas Leathley wrote: > ```php > $this->handler = match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', > is_string($var) => '"'.$var.'"', > is_callable($var) => 'callable', >

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Andreas Leathley
On 15.12.20 20:08, Sara Golemon wrote: Or even better with existing syntax: ```php $this->handler = match($var) { null, true, false => json_encode($var), default => \is_string($var) ? "\"$var\"" : \rtrim(\print_r($var, true)), }; I appreciate that this is a specific counter-example to your

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Sara Golemon
On Mon, Dec 14, 2020 at 5:30 PM Andreas Leathley wrote: > With match this becomes much more concise: > > ```php > $this->handler = function ($var): string { > return match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', >

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Larry Garfield
On Tue, Dec 15, 2020, at 3:00 AM, Nikita Popov wrote: > On Mon, Dec 14, 2020 at 6:34 PM Larry Garfield > wrote: > > > I present to Internals this tiny RFC to follow up on the match() > > expression RFC from earlier in the year. There was solidly positive > > support for this shortcut previously

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Ilija Tovilo
Hi internals > With match this becomes much more concise: > > ```php > $this->handler = function ($var): string { > return match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', > \is_string($var) => '"'.$var.'"', >

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Nikita Popov
On Mon, Dec 14, 2020 at 6:34 PM Larry Garfield wrote: > I present to Internals this tiny RFC to follow up on the match() > expression RFC from earlier in the year. There was solidly positive > support for this shortcut previously but it was removed for simplicity at > the time, with the intent t

Re: [PHP-DEV] [RFC] Short-match

2020-12-15 Thread Olle Härstedt
On Tue, 15 Dec 2020, 00:30 Andreas Leathley, wrote: > I checked in my vendor directory for currently used switch(true) usages, > there were 96 matches. It is often used when handling an unknown value > and needing to display or convert it, as there the structure of a switch > is easier to scan co

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Andreas Leathley
I checked in my vendor directory for currently used switch(true) usages, there were 96 matches. It is often used when handling an unknown value and needing to display or convert it, as there the structure of a switch is easier to scan compared to other comparisons like ifs (at least it is for me).

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Paul Crovella
On Mon, Dec 14, 2020 at 1:23 PM Sara Golemon wrote: > > On Mon, Dec 14, 2020 at 2:24 PM Doug Nelson wrote: > > > Both you and Sara at different points have talked about thinking was bad > > practice, but I've not read anything compelling about why it should be > > considered as such. > > > > > I'

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Björn Larsson
Den 2020-12-14 kl. 22:23, skrev Sara Golemon: On Mon, Dec 14, 2020 at 2:24 PM Doug Nelson wrote: Both you and Sara at different points have talked about thinking was bad practice, but I've not read anything compelling about why it should be considered as such. I'm not a full -1 on the conce

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Andreas Leathley
On 14.12.20 18:33, Larry Garfield wrote: I present to Internals this tiny RFC to follow up on the match() expression RFC from earlier in the year. There was solidly positive support for this shortcut previously but it was removed for simplicity at the time, with the intent to bring it back la

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Kamil Tekiela
I don't understand what's the advantage of the short match? Why would I ever want to use it? If I ever saw this kind of code in my codebase then I would immediately refactor it to use if statements. That is just abuse of match statement in my opinion. If someone wants to abuse match syntax like thi

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Sara Golemon
On Mon, Dec 14, 2020 at 2:24 PM Doug Nelson wrote: > Both you and Sara at different points have talked about thinking was bad > practice, but I've not read anything compelling about why it should be > considered as such. > > I'm not a full -1 on the concept (especially as match(true) has the conv

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Olle Härstedt
Another situation in which _ might be useful. match (_) { ... } On Mon, 14 Dec 2020, 21:43 Marco Pivetta, wrote: > Hey Doug, > > > > > On Mon, Dec 14, 2020, 21:24 Doug Nelson wrote: > > > Hi Marco, > > > > Is there any chance you can elaborate on why you feel it's a bad idea? > > > > Both you a

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Marco Pivetta
Hey Doug, On Mon, Dec 14, 2020, 21:24 Doug Nelson wrote: > Hi Marco, > > Is there any chance you can elaborate on why you feel it's a bad idea? > > Both you and Sara at different points have talked about thinking was bad > practice, but I've not read anything compelling about why it should be

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Doug Nelson
Hi Marco, Is there any chance you can elaborate on why you feel it's a bad idea? Both you and Sara at different points have talked about thinking was bad practice, but I've not read anything compelling about why it should be considered as such. Kind regards, Doug Nelson On Mon, 14 Dec 2020 at 1

Re: [PHP-DEV] [RFC] Short-match

2020-12-14 Thread Marco Pivetta
Hey Larry, On Mon, Dec 14, 2020 at 6:34 PM Larry Garfield wrote: > I present to Internals this tiny RFC to follow up on the match() > expression RFC from earlier in the year. There was solidly positive > support for this shortcut previously but it was removed for simplicity at > the time, with

[PHP-DEV] [RFC] Short-match

2020-12-14 Thread Larry Garfield
I present to Internals this tiny RFC to follow up on the match() expression RFC from earlier in the year. There was solidly positive support for this shortcut previously but it was removed for simplicity at the time, with the intent to bring it back later. It's now later. https://wiki.php.net