Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122683 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 EC96F1AD8F6 for ; Mon, 18 Mar 2024 20:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710794075; bh=ZPAFIolDYngm6Fy6z7SClWbEJMBhGWMTJSdfXE1oK70=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Q2Q5z+HaOotBGKOb45Yrs8ggigUriVJevn2nKoO0kAclGPkSuvDsin0HFIHBRFFy3 L5u3AEv9JUegJqr1pfrle/6jwSRmeFnSnq62pfaKUDYSuPY+Px56HXIa3YI7tamEao y0iFde/xN7/tQLlygJRqfpz6hReTKwxRaJ5B5wMtvAEc9iWVRrFcAymY+dMNOuiBe0 Vu5rhm8G82ePkuWq9DGWIAj0jsiaBMmrnIAzBLUAMPIxrfyd91KFla8Zl18h0DE+r8 A4tnD/TF3NsnFsC8qkMa1tLiTX4/jmiURz4sI7ECuk9zrKWSzRCuC+ofa9wjKg7vQm zAbQMrl//CYLg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D52818005B for ; Mon, 18 Mar 2024 20:34:34 +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_MISSING,HTML_MESSAGE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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, 18 Mar 2024 20:34:33 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E1F9311400CB for ; Mon, 18 Mar 2024 16:34:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 18 Mar 2024 16:34:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1710794052; x=1710880452; bh=YkUW93rfGJ cCRSl03ce1HhV9vB3CGdlyVjWNoEFagDg=; b=V9fdfs/4d97a50WG9zQfwuwlUa 9bZ1UCXMCzY6X0eU/6CmuSU81kWWSu3cmXLpOpEeBFkyct4DkM5gY94sHzN16IDI 7YT5PZ3uSr9mCKdpbdDrSC15LanRKIzdtzWDhPjVU19NinpSQEUR+h930P+J64gM jaid95IATRSiBMdI9fWs4JnIIdUe3y0kTeabdLq514H+ix3+FIPxq17KQ7IvL+aK ilhrhQ/es+rI9i5k6L7fA8xXAz+BhiC9Dqs9v9kFJz9o2ElzhfHkPvL3I3xKzHaZ 37c77ZxKHWAZkVD679a2vhM0LdLGHI6xKkm08D0kOB1afZOa8QuHB691adag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1710794052; x=1710880452; bh=YkUW93rfGJcCRSl03ce1HhV9vB3C GdlyVjWNoEFagDg=; b=tX6A4IBzMF93723x1KQdvIoqJRZa7pSQOmnKQ4kcTLao RZXrYXzrpubg8/GX6NrfPhKXBdGGxLlNRqctc0LjW4HifNHz3nXp6wbIsC6zrMtD l4f0wrhz/lAcm4Hx62/GsE2Rxrs0vU6aQWjBkxy5IniFGaUXgrcbA9fr2YiEFEEP jugimjJKRl5cfpQRN39jC96xiKpfsDsfYwcQWhjpQf7kuFDn2tu33/Z4RJyUheVZ ID6f+foIJJeWIvdJRqCe4vyyPrr8CTucliSFlBiFnUH6cfkq7D8Y8svVxS5Pw+fd n4po4mSgsRP3OOmPUTkaXQzUcqtFeAgRKdgVj7l8Qg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeejgddufeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtre ertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcu oehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhephe etleeiiefgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrph hhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 18 Mar 2024 16:34:12 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------our69A0xo0oXsgRVmW3mN1sA" Message-ID: Date: Mon, 18 Mar 2024 20:34:09 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Proposal: Arbitrary precision native scalar type Content-Language: en-GB To: internals@lists.php.net References: <18c42fdbb30.2831.17a3710df6d58f02ca570cc47e197a63@interi.co> In-Reply-To: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------our69A0xo0oXsgRVmW3mN1sA Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 18/03/2024 04:39, Alexander Pravdin wrote: > I'm not in the context of the core team plans regarding "strict > types". Could you share some details here? What is the current plan > regarding it? To make strict types on by default eventually? Or > something else? PHP doesn't really have a defined "core team". There are contributors who are particularly active at a given time (sometimes, but far from always, because someone is paying them), contributors who are particularly long-standing and respected, contributors who throw themselves into a pet project and make it happen, and so on. Partly as a consequence of this, it's often hard to pin down any long-term plan about anything, outside of what particular people would like to see. So Gina's opinion (it was suffixed "IMHO") that strict types was a mistake shouldn't be read as "we have a solid plan for what is going to replace strict_types which everyone is on board with". I think a reasonable number of people do share the sentiment that having two separate modes was a mistake; and neither mode is actually perfect. It's not about "making it on by default", it's about coming up with a unified behaviour that makes the setting redundant. All of which is something of a diversion from the topic at hand, which is this: > How can we introduce the ability to write user code in default > decimals and at the same time keep the old way of working as it was > before, to not introduce any troubles into the existing code and not > introduce performance issues? As a user, I would like to have a > choice. I don't think choice is really what you want: if you were designing a language from scratch, I doubt you would say "let's give the user a choice of what type 1 / 10 returns". What it's actually about is *backwards compatibility*: what will happen to code that expects 1/10 to give a float, if it suddenly starts giving a decimal. For most cases, I think the rule can be as simple as "decimal in means decimal out". What's maybe not as obvious at first sight is that that can apply to operators as functions, and already does: 100 / 10 gives int(10), but 100.0 / 10  gives float(10.0), as do 100 / 10.0  and 100.0 / 10.0 By the same logic, decimal(1) / 10 can produce decimal(0.1) instead of float(0.1), and we don't need any fancy directives. Even better if we can introduce a shorter syntax for decimal literals, so that it becomes 1_d / 10 Where things get more complicated is with *fixed-precision* decimals, which is what is generally wanted for something like money. What is the correct result of decimal(1.03, precision: 2) / 2 - decimal(0.515, 3)? decimal(0.51, 2)? decimal (0.52, 2)? an error? And what about decimal(10) / 3? If you stick to functions / methods, this is slightly less of an issue, because you can have decimal(1.03, 2)->dividedBy(2, RoundingMode::DOWN) == decimal(0.51, 2); or decimal(1.03, 2)->split(2) == [ decimal(0.52, 2), decimal(0.51, 2) ] Example names taken directly from the brick/money package. At that point, backwards compatibility is less of an issue as well: make the new functions convenient to use, but distinct from the existing ones. In short, the best way of avoiding declare() directives is not to replace them with something else, but to choose a design where nobody feels the need for them. Regards, -- Rowan Tommins [IMSoP] --------------our69A0xo0oXsgRVmW3mN1sA Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 18/03/2024 04:39, Alexander Pravdin wrote:
I'm not in the context of the core team plans regarding "strict
types". Could you share some details here? What is the current plan
regarding it? To make strict types on by default eventually? Or
something else?


