Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124159 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 97EDA1A009C for ; Mon, 1 Jul 2024 20:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719865205; bh=cKJDnEuUVLH4RGKYl/yhWzct/W1tXAl/q5Z+59tfIlA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Mt9KIWz7XSWdE76i1rO0C68YIezRwoqeIK3iLY5jvUewNRvm9+17aO35gFz1eUt/L FOeSWVRi1il50FOSvod/diXCsBO1lqakTdgexVOaNqbd3BYHcoZ2A2Daq3ONEt9FM8 44W6JHN7xeUJQ3C+gbbXTwNKUGj3dycxRps2XkBq0U2nGvC74d2eUXOPwFlyFAEPhI 0zo4fu0aNcYHRFEVHRtFCn8aoSCBoP2ere6dglo56VSQbHSNespLiEhTyy758zVjSp MXTjZnMxImULxYHLW1vQhRIwd+fhRhUG4Aa78lfKEGPcUubvuwRbKgQoGDyC5GLylL 70qlNtljrmlFQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DB33418006E for ; Mon, 1 Jul 2024 20:20:04 +0000 (UTC) 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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Mon, 1 Jul 2024 20:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1719865121; bh=ZgUmyvFkbNRQC9lGJxsrNM3pHt2EjKgAaYab/0Jhdrs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=hBOfsOhcXGRIZ7KU/485kwawnze+ZxNr0x8ELyus/ox8WngridMzB9oq3YBV1TJRW 2rwj6J/4nxtUErcsOKsCMj2J8vqcOT3PDhV9E1BO4GuCFOkXKatBqSvxCQW8nyv/Kq 1wm0FcX09VIlXM05QvlmHFxAmRqzJFSWs+F4OydDfFNOfh1minumD60zE4ixXt+PzR 2O9sdB55WZ6VlRFmYSl31U3/Kp0F9dYmZ5b2MnmDKlNHHLEj7hN3lrhcdzI8t1Z+Hx fTnmdFtKFztCYO49GqcPKf+Q4rwtSo6AhbtfKcqGWONm7qt3MQGc/lbnp1fPLRu9ZA 5rjIhulzEYwgw== Message-ID: <8870a7d0-7b65-4ccf-b20c-e69a3c5fc7de@bastelstu.be> Date: Mon, 1 Jul 2024 22:18:37 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [discussion] Correctly name the rounding mode and make it an Enum To: Claude Pache Cc: "Gina P. Banyard" , Saki Takamachi , Jorg Sowa , php internals References: <9zUVZKaEYixjCLLhviQPYFQtSAEhsRMWL6xbKeogzAGsH-STebN9JqJxITAPVfdKTNu7gEs_m77OkIcOzaiscoajx8Hp8VWRKkhTTCPkGko=@gpb.moe> <6E690732-8BED-4A01-8385-648E7CEDFD9F@sakiot.com> <70f63dd2e0ba7959a9e3bb7fa68ce14a@bastelstu.be> <67d37d56-625f-4f80-805d-a5db2d3807bb@bastelstu.be> <0A9642EC-0FCC-4BC3-82C2-C6C968CD8D1C@gmail.com> Content-Language: en-US In-Reply-To: <0A9642EC-0FCC-4BC3-82C2-C6C968CD8D1C@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi please apologize the delay in getting back to you. I was absolutely swamped with mailing list mails, other work and I didn't want to give a reply that I did not give any thought. On 6/19/24 21:14, Claude Pache wrote: > Second, “TowardsPositiveInfinity” is just a mouthful synonym for “Up”. You could just name it: > > Round::Up Except that it isn't and both the RFC and the two fine folks who already replied explained why. > At this point, you may invoke either Hamming or Levenshtein and compare it negatively with `Round::HalfUp`. Yes there is a risk a confusion (and I do think that such a name is suboptimal for this reason), but the confusion is not just caused by the short Levenshtein distance. That brings to the most important part of my review. Please note that the comparison was not made against the corresponding “Half” mode, but rather that the term “Up” is needlessly ambiguous. As I've also replied to Jordan: The RFC intentionally does not use the Up terminology (except to refer to the existing constants, which unfortunately use that terminology). > In my opinion, the most important criterion for a good name is: > > The name must be clear for itself, not just when comparing it with other ones. > > The problem with `Round::Up` (or `Round::[Towards]PositiveInfinity`), when you first encounter it, is that it is relatively easy to mistakingly assume that it is a “half-*” mode, and to erroneously interpret it as `Round::HalfUp` (or, its synonym `Round::HalfTowardsPositiveInfinity`). That is a fair concern. We shortly discussed splitting the enum into one "MidpointRoundingMode" and one other enum for the directed rounding modes, but we felt that it did not reliably solve this problem either. At least with a single enum all the 'Half' modes would appear in autocompletion. > But that the converse is false: it is impossible to interpret `Round::HalfUp` as if it were `Round::Up` (or `Round::TowardsPositiveInfinity`), because of the distinctive “Half” token that immediately indicate the right interpretation. Right. > So, the best way to disambiguate `Round::Up` from `Round::HalfUp`, is not to replace “Up” with some creative synonym, but to add a distinctive token that plays the role of — and contrasts with — “Half”. I don’t know if the following suggestion makes sense for you, but it is the one I have found: > > Round::FullUp You might have misunderstood my email. The concerns were not that HalfTowardsZero is too similar to TowardsZero, but rather that HalfTowardsZero is too similar to HalfTowardsEven, because they share the same 11-character prefix. > That said, I think that there is an even better option. I know you will not like it, but bear with me. I sincerely think that the best name is just: > > Round::Ceiling > > It is short, distinctive, and standard across the computing industry. > > Yes, this name is idiosyncratic to English and not used in several other (natural) languages, and if you don’t know English, you will not grasp the metaphor and have to just learn it. However, whatever other name you invent, you *have* to learn “ceil” anyway, because you *will* encounter it sooner or later. Many common (programming) languages, including JavaScript, C++, Java, Python, have a `ceil` function. Even if you manage not to learn any of those and to code in PHP only, you are at risk to stumble on its built-in `ceil(...)` function, or its newly-introduced `bcceil(...)` variant. > > Therefore, unless we find a name that is *really* good, I suggest to not fall into the NIH syndrome, and not to force users to learn another name *in addition to* “ceiling”. There is precedent for an "infinity-based" naming in other programming languages. The most mainstream one is probably C#: https://learn.microsoft.com/en-us/dotnet/api/system.midpointrounding?view=net-8.0 But there is also MATLAB: https://de.mathworks.com/help/matlab/ref/round.html#mw_e51282fd-7461-4bab-9f38-6106551bb8b2 We can even find precedent in PHP itself. The GMP extension already has rounding mode constants GMP_ROUND_PLUSINF and GMP_ROUND_MINUSINF: https://www.php.net/manual/en/gmp.constants.php And to add some anecdata: Just a few days ago I fixed a bug where the floor() function was incorrectly used where rounding towards zero was desired, resulting in incorrect results for negative numbers. The Ceiling / Floor / Up / Down naming is needlessly ambiguous, especially for non-native speakers. > For the same reason, `Round::TowardsZero` (suboptimal, because confusable with `Round::HalfTowardsZero`) could be replaced with: `Round::Truncate`. > While I think that Truncate is reasonably clear, breaking the mapping between the midpoint modes and the directed rounding modes just for this case does not appear useful. Best regards Tim Düsterhus