Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122372 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id BBAB51ACEBF for ; Wed, 14 Feb 2024 23:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707954512; bh=/NRfmrKx6kbLzTREaRssyF1Icsbynsqb/CRvaQTyM6M=; h=References:In-Reply-To:From:Date:Subject:To:From; b=V5S5CVvls3gVAlcltXprrq+x9uhWdqPcdpFDUKmEMyZ2na092XCKZ/XiTrktdz4AR gyNcMVPPUYAm0Rc3+xic4cy64MkmHE/5+iV737qb1froe3Fn88UUJcmwUWIE+GYgEu ipcscN7UZXeyL09FuotCtLwnV97o18GRz0V+RJhCHkBz0MSDMMJmEbFGEI6HLGvpDF RYeHBFchy121P4QZD4BG4lqoL/2UyDe2CkJmb5HEokjOfK2SzT+T2sSwPdhoaMSK6e YUvPv3BintjfcBmD7L7YGH2S/VL+B2N8S4KLBYqwEdgqDoJRzx+gH/dyc/WQQ6qCXQ qdky3nsCgxTzA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 56DE4180953 for ; Wed, 14 Feb 2024 15:48:31 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <6562680@gmail.com> Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 14 Feb 2024 15:48:30 -0800 (PST) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-595d24ad466so166065eaf.0 for ; Wed, 14 Feb 2024 15:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707954509; x=1708559309; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=oSlWRdWJ2Mpq/+PH2IHq2BCcKQLztfBWKOHy0jnIn7Q=; b=YYsEzYSmp0hToiaKsMqsmcGkq1MUVSJjtisnh6yEFG+VofRA08T7+BmQI8JAz1Qwkh l8upf7dFGF0jXNRCa3xhul5ou3WUc0D9pLsH4oRlKa8YX+RHCxGkOPzL1Dub5ybs3rD+ uWN6iLaESY6CwXtYv0HsK7bAz16IlLRaCCNu0GC7QOBjk6D5u+SnheS/w2W0QsjBYlJk FRZtBU2cmQ/ZAcFPqhyybtyEQ5CUGJO/Fg6Vft2ogYoUQ2QVAABK8K1ahGxDUdrZdwpx 8HN668PxgUmHJVzvAiIeAmaScuXYZpB16kKsnUMLU0E5GY6yhd6RokAr+W62fTY29gSm faRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707954509; x=1708559309; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oSlWRdWJ2Mpq/+PH2IHq2BCcKQLztfBWKOHy0jnIn7Q=; b=Z9urY8X2d85YhDGzvPA6mNMZx3Vy06Qy2J3YukiASa138ChZy6kq8vaJASYL+IF/6+ Slb1g0SRP2oNkTsWj8O52PrkfiGCTSQtfl2fxj7dlqncldv/OJ0si1MGUaIBzE2fALgb jAZJCAjZPoFFxtU87BPgzCgtZHdAtFCizSxj1wsPBFE6/WzztKwl6h5kLeMV6wmsU7Y4 z52ze0YirALuOCo0dDXTKJ53mPC0MoonHS+2mYIZ+zB1C4DMcncme6t8K6vUS84k375p mEu6BfXFnEMQAhxwuUb3ztUAxjGhTR9ibxu7GveifhHUG4TWNxv+NwjA7rjqe8XUzJqT dwtg== X-Forwarded-Encrypted: i=1; AJvYcCVp9n4g9BL7HO+FnHm3C6fnzXnDRVJE3yZqiHfRIj+Cgty7xQKWFzNCxqrwOU2ZEHCyHSzlLkO0TDHFqYpi+7MaNSF1PKjIdQ== X-Gm-Message-State: AOJu0Yxj7wKtXxHhPAaLwIea45d3bD2QWbCVVqbGM20jGhaA4b9/jGof hkRyopmIqa020FAtbYRfAK0Hehz5YotFSHEz1K1EJWZl+6Z4WxuBZIFIWAJ8qpWq/zJbEEwOE6h xAV6obXDVkiHADDrySDBnsO4NbeM= X-Google-Smtp-Source: AGHT+IHU6HbE5xZCkfX2OX3WIXEv2UXaoDbglWmwqbB37JHJbP9M4gRrPuv7eFaXMVhCXZzmE3eH2ojQPU2EmGvRzYY= X-Received: by 2002:a4a:7605:0:b0:59a:12e1:c3c3 with SMTP id t5-20020a4a7605000000b0059a12e1c3c3mr246432ooc.4.1707954509219; Wed, 14 Feb 2024 15:48:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: =?UTF-8?B?Yg==?= <6562680@gmail.com> Date: Thu, 15 Feb 2024 02:47:52 +0300 Message-ID: Subject: Re: [PHP-DEV] [Discussion] Thoughts on casting to null To: Robert Landers , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000d08cd706116025a9" From: 6562680@gmail.com (=?UTF-8?B?0JPRgNC40LPQvtGA0LjQuSBTZW5pb3IgUEhQIC8g0KDQsNC30YDQsNCx0L7RgtGH0LjQuiBXZQ==?==?UTF-8?B?Yg==?=) --000000000000d08cd706116025a9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I don't even know why lambda realization is not the same as in javascript. ``` let action =3D function () { console.log('hello'); return 1; } let fn1 =3D () =3D> action(); console.log(fn1()); // calls hello(), returns 1, for me, not a best way, could be read like "call action() then create function that returns result of that call" let fn2 =3D () =3D> (action()); console.log(fn2()); // calls hello(), returns 1, common, short way // what's this? (() =3D> ())(); // could look strange? no, its declaring unnamed function that does nothing and returns nothing and calls it immediately. let fn3 =3D () =3D> { action(); } console.log(fn3()); // calls hello(), returns undefined, common, short without return let fn4 =3D () =3D> action; console.log(fn4()); // returns function, very handy for Promises, that start init function immediate on new call, so it wraps function to "task" available to call it later somewhere, maybe in another promise ``` Why is the PHP implementation redesigned from scratch instead of using the idea of the one that works? ps. Guess, the discussion to change syntax that you cold rewrite with single line: ``` // > what? // fn() =3D> $client->ping() ? null : null // > that // static function () { $client->ping(); } ``` Ahh, the main problem in fn() is exactly that you don't like.... `use` statement)))) So long to write the `use` keyword. =D0=90nd you prefer the `js` implementation, which automatically uses the current scope in your callback. And you need something handy, that is allow create functions: - with all variables (copy local state) - with short syntax - with return modes variety - with return types and parameter types, if you need it is more interesting, than talk about error collection that requires rewriting half of the app As I remember you say, you work on projects with a million lines of code and you prefer correctness instead of simplification. Why do you use short functions then? OOP awaits you. Create a function that wraps function: 1. one function returns result (client.ping()) 2. second one returns null|result (myclass.clientPingOrNull()) 3. The third one catches the first one with a try catch to return the result and return errors (myclass.tryClientPingOrNull()) 4. then call that batch of correctness in your callback... Sorry, couldn't resist myself --000000000000d08cd706116025a9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I don't even know why lambda realization is not the same as= in javascript.

