Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Mon, Feb 25, 2013 at 1:17 PM, Clint Priest wrote: > > On 2/21/2013 5:17 AM, David Muir wrote: >> >> On 21/02/2013, at 6:12 AM, Lazare Inepologlou wrote: >> >>> >>> Long code is not always equivalent to readable code. A shorter syntax >>> could >>> improve readability in *some* cases. >>> >>> Long: >>> $users->OrderBy( function( $x ){ return $x->Surname; } ); >>> >>> Short: >>> $users->OrderBy( $x ==> $x->Surname ); >>> >> I think your example proves the opposite. The fist example was much easier >> to read and understand than the second. > > That all depends on how many languages you're versed in, the short syntax > above is common in many modern languages and has no clarity issues for me. > > > -- > -Clint > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Just letting my voice hear as a "php developer" watching this list from time to time. As a php developer i'm heavily against adding this "feature" to php. It makes the code very vague to understand and specially if it's spread over multiple files. For example file_a.php has: $sayHi = { echo "hi"; }; Now lets say file_b.php has this: $sayHi(); This is just code obfuscation! Please don't add it. It would be neat as a code obfuscation technique :) Just my 5 cents. Cheers, Mark -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 2/21/2013 5:17 AM, David Muir wrote: On 21/02/2013, at 6:12 AM, Lazare Inepologlou wrote: Long code is not always equivalent to readable code. A shorter syntax could improve readability in *some* cases. Long: $users->OrderBy( function( $x ){ return $x->Surname; } ); Short: $users->OrderBy( $x ==> $x->Surname ); I think your example proves the opposite. The fist example was much easier to read and understand than the second. That all depends on how many languages you're versed in, the short syntax above is common in many modern languages and has no clarity issues for me. -- -Clint -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
2013/2/21 Levi Morrison > On Thu, Feb 21, 2013 at 4:17 AM, David Muir wrote: > > > > On 21/02/2013, at 6:12 AM, Lazare Inepologlou > wrote: > > > >> 2013/2/20 Sanford Whiteman < > swhitemanlistens-softw...@cypressintegrated.com> > >> > It still looks like some random characters bashed together by a monkey > with a keyboard. > >>> > >>> +1, I am a fiend for ternary expressions and crazy one-liners, but > >>> this makes me want to go back and unroll everything I've ever done > >>> into readable code. :) > >>> > >> > >> Long code is not always equivalent to readable code. A shorter syntax > could > >> improve readability in *some* cases. > >> > >> Long: > >> $users->OrderBy( function( $x ){ return $x->Surname; } ); > >> > >> Short: > >> $users->OrderBy( $x ==> $x->Surname ); > >> > > > > I think your example proves the opposite. The fist example was much > easier to read and understand than the second. > > > > Obviously that's up to interpretation; I think the second is better > though I don't understand why `==>` is there instead of something > simpler. > It's just an example, and it's not important. I wanted to use something that is similar to the key-value mapping operator, but not the same. What is important is that the short version is declarative: emphasis is put to what to do, not how to do it. The mechanics are not exposed, and this is why some may find it harder to understand at first sight. Lazare INEPOLOGLOU Ingénieur Logiciel
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Thu, Feb 21, 2013 at 4:17 AM, David Muir wrote: > > On 21/02/2013, at 6:12 AM, Lazare Inepologlou wrote: > >> 2013/2/20 Sanford Whiteman >> It still looks like some random characters bashed together by a monkey with a keyboard. >>> >>> +1, I am a fiend for ternary expressions and crazy one-liners, but >>> this makes me want to go back and unroll everything I've ever done >>> into readable code. :) >>> >> >> Long code is not always equivalent to readable code. A shorter syntax could >> improve readability in *some* cases. >> >> Long: >> $users->OrderBy( function( $x ){ return $x->Surname; } ); >> >> Short: >> $users->OrderBy( $x ==> $x->Surname ); >> > > I think your example proves the opposite. The fist example was much easier to > read and understand than the second. > Obviously that's up to interpretation; I think the second is better though I don't understand why `==>` is there instead of something simpler. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 21/02/2013, at 6:12 AM, Lazare Inepologlou wrote: > 2013/2/20 Sanford Whiteman > >>> It still looks like some random characters bashed together by a monkey >>> with a keyboard. >> >> +1, I am a fiend for ternary expressions and crazy one-liners, but >> this makes me want to go back and unroll everything I've ever done >> into readable code. :) >> >> -- S. > > > Long code is not always equivalent to readable code. A shorter syntax could > improve readability in *some* cases. > > Long: > $users->OrderBy( function( $x ){ return $x->Surname; } ); > > Short: > $users->OrderBy( $x ==> $x->Surname ); > > > > Lazare INEPOLOGLOU > Ingénieur Logiciel I think your example proves the opposite. The fist example was much easier to read and understand than the second. Cheers, David -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
2013/2/20 Sanford Whiteman > > It still looks like some random characters bashed together by a monkey > > with a keyboard. > > +1, I am a fiend for ternary expressions and crazy one-liners, but > this makes me want to go back and unroll everything I've ever done > into readable code. :) > > -- S. > Long code is not always equivalent to readable code. A shorter syntax could improve readability in *some* cases. Long: $users->OrderBy( function( $x ){ return $x->Surname; } ); Short: $users->OrderBy( $x ==> $x->Surname ); Lazare INEPOLOGLOU Ingénieur Logiciel
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
> It still looks like some random characters bashed together by a monkey > with a keyboard. +1, I am a fiend for ternary expressions and crazy one-liners, but this makes me want to go back and unroll everything I've ever done into readable code. :) -- S. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Tue, 19 Feb 2013, Levi Morrison wrote: > > Have you considered how this will work/look in an array? > > > > $a = [$b => ($n) $m => $m * $n]; // wat. > > First off, it should be: > > $a = [$b => ($n) |$m| => $m * $n]; > > The || make a big difference in this situation. It still looks like some random characters bashed together by a monkey with a keyboard. cheers, Derick -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 02/19/2013 09:45 AM, Marcello Duarte wrote: And "just for you" is also inaccurate. You will find that the technologies I've been referring to are becoming the tools you will use for DevOps, etc... tasks. Do you guys listen to people outside of internals? It would be good to have a feedback mechanism that actually involve PHP developers in real world projects. I take that if you are coding with other languages like C, all the time, that you may loose contact with the way things are done. I should add "don't flame existing developers" to https://blogs.oracle.com/opal/entry/the_mysterious_php_rfc_process (Note that "In summary" paragraph at the end). Without getting into the merits of the syntax change, I will say that the RFC is missing a lot: who will write the patch, where are examples of syntax in other languages, where is the clear comparison with existing PHP syntax, what are the quantifiable benefits. Don't forget to update the RFC with the mail list comments, e.g. the BC issue. Even if your RFC is rejected, it will help future PHP development if the RFC contains a summary of mail list discussions. Chris -- christopher.jo...@oracle.com http://twitter.com/ghrd Newly updated, free PHP & Oracle book: http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
@Marcello: actually, I am also of the idea that there's no real additional value in such a syntax... Since I'm using ZF2 (yeah, that framework that converts array to applications) I am kinda used to have dozens of `function () {}` closures for service factories: so far no problems with it. As stated before, it spares 9 chars while the end developer (devops or whoever coding instead of of the devops) loses a lot of readability that is not really such a big problem. Also, as it is for DSLs, you could always use a parser to handle this kind of thing in your own domain. What exactly is the limit that you see when applying the more verbose `function () {}` syntax? I am just wondering since moving to `{}` will still not make this portable to any platform except PHP itself. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 19 Feb 2013, at 17:32, Leigh wrote: > > On 19 February 2013 16:46, Marcello Duarte wrote: > I find that more and more my developers have to learn ruby just to be able to > work in our projects. We are one of the largest PHP shops in Europe and even > the proprietary tools we are writing for DevOps stuff we are writing in Ruby. > This small syntax arrangement would make it possible to write DSLs in PHP. > The result is that I can have my PHP developers focusing on one language only > and get the job done. The problem of the web is a bit more complex now, if > you look on all you need to develop and deploy a large PHP application. > > That is one of the choices you made for your projects. You looked at what was > available, and decided that Ruby was the best choice for the task at hand. > > While I agree it's unfortunate that your developers to have to waste their > time learning Ruby, when they could be doing more productive things, that > doesn't mean it's a good idea to try and retrofit some evil syntax into PHP > "just for you", no matter how large an organisation you are. I am curious: "evil syntax"? I am not attached to the syntax I have described. I am open to discuss the syntax. It would be good with using the callable as last argument converted into a block for DSLs. I don't think this is evil, but I don't want to fall into a personal taste debate. I want something I can use. And "just for you" is also inaccurate. You will find that the technologies I've been referring to are becoming the tools you will use for DevOps, etc... tasks. Do you guys listen to people outside of internals? It would be good to have a feedback mechanism that actually involve PHP developers in real world projects. I take that if you are coding with other languages like C, all the time, that you may loose contact with the way things are done. > By the way, PHP is open source, feel free to make the parser do whatever you > want. > > > > On 19 February 2013 16:40, Levi Morrison wrote: > > Say we agree on the syntax above > >> ($n) |$m| => $m * $n; > > What happens when my one liner function needs to do one more operation > > like checking the value of $n before multiplication? > > As I stated before suggesting the syntax: It's only meant for a single > expression. It's purposefully NOT intended to cover multiple > expressions. In that case the current (verbose) syntax is better for > all criteria I care about. Additionally, neither Python nor Dart > allows multiple expressions in their short-syntax functions. > > I prefer this. In this case (imho), a simplified syntax *should* go hand in > hand with simplified functionality. If PHP is to adopt such a syntax I'd much > prefer it takes the single expression approach. This does achieve the goals > of easy readability and maintenance because you know the expression is bound > by certain limitations. > -- Marcello Duarte Head of Training Inviqa enterprise open source e-mail: marce...@inviqa.com mobile: +44 78 3316 8193 phone: +44 20 3179 9555 twitter: @_md @Inviqa inviqa.com Disclaimer This email and any attachments may be confidential and are intended solely for the use of the addressee. Any views or opinions expressed are those of the author and may not represent those of Inviqa. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone. Please contact the sender if you believe you have received this email in error.
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 19 February 2013 16:46, Marcello Duarte wrote: > I find that more and more my developers have to learn ruby just to be able > to work in our projects. We are one of the largest PHP shops in Europe and > even the proprietary tools we are writing for DevOps stuff we are writing > in Ruby. This small syntax arrangement would make it possible to write DSLs > in PHP. The result is that I can have my PHP developers focusing on one > language only and get the job done. The problem of the web is a bit more > complex now, if you look on all you need to develop and deploy a large PHP > application. > That is one of the choices you made for your projects. You looked at what was available, and decided that Ruby was the best choice for the task at hand. While I agree it's unfortunate that your developers to have to waste their time learning Ruby, when they could be doing more productive things, that doesn't mean it's a good idea to try and retrofit some evil syntax into PHP "just for you", no matter how large an organisation you are. By the way, PHP is open source, feel free to make the parser do whatever you want. On 19 February 2013 16:40, Levi Morrison wrote: > > Say we agree on the syntax above > >> ($n) |$m| => $m * $n; > > What happens when my one liner function needs to do one more operation > > like checking the value of $n before multiplication? > > As I stated before suggesting the syntax: It's only meant for a single > expression. It's purposefully NOT intended to cover multiple > expressions. In that case the current (verbose) syntax is better for > all criteria I care about. Additionally, neither Python nor Dart > allows multiple expressions in their short-syntax functions. > I prefer this. In this case (imho), a simplified syntax *should* go hand in hand with simplified functionality. If PHP is to adopt such a syntax I'd much prefer it takes the single expression approach. This does achieve the goals of easy readability and maintenance because you know the expression is bound by certain limitations.
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
> Have you considered how this will work/look in an array? > > $a = [$b => ($n) $m => $m * $n]; // wat. First off, it should be: $a = [$b => ($n) |$m| => $m * $n]; The || make a big difference in this situation. Secondly, if you hit a situation where the syntax is confusing, use a less confusing syntax if possible. This goes for any type of syntactic confusion, not just short-array syntax. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Tue, Feb 19, 2013 at 6:40 PM, Levi Morrison wrote: > > Say we agree on the syntax above > >> ($n) |$m| => $m * $n; > > What happens when my one liner function needs to do one more operation > > like checking the value of $n before multiplication? > > As I stated before suggesting the syntax: It's only meant for a single > expression. It's purposefully NOT intended to cover multiple > expressions. In that case the current (verbose) syntax is better for > all criteria I care about. Additionally, neither Python nor Dart > allows multiple expressions in their short-syntax functions. > > +1 A similar syntax was applied in C# lambads. For example : m => m * n. Though C# allows to use code block in lambdas, I do think that we should focus on one-expression only, since the current callbacks syntax (function() { }) is great, I believe, for multiline code. > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 19 Feb 2013, at 14:16, Leigh wrote: >> >> >> I can understand that If you haven't tried to write a tool like >> capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see >> much value in implementing such things. >> >> > Your RFC doesn't go to great lengths to explain the value either. Pretend > the reader has no experience with any of those tools you mention, pretend > the only language they know is PHP, please explain where the value for this > syntax is in PHP? Very good feedback. Very much appreciated. I will see if I can expand on what I have that. Thank you. > I find the existing syntax easy to understand. I find the proposed syntax > disproportionally difficult and unintuitive in relation to any benefit it > is supposed to give. > > >> What is superfluous for is useful for other users. It would be useful >> building DSL. At my company we use loads of ruby tools for deploying, >> provisioning, etc. just because of the DSL they provide. The array short >> syntax was great news. Adding a short syntax for closures would make it >> possible to write such scripts in PHP – where the syntax would not stand on >> its way. >> >> > > > If Ruby is the right tool for the job, and PHP is not the right tool for > the job, the answer to which language to use seems obvious right? I find that more and more my developers have to learn ruby just to be able to work in our projects. We are one of the largest PHP shops in Europe and even the proprietary tools we are writing for DevOps stuff we are writing in Ruby. This small syntax arrangement would make it possible to write DSLs in PHP. The result is that I can have my PHP developers focusing on one language only and get the job done. The problem of the web is a bit more complex now, if you look on all you need to develop and deploy a large PHP application. > I disagree wholeheartedly that this proposed syntax would make code in any > way more readable, or maintainable. Please understand that there is a difference between code you write and other people maintain, and code you write for other people to use. The purpose of this feature is focused on the later, to allow the construction of DSLs, so users of your code can focus on the task at hand. -- Marcello Duarte -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
>> Say we agree on the syntax above >>> ($n) |$m| => $m * $n; >> What happens when my one liner function needs to do one more operation >> like checking the value of $n before multiplication? > > As I stated before suggesting the syntax: It's only meant for a single > expression. It's purposefully NOT intended to cover multiple > expressions. In that case the current (verbose) syntax is better for > all criteria I care about. Additionally, neither Python nor Dart > allows multiple expressions in their short-syntax functions. Have you considered how this will work/look in an array? $a = [$b => ($n) $m => $m * $n]; // wat. S -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
> Say we agree on the syntax above >> ($n) |$m| => $m * $n; > What happens when my one liner function needs to do one more operation > like checking the value of $n before multiplication? As I stated before suggesting the syntax: It's only meant for a single expression. It's purposefully NOT intended to cover multiple expressions. In that case the current (verbose) syntax is better for all criteria I care about. Additionally, neither Python nor Dart allows multiple expressions in their short-syntax functions. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Tue, 19 Feb 2013 16:31:39 -, Marcello Duarte wrote: On 19 Feb 2013, at 16:29, Morfi wrote: ($n) => { echo $n; } ($n) use ($m) => { echo $n; } Morfi, the problem pointed out already is when you have no arguments it would be the same as the statement block, which would cause BC issues. Why not () => { echo $n; } then? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 19 Feb 2013, at 16:29, Morfi wrote: > ($n) => { echo $n; } > ($n) use ($m) => { echo $n; } Morfi, the problem pointed out already is when you have no arguments it would be the same as the statement block, which would cause BC issues. > On Tue, Feb 19, 2013 at 8:11 PM, Levi Morrison wrote: > >>> IF (and I stress if) we add a a shorter anonymous function syntax I'd >>> like it to be geared towards one-liners because that's where the >>> current syntax feels really verbose, especially when you close over >>> other variables: >>> >>>function ($n) use ($m) { return $m * $n; } >>> >>> Versus one potential option: >>> >>>($value) |$m| => $m * $n; >> >> My apologies, this was meant to read: >> >>($n) |$m| => $m * $n; >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > Best regards, Andrey -- Marcello Duarte marcello.dua...@gmail.com http://marcelloduarte.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
($n) => { echo $n; } ($n) use ($m) => { echo $n; } On Tue, Feb 19, 2013 at 8:11 PM, Levi Morrison wrote: > > IF (and I stress if) we add a a shorter anonymous function syntax I'd > > like it to be geared towards one-liners because that's where the > > current syntax feels really verbose, especially when you close over > > other variables: > > > > function ($n) use ($m) { return $m * $n; } > > > > Versus one potential option: > > > > ($value) |$m| => $m * $n; > > My apologies, this was meant to read: > > ($n) |$m| => $m * $n; > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Best regards, Andrey
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Hello, On Tue, Feb 19, 2013 at 6:09 PM, Levi Morrison wrote: > There's already been an overwhelming negative reaction to this > particular proposed syntax so I won't belabor the point much. In > short, this is too similar to block statements and does have BC > issues. > > -- > > IF (and I stress if) we add a a shorter anonymous function syntax I'd > like it to be geared towards one-liners because that's where the > current syntax feels really verbose, especially when you close over > other variables: > > function ($n) use ($m) { return $m * $n; } > > Versus one potential option: > > ($value) |$m| => $m * $n; > > This syntax is short and expressive at the expense of clarity. > Basically all short-syntax has that trade-off, so I am personally fine > with it. The only other potential problem I see is parsing it; someone > more familiar with PHP's parser would have to verify whether that > would be a problem. > I think that before we establish a syntax for this we should see if there's a real need for this feature, and after that, get a syntax to implement the feature. Say we agree on the syntax above > ($n) |$m| => $m * $n; What happens when my one liner function needs to do one more operation like checking the value of $n before multiplication? I'd rather see a proposal to drop the 'function' keyword from the classes methods and only leave the visibility scope and method name, but for anonymous functions like this one I'd rather keep the 'function' keyword in order to have better visibility when I'm doing a code review/scan new code in a library. What do you think? Florin Patan https://github.com/dlsniper -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
> IF (and I stress if) we add a a shorter anonymous function syntax I'd > like it to be geared towards one-liners because that's where the > current syntax feels really verbose, especially when you close over > other variables: > > function ($n) use ($m) { return $m * $n; } > > Versus one potential option: > > ($value) |$m| => $m * $n; My apologies, this was meant to read: ($n) |$m| => $m * $n; -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
There's already been an overwhelming negative reaction to this particular proposed syntax so I won't belabor the point much. In short, this is too similar to block statements and does have BC issues. -- IF (and I stress if) we add a a shorter anonymous function syntax I'd like it to be geared towards one-liners because that's where the current syntax feels really verbose, especially when you close over other variables: function ($n) use ($m) { return $m * $n; } Versus one potential option: ($value) |$m| => $m * $n; This syntax is short and expressive at the expense of clarity. Basically all short-syntax has that trade-off, so I am personally fine with it. The only other potential problem I see is parsing it; someone more familiar with PHP's parser would have to verify whether that would be a problem. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
I also don't like the RFC proposed syntax. I have to say that I don't really like those short magic-like syntax things in in other languages too. If you work with them on the day-to-day basis and tools are built around those concepts - it's one thing. In PHP syntax is mostly self-explanatory and for the most part there is only one way to do it (or the differences in syntax have their own uses - like for () {} is used in code and for (): endfor; is good for templates). I like the current $x = function () {}. It's the same in JavaScript (and because most of us use jQuery - we use it a lot) and realistically I don't type it - IDE does auto-complete for me. P.S. I want to tell all those syntax enhancement guys - don't push syntax-sugar stuff into PHP for the sake of shorter syntax. First, for the most part it looks alien in PHP. Second - it really depends on the preception - I for example hate Ruby syntax, it's crap and unreadable - this just illustrated that's one mans beauty is other mans ugly. PHP syntax maybe not the most pretty out there, but it is sure as hell easy to read even if coder makes a mess of it. I saw the opinion on the internet that PHP is a scripted version of C in the sense of their positioning and usage. And I totally agree with it, and I want it to stay that way. PHP should not be the pretty one, or be on the feature edge. PHP needs to just walk with time and adopt the good stuff fully integrating into itself, not just patching the core and adding some half-weird syntax that just doesn't really fit PHP. You also have to remember that PHP is a WEB development script language, not general purpose script language like Ruby or Python. Not all features, that are good in general purpose languages, are good for WEB language. Some of those features may bring performance hits that are not worth it. My 0.02$, Arvids.
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
> > > I can understand that If you haven't tried to write a tool like > capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see > much value in implementing such things. > > Your RFC doesn't go to great lengths to explain the value either. Pretend the reader has no experience with any of those tools you mention, pretend the only language they know is PHP, please explain where the value for this syntax is in PHP? I find the existing syntax easy to understand. I find the proposed syntax disproportionally difficult and unintuitive in relation to any benefit it is supposed to give. > What is superfluous for is useful for other users. It would be useful > building DSL. At my company we use loads of ruby tools for deploying, > provisioning, etc. just because of the DSL they provide. The array short > syntax was great news. Adding a short syntax for closures would make it > possible to write such scripts in PHP – where the syntax would not stand on > its way. > > If Ruby is the right tool for the job, and PHP is not the right tool for the job, the answer to which language to use seems obvious right? I disagree wholeheartedly that this proposed syntax would make code in any way more readable, or maintainable.
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Hi Marcello, Am 19.02.2013 um 14:51 schrieb Marcello Duarte : > Thanks for the feedback. I get most people here don't appreciate the value of > the feature. > > I can understand that If you haven't tried to write a tool like capistrano, > rspec, chef, puppet, etc, etc in PHP you probably won't see much value in > implementing such things. > > On 19 Feb 2013, at 13:19, Derick Rethans wrote: >> On Tue, 19 Feb 2013, Marcello Duarte wrote: >> >>> Inspired by Sara, here is another RFC, I finally got around to draft: >>> >>> https://wiki.php.net/rfc/short-syntax-for-anonymous-function I don’t like the syntax, but the proposal in general. If you compare PHPs syntax to various others, it is indeed clumsy. Python: map(lambda v: v * 2, [1, 2, 3]) Ruby: [1, 2, 3].map{|x| x * 2} Scala: List(1, 2, 3).map((x: Int) => x * 2) PHP: array_map(function ($x) {return $x * 2;}, [1, 2, 3]); So even a statically typed language like Scala is shorter and better to read. A good improvement would be implicit return and getting rid of the function keyword. array_map(($x): $x * 2;, [1, 2, 3]); But this RFC should come with a patch, otherwise we are discussing things that aren’t necessarily easy to implement. cu, Lars -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Thanks for the feedback. I get most people here don't appreciate the value of the feature. I can understand that If you haven't tried to write a tool like capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see much value in implementing such things. On 19 Feb 2013, at 13:19, Derick Rethans wrote: > On Tue, 19 Feb 2013, Marcello Duarte wrote: > >> Inspired by Sara, here is another RFC, I finally got around to draft: >> >> https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > I'd be really reluctant to add this -- it's yet another (superfluous) > syntactical sugar, there is no patch, and how does this work with bound > variables (use keyword)? I added an example with the use keyword. What is superfluous for is useful for other users. It would be useful building DSL. At my company we use loads of ruby tools for deploying, provisioning, etc. just because of the DSL they provide. The array short syntax was great news. Adding a short syntax for closures would make it possible to write such scripts in PHP – where the syntax would not stand on its way. On 19 Feb 2013, at 13:28, Patrick ALLAERT wrote: >> BC break detected: >> >> > { >>echo "foo\n"; >>return "bar"; >> }; >> >> echo "baz\n"; >> return 42; >> ?> I am actually more concerned with Patrick's feedback regarding BC. I can't think of a solution for this right now. > cheers, > Derick > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Marcello Duarte
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Hello, On Tue, Feb 19, 2013 at 2:57 PM, Marcello Duarte wrote: > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > Please feedback, > -- > Marcello Duarte > I really don't like syntax for this. It makes it hard to follow. Removing a couple of characters while making the syntax harder to follow isn't a good thing imho. Also it's a BC break, like Patrick mentioned. Have a nice day, Florin Florin Patan https://github.com/dlsniper -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Hi, I don't really like to write every time a "long" 'function()', only for passing a little callback like 'function ($v) { var_dump($v); }'...: Nice proposal, but writing the last argument outside of the function call could be confusing... An user-function is not a language construct (like while etc.) regards, Bob Am 19.2.2013 um 13:57 schrieb Marcello Duarte : > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > Please feedback, > -- > Marcello Duarte -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
2013/2/19 Marcello Duarte : > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > Please feedback, > -- > Marcello Duarte BC break detected: The {} would probably be a closure that is not assigned to anything while the current behaviour is to print "foo" and exit while returning "bar". -1 since it only saves 10 chars ("function()") without real added value. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
I also am not in favour of the syntax, it's too short and quirky. I'm honestly fine with 'function()' it's very explicit On Tue, Feb 19, 2013 at 1:20 PM, Anthony Ferrara wrote: > Marcello, > > > On Tue, Feb 19, 2013 at 7:57 AM, Marcello Duarte > wrote: > > > Inspired by Sara, here is another RFC, I finally got around to draft: > > > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > > > Please feedback, > > -- > > Marcello Duarte > > > > > I like the concept. I dislike the syntax. It looks too much like a JSON > object declaration, and it feels like it should be returning an object > instead of a closure/anonymous function. Additionally, I don't like that > it's also a closure. Short functions like this should be for simple > functions... > > Perhaps: > > lambda $x: trim($x); > > $x: trim($x); > > Or something similar... > > Anthony >
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On 19 February 2013 13:57, Marcello Duarte wrote: > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > Please feedback, > > Duh, I don't think function(){} is long. -- Regards, Mike
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
Marcello, On Tue, Feb 19, 2013 at 7:57 AM, Marcello Duarte wrote: > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function > > Please feedback, > -- > Marcello Duarte > > I like the concept. I dislike the syntax. It looks too much like a JSON object declaration, and it feels like it should be returning an object instead of a closure/anonymous function. Additionally, I don't like that it's also a closure. Short functions like this should be for simple functions... Perhaps: lambda $x: trim($x); $x: trim($x); Or something similar... Anthony
Re: [PHP-DEV] [RFC] Short syntax for anonymous functions
On Tue, 19 Feb 2013, Marcello Duarte wrote: > Inspired by Sara, here is another RFC, I finally got around to draft: > > https://wiki.php.net/rfc/short-syntax-for-anonymous-function I'd be really reluctant to add this -- it's yet another (superfluous) syntactical sugar, there is no patch, and how does this work with bound variables (use keyword)? cheers, Derick -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] [RFC] Short syntax for anonymous functions
Inspired by Sara, here is another RFC, I finally got around to draft: https://wiki.php.net/rfc/short-syntax-for-anonymous-function Please feedback, -- Marcello Duarte