Re: Better name for method Randomizer::nextFloat()

From: Date: Sun, 15 Oct 2023 00:04:59 +0000
Subject: Re: Better name for method Randomizer::nextFloat()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121317@lists.php.net to get a copy of this message
On Sat, 14 Oct 2023 at 18:48, David Grudl <david@grudl.com> wrote: > > A) The problem with nextFloat() is that the name creates a false > expectation. Take a look at the following code: > ``` > $randomizer = new \Random\Randomizer(); > $a = $randomizer->getFloat(100, 200); // number between 100..200 > $b = $randomizer->nextFloat(); // another number between 100..200 ??? > ``` > I don't even get the point of nextFloat. Its a random function, there is no thing as "next". I think the major pet peeve i have is that the "Randomizer" class is encapsulating all random functions. I would like to see each randomizer have its own class, since they are under the Random namespace anyway, I believe they should be Random/StringRandomizer, Random/IntRandomizer, Random/FloatRandomizer, so on so forth. Basically Ramdom/{Type}Randomizer. This would also allow more granular and specific functionality for each type. For example, for this discussion, the class, Random/FloatRandomizer (and IntRandomizer) could be instatiated with its boundries. ```php $randomFloat = new Random/FloatRandomizer($lowerBound, $upperBound, $boundryInterval) $a = $randomFloat->get(); $b = $randomFLoat->next(); ``` Is that not more intuitive?

« previous php.internals (#121317) next »