Re: [RFC] [Discussion] Short Closures
| From: | Tony Marston | Date: | Tue, 01 Sep 2015 08:45:38 +0000 |
| Subject: | Re: [RFC] [Discussion] Short Closures | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87981@lists.php.net to get a copy of this message | ||
"Yasuo Ohgaki" wrote in message news:CAGa2bXZpUd0J86D-VLSC+fUKhzRJk_3Qu_5afkG0bM+DE7XYew@mail.gmail.com...
Hi Anthony and Bob, On Tue, Sep 1, 2015 at 2:53 PM, Anthony Ferrara <ircmaxell@gmail.com> wrote:This argument is irrelevant for several reasons: (1) I am not familiar with any of those languages, nor are many PHP users. (2) Just because other languages have such a feature is not a good reason for adding it into PHP. (3) Introducing write-only (less readable or completely unreadable) code will ALWAYS be a barrier to those who have used nothing but PHP for the last 10+ years. As H. Abelson and G. Sussman wrote in 1984: "Programs must be written for people to read, and only incidentally for machines to execute." Writing compact code which has several functions compressed into a single line may be clever where you come from, but it leaves new readers scratching their heads saying "WTF!!". As a follower of the KISS principle I always aim to write simple, readable code, and my critics always say "It is too simple. Proper OO is supposed to be more complex than that". The mark of genius is to achieve complex things in a simple manner, not to achieve simple things in a complex manner. -- Tony MarstonMost programming languages today have a "short form" closure or lambda syntax HackLang: ($x) ==> $x + 1; C++: [](int x) -> int { return x + 1; } Java: (int x) -> x + 1; Python: lambda x: x+1 Ruby: lambda |x| { x + 1 } Rust: |x| x + 1 JavaScript (ES6): x => x + 1 C#: x => x + 1 Objective C: ^(int x) { return x + 1; }Nice summary! The syntax may look strange at first, but proposed syntax is close enough to other languages. There will be no barrier for our users in the long run.