Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112845 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96815 invoked from network); 12 Jan 2021 00:15:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jan 2021 00:15:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A11F1804E3 for ; Mon, 11 Jan 2021 15:53:22 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 Jan 2021 15:53:21 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 68F862216 for ; Mon, 11 Jan 2021 18:53:20 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Mon, 11 Jan 2021 18:53:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Dbhj/I2yIiAHdzihkn5dyyPu0Zgp573nF/PGoasHV 6o=; b=XNCWY4buvn6BI/MJYXLMtXMsjEGuWNU/UWHRrne9aiI3PpPj9vYnNLE7D m+4+08ohCVtT4UkQWWs366SAGdTEqHG0ozBmGN0878g+Py35IfuKMjnpkgkvTWAI 3W/IJd0ETHmpfPZ0LUEWxbqQe2s8QtOChRL9b9l/g35++YyWQoQr0FP9iFOfGOl9 dyC5qhcO/Le/mjHYqWU9ggyLpAJZZ08gbLjQFLufOIAnWIzgrBGi0WbGjJKwG86s qmYSDv7PcHmkip5tko+JbNi7DDKoBfAhLTEQDvL9MK5J3PzYsf2vCcFW6Zat5qYY f/4w7W9QecRKeQ1TqE7bN3A3x5LxQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdehvddgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8F9C514200A2; Mon, 11 Jan 2021 18:53:19 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-45-g4839256-fm-20210104.001-g48392560 Mime-Version: 1.0 Message-ID: <28f44744-4dc5-4cb8-8751-6b66386119fa@www.fastmail.com> In-Reply-To: <490416F4-7E2F-454F-A317-43212CA6C2D1@benramsey.com> References: <490416F4-7E2F-454F-A317-43212CA6C2D1@benramsey.com> Date: Mon, 11 Jan 2021 17:52:59 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] "TryX" idom for Enumerations From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jan 11, 2021, at 2:27 PM, Ben Ramsey wrote: > > On Jan 10, 2021, at 20:09, Larry Garfield w= rote: > >=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" idio= m is present in C# and Rust, but to my knowledge has never existed in PH= P. That doesn't make it bad; it actually combines quite well with the n= ull coalesce operator to allow for default values, making a valueOrDefau= lt() method unnecessary. > I have no problem introducing this idiom (or similar). In fact, I welc= ome it. >=20 > In userland, the same concept is often achieved with methods like=20 > `fromOrNull()`, and as Mark points out, the word =E2=80=9Ctry=E2=80=9D= makes me think=20 > the method should throw an exception if it fails. I=E2=80=99m not advo= cating=20 > for `xOrNull()`, though, since I think that smacks of Hungarian=20 > notation, but maybe we can come up with something that is a more=20 > PHP-ish name. ;-) >=20 > =E2=80=9CThere are two hard things in computer science: cache invalida= tion,=20 > naming things, and off-by-one errors.=E2=80=9D --Phil Karlton >=20 > Cheers, > Ben Do you have a suggestion for a better, more PHP-ish naming convention? "It's what other languages use and they don't have a problem" is a valid= argument, but not a slam dunk so alternate naming patterns are on the t= able. --Larry Garfield