Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124098 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 484E11A009C for ; Sun, 30 Jun 2024 14:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719757599; bh=6dXjKk3nY5g8f6bPdEb9GMZgyXKDO2vLXy7glu1uZ0s=; h=Date:Subject:To:References:From:In-Reply-To:From; b=M6YOCz2bRq+Pv6nT9RVz5JEFRliEsqVISrjno5HaDqsp1Vt6JQlUNFcvavlvCEabe NUV8gbmbyY2Ir+bOGBLwUL+YDiGctPbrqvlyJKtlYGubd+WaDftWxltQN9M+RGYd4o wJmzeXOyVtbm1SJ3bHHR2z858QjI/e7jfWGQoQtvJhzIrUNG1u41RBHlSknHKc6EaL wwWZMZv/SqMnnv10cWBqB/2Vj8umxdVr5sQj7H0rcCrpMlgQDoxJSPEUTCFMs5nVEW Fst0U0Wmu9kthJlajGGl9QxvtKIE1rErHn6Y+kLOxCrGJZFmLvPQYefV14pmDkQ/e/ eKyxCdpJowM5Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 639D61806A3 for ; Sun, 30 Jun 2024 14:26:38 +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 ; Sun, 30 Jun 2024 14:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1719757517; bh=6HHWeBGGNQn3BbPxKukTNGyAlVlNM7xs/GKZGoWqvw8=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=S2/EIgejvNVip/XaYPyOMpGB8eXAyjwqSegiM1/4OJMm2NrC/khK2O54eOodIVVH1 bwgJZNbF2JSmhBt64sXgeJxxd/kbGPZuM1oTAbWP37DhWHTvqQwbSeVEV4WonogC/k BxItluPfDyg3n0LEFpQONOodHHAz26hWprf08uCo2Ks5ERVYhbLF+Cfy9tFFhj2QK7 DTltM+sMYphMrp9JaZRwppwmegCab8ufopm8IwGmQdBgxI3VN9PoBJ8OLKOesiLWPX 55kvpZ6Jr2OAbvB5lgdAxTiLpYaffkGfmDrUpVCgrwI123jpYdd2flIasYUmgtv3wX PAlInL2C5U90w== Message-ID: Date: Sun, 30 Jun 2024 16:25:16 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Add bcdivmod to BCMath To: Juliette Reinders Folmer , internals@lists.php.net References: <668168A7.4040005@adviesenzo.nl> Content-Language: en-US In-Reply-To: <668168A7.4040005@adviesenzo.nl> 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 On 6/30/24 16:16, Juliette Reinders Folmer wrote: > Just a suggestion: what about making the returned array an associative > array ? Like so: > ``` > array( > 'quotient' => 61, > 'remainder' => 1, > ); > ``` > > This would remove the need for devs to remember the order of the return > values and would make the return value self-documenting. > An associative array would combine the worst of an array (no IDE autocompletion, no strong typing, increased memory usage) with the worst of an object (no easy way to extract the values into local variables with array destructuring). The example in the RFC doesn't show it, but the following makes the proposed API really convenient to use: $slicesOfPizza = new BcMath\Number(8); $mouthsToFeed = new BcMath\Number(3); [$perMouth, $slicesLeft] = $slicesOfPizza->divmod($mouthsToFeed); Note how the order of values matches the words in the method name. First the result of 'div', then the result of 'mod'. Best regards Tim Düsterhus