```
let action =3D function () {
console.log(= 'hello');

return 1;
}

let fn1 =3D () =3D> acti= on();
console.log(fn1()); // calls hello(), returns 1, for me, not a bes= t way, could be read like "call action() then create function that ret= urns result of that call"

let fn2 =3D () =3D> (action());console.log(fn2()); // calls hello(), returns 1, common, short way

= // what's this?
(() =3D> ())(); // could look strange? no, its de= claring unnamed function that does nothing and returns nothing and calls it= immediately.

let fn3 =3D () =3D> { action(); }
console.log(fn= 3()); // calls hello(), returns undefined, common, short without return
=
let fn4 =3D () =3D> action;
console.log(fn4()); // returns functi= on, very handy for Promises, that start init function immediate on new call= , so it wraps function to "task" available to call it later somew= here, maybe in another promise
```

Why is the PHP implementation = redesigned from scratch instead of using the idea of the one that works?
ps. Guess, the discussion to change syntax that you cold rewrite with = single line:

```
// > what?
// fn() =3D> $client->pin= g() ? null : null

// > that
// static function () { $client-&g= t;ping(); }
```

Ahh, the main problem in fn() is exactly that you= don't like.... `use` statement)))) So long to write the `use` keyword.=

=D0=90nd you prefer the `js` implementation, which automatically us= es the current scope in your callback.

And you need something handy,= that is allow create functions:
- with all variables (copy local state)=
- with short syntax
- with return modes variety
- with return typ= es and parameter types, if you need it

is more interesting, than tal= k about error collection that requires rewriting half of the app

As = I remember you say, you work on projects with a million lines of code and y= ou prefer correctness instead of simplification.

Why do you use shor= t functions then? OOP awaits you.

Create a function that wraps funct= ion:
1. one function returns result (client.ping())
2. second one ret= urns null|result (myclass.clientPingOrNull())
3. The third one catches t= he first one with a try catch to return the result and return errors (mycla= ss.tryClientPingOrNull())
4. then call that batch of correctness in your= callback...

Sorry, couldn't resist myself
--000000000000d08cd706116025a9--