PHP doesn't really have a defined "core team". There are contributors who are particularly active at a given time (sometimes, but far from always, because someone is paying them), contributors who are particularly long-standing and respected, contributors who throw themselves into a pet project and make it happen, and so on.

Partly as a consequence of this, it's often hard to pin down any long-term plan about anything, outside of what particular people would like to see. So Gina's opinion (it was suffixed "IMHO") that strict types was a mistake shouldn't be read as "we have a solid plan for what is going to replace strict_types which everyone is on board with". 

I think a reasonable number of people do share the sentiment that having two separate modes was a mistake; and neither mode is actually perfect. It's not about "making it on by default", it's about coming up with a unified behaviour that makes the setting redundant.


All of which is something of a diversion from the topic at hand, which is this:

How can we introduce the ability to write user code in default
decimals and at the same time keep the old way of working as it was
before, to not introduce any troubles into the existing code and not
introduce performance issues? As a user, I would like to have a
choice.



I don't think choice is really what you want: if you were designing a language from scratch, I doubt you would say "let's give the user a choice of what type 1 / 10 returns". What it's actually about is *backwards compatibility*: what will happen to code that expects 1/10 to give a float, if it suddenly starts giving a decimal.

For most cases, I think the rule can be as simple as "decimal in means decimal out". What's maybe not as obvious at first sight is that that can apply to operators as functions, and already does: 100 / 10 gives int(10), but 100.0 / 10  gives float(10.0), as do 100 / 10.0  and 100.0 / 10.0

By the same logic, decimal(1) / 10 can produce decimal(0.1) instead of float(0.1), and we don't need any fancy directives. Even better if we can introduce a shorter syntax for decimal literals, so that it becomes 1_d / 10


Where things get more complicated is with *fixed-precision* decimals, which is what is generally wanted for something like money. What is the correct result of decimal(1.03, precision: 2) / 2 - decimal(0.515, 3)? decimal(0.51, 2)? decimal (0.52, 2)? an error? And what about decimal(10) / 3?

If you stick to functions / methods, this is slightly less of an issue, because you can have decimal(1.03, 2)->dividedBy(2, RoundingMode::DOWN) == decimal(0.51, 2); or decimal(1.03, 2)->split(2) == [ decimal(0.52, 2), decimal(0.51, 2) ] Example names taken directly from the brick/money package. 

At that point, backwards compatibility is less of an issue as well: make the new functions convenient to use, but distinct from the existing ones.


In short, the best way of avoiding declare() directives is not to replace them with something else, but to choose a design where nobody feels the need for them.

Regards,

-- 
Rowan Tommins
[IMSoP]
--------------our69A0xo0oXsgRVmW3mN1sA--