Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121327 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78750 invoked from network); 15 Oct 2023 17:24:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Oct 2023 17:24:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A9DFA180506 for ; Sun, 15 Oct 2023 10:24:51 -0700 (PDT) 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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Sun, 15 Oct 2023 10:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1697390689; bh=BEaTfZoKczQIGi4DJ1rxuYEqMAyUhi9xBUuo/JaG9fI=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=hUqVC6SIBYCLnV4l5vGeg/Hy5juJ5DFH4VcW6hP7Ex8bIqC38QC0zyxBJ5K8hVgTx HV15Z98yNcDWoH1TubwguGuZNE/Bb9JoOrddbWDh66OlAmTyZ0MJtp2O64Dz5/N9xQ TqcGHH8W8g36ISgWzObgtLoFyYVVPQvuWX4h0C3yAobp6YS5JnqWF7QERlG41DOCqa 4i/U7Zoz3XIPcZoHktpJuafkbvLiTYBjcZPsdCn2rRqZ8qUR9EpvoXqNlNpiqOaq1y ArTR9zMXmRoYifmzP5RUHQTdTlEB0wqAQwF0Q6NGLcOwLBnWzo5nIAOF3sukFVLQQ3 G7JGXC1EsgooA== Message-ID: Date: Sun, 15 Oct 2023 19:24:47 +0200 MIME-Version: 1.0 To: David Grudl , internals@lists.php.net References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Better name for method Randomizer::nextFloat() From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 10/14/23 19:47, David Grudl wrote: > random number in the interval 0...1, so it does the same thing as > getFloat(0, 1). See > https://wiki.php.net/rfc/randomizer_additions#nextfloat For the record: That is correct. > B) When trying to think of a more appropriate name (e.g. > `getFloat01()` ?), I find that the simple `getFloat(0, 1) is concise > and succinct enough. If it were really useful to have a method that > returns numbers in this interval, wouldn't it be better to give the > $min and $max parameters the default values of 0 and 1, and thus call > `getFloat()` directly? Yes, the right-open interval [0, 1) is useful to have as a special case, because it directly maps onto percentages, allowing you to easily generate booleans with a specific chance. Making those default values of getFloat() wouldn't be better, though. It is not meaningful to only provide *one* of the boundaries (specifically $min), but PHP does not support overloaded signatures without func_num_args() trickery and this was banned for internal functions as of this RFC: https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#policy_about_new_functions Making getFloat(float $min = 0.0, float $max = 1.0, IntervalBoundary $boundary = IntervalBoundary::ClosedOpen) would seemingly make it legal to call ->getFloat(0.5), which I consider to be worse than nextFloat(). Side note: The implementation of nextFloat() is much more efficient than that of getFloat(0.0, 1.0) and the output will differ even for the same seeded engine. The domain of legal return values is identical. > C) PHP 8.3 is still in testing and this change can be made. If it is > not done now, it will never be done and programmers will have to use > and also read unintuitive APIs for years. Similarly, in the days > before PHP 8.0 was released, I suggested changing PhpToken::getAll() > to today's tokenize() and there was no problem with that > https://bugs.php.net/bug.php?id=80328 The release managers would need to decide whether a change would be legal at this point in the release process, but I strongly doubt it, especially since naming is inherently bike-shedding territory and since the method name is already in various blog articles and in the documentation. For the same reason I'm not sure if comparing this to PhpToken::getAll() / tokenize() is a useful comparison, since the tokenizer is a very specialized feature that only few developers will care about. Making a breaking change late in the release process will have a much smaller impact to existing documentation / blog articles / feature videos / etc. Best regards Tim Düsterhus