Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112849 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72659 invoked from network); 12 Jan 2021 16:35:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jan 2021 16:35:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6032D1804E2 for ; Tue, 12 Jan 2021 08:13:53 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 12 Jan 2021 08:13:52 -0800 (PST) Received: by mail-io1-f52.google.com with SMTP id r9so5183367ioo.7 for ; Tue, 12 Jan 2021 08:13:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=401tvZOaoq1ptH37qox1pvYHFbaHc/NgqbnbFQ9yZoo=; b=hzBBSJ0Fe/Yz4T9NyLdByZr1JRQsNrMpuqI0kSPSZfcxtE/v3pJyx8rGExow/aXnda 97Dwcq34Ir9e5qnkYVgkUv3gug+QRvy6yBKEykiKfsYqYUlsykAoEqzgsPSDjsE1dYvz Jm/ltANWJIeRLvBCpqz6XzbkWEwa6FopX6lztQh6WYOELw9eR5UOvpowhhrs6y7Xd5Lg jm/VYqXyRxTaET4IcGiAxmY8gnGbXPlawRdOZrZh17Y5wKiypTu9T6qE7oypnwUXq5sn fDw04GpJpRZQY22ihmUM8+Y7NsRpGp5OmsIKsnKyyjtiDogd1GoOe5T+992Y39LrkY1y jJgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=401tvZOaoq1ptH37qox1pvYHFbaHc/NgqbnbFQ9yZoo=; b=diG9neqjejLG19mmxwk8cjxIbsk5Q7tyxd9agGqX4Jf8r+k2ehdboEWJ+ToFuLLDjf 4gszdXShjMxJFX0sQHDHj66jSTpc28remh3xGr4LuIy3opucmMnaesJzhGpyfr19EawR k5CDs16qE4p0wETNJF34QBJeO/Y1wsY6M1UCkM7843xqxxbZmFW97qRXhgbClcsg8lmY S7HrwAV0LFJu4IjHnKyq1hPX8sVziFgXEIBosLZzNG8i/U0hq5+wlAOL7B+e1YKk6stZ +RTrHKU5D7yiq9LMhca44x/SPvJzKM7a8znqW/NECkCspJ3UhBwcp1MPg923uOhXBeYg y/Gw== X-Gm-Message-State: AOAM531R/NeY53QZiCM4phsWT2danlBQa7xPXyvzqYT8u+N/OxmsOHkr G/fGCVhnptuyD9HuqxLa24Wi9mnH0wPXN3Xn X-Google-Smtp-Source: ABdhPJyiw2QTvJOqa1QMsw5dxhN7zuZ0SeCTDv38nxt4hEtnhyNQc5AWIvf+AHcSOJniu3E5hWROxw== X-Received: by 2002:a02:e87:: with SMTP id 129mr121529jae.34.1610468029732; Tue, 12 Jan 2021 08:13:49 -0800 (PST) Received: from [10.10.42.56] ([96.61.105.82]) by smtp.gmail.com with ESMTPSA id s4sm2285611ioc.33.2021.01.12.08.13.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 08:13:49 -0800 (PST) Message-ID: <1183F48B-57BB-4CBE-8474-CF1D7DFD7F6E@benramsey.com> Content-Type: multipart/signed; boundary="Apple-Mail=_835A2195-479C-4462-AC09-80D6A9FC552B"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Date: Tue, 12 Jan 2021 10:13:47 -0600 In-Reply-To: <26074258-B6B5-40EA-A043-E3FAD1FB5365@newclarity.net> Cc: Larry Garfield , php internals To: Mike Schinkel References: <490416F4-7E2F-454F-A317-43212CA6C2D1@benramsey.com> <28f44744-4dc5-4cb8-8751-6b66386119fa@www.fastmail.com> <26074258-B6B5-40EA-A043-E3FAD1FB5365@newclarity.net> X-Mailer: Apple Mail (2.3654.40.0.2.32) Subject: Re: [PHP-DEV] "TryX" idom for Enumerations From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_835A2195-479C-4462-AC09-80D6A9FC552B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 11, 2021, at 19:09, Mike Schinkel wrote: >=20 >> On Jan 11, 2021, at 6:52 PM, Larry Garfield = wrote: >>=20 >> On Mon, Jan 11, 2021, at 2:27 PM, Ben Ramsey wrote: >>>> On Jan 10, 2021, at 20:09, Larry Garfield = wrote: >>>>=20 >>>> On Sun, Jan 10, 2021, at 4:40 PM, Mark Randall wrote: >>>>> On 10/01/2021 21:27, Larry Garfield wrote: >>>>>> The "a method that begins with try is nullable, so watch out" = idiom is present in C# and Rust, but to my knowledge has never existed = in PHP. That doesn't make it bad; it actually combines quite well with = the null coalesce operator to allow for default values, making a = valueOrDefault() method unnecessary. >>=20 >>=20 >>> I have no problem introducing this idiom (or similar). In fact, I = welcome it. >>>=20 >>> In userland, the same concept is often achieved with methods like >>> `fromOrNull()`, and as Mark points out, the word =E2=80=9Ctry=E2=80=9D= makes me think >>> the method should throw an exception if it fails. I=E2=80=99m not = advocating >>> for `xOrNull()`, though, since I think that smacks of Hungarian >>> notation, but maybe we can come up with something that is a more >>> PHP-ish name. ;-) >>>=20 >>> =E2=80=9CThere are two hard things in computer science: cache = invalidation, >>> naming things, and off-by-one errors.=E2=80=9D --Phil Karlton >>>=20 >>> Cheers, >>> Ben >>=20 >> Do you have a suggestion for a better, more PHP-ish naming = convention? >=20 > maybeFrom()? I think a `maybeX()` idiom is better, though it might be confusing to = those familiar with functional programming languages that have a `Maybe` = data type. If we had generics, we could introduce a `Maybe` class, and these = methods could return `Maybe`, for example. That said, maybe = `?self` is effectively the same thing? For me, `maybeX()` is great, but I=E2=80=99d like to hear any = objections/suggestions from others. Cheers, Ben --Apple-Mail=_835A2195-479C-4462-AC09-80D6A9FC552B Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCX/3KvAAKCRCwLZeYnIwH G4P2AP95YXT+N608YmWotvLHTOfZmqYk4S743xMMo/chgkKN9gD9EdIwK/G5g3N5 eATTE1wu0HJ60gq0oDQnLcrlqtp7iLA= =uPeq -----END PGP SIGNATURE----- --Apple-Mail=_835A2195-479C-4462-AC09-80D6A9FC552B--