On Fri, Jun 21, 2024 at 10:12 AM Paul Dragoonis <dragoo...@gmail.com> wrote:
> > > On Thu, Jun 20, 2024 at 11:54 PM Rowan Tommins [IMSoP] < > imsop....@rwec.co.uk> wrote: > >> On 19/06/2024 16:34, Larry Garfield wrote: >> >> Also, as someone who does put every file into strict mode as a matter of >> course, and appreciates the many languages that do not even have a >> concept of non-strict mode (like Go or Rust), I really don't appreciate >> the backhanded comments in this thread about people who, you know, care >> about type safety. (Something that weak mode, when it was introduced in >> PHP 7, only marginally provided if at all.) Strict mode prevents bugs, >> full stop, and we should not fault anyone for applying that bug-stopper >> tool liberally. >> >> >> > Hey Rowan, > I meant Hey Robert, but half replying to Rowan's suggestions too. > > What Gina, Larry and Sebastian said. > > My $0.02 is > > 1. typing "declare(strict_types=1);" is already cumbersome enough, we > don't need to be adding more words and complexity to it > > 2. adding the word "coerce" or "coercion" to a thing is really not good > from a DX (developer experience) perspective. It will not add clarity it > will add *confusion*... "What is this coersion thing I've never heard of" > > 3. remember who the target audience is.. Rust and Golang are not > beginner-friendly or entry-level languages, so the fact you're even using > Rust means you know what you're doing and likely know what coersion is > > 3.1 PHP's strength is that it's beginner friendly and by that I mean just > remember a significant portion of our userbase are Wordpress developers > (and Drupal / Magento alike) .. and many WP devs won't have even heard of > Dependency Injection before nevermind the complexities of type coersion, so > we need to keep things *simple as possible* at all times > > 4. I think the solution you're looking here for is better *education* to > the end-users, on what the implications of X or Y are .. rather than > changing the language itself .. so the merits of your proposal are good, in > that it helps the end-user understand the system better .. it's just the > solution you're proposing here just isn't it (so far). > > > > Used correctly, it absolutely does. Used incorrectly, it can actually end >> up *hiding* errors. >> >> I've seen lots of cases where code like this: >> >> some_function_expecting_int($_GET['foo']); >> >> Gets changed to this: >> >> declare(strict_types=1); >> some_function_expecting_int( (int)$_GET['foo'] ); >> >> Even in PHP 7.0, the first version is actually *stricter* than the >> second, because explicit casts never fail, but parameter coercion (mode 0) >> always failed for strings like "hello"; as of 8.0, it also fails for >> strings like "123foo" and "". >> >> And this is exactly the kind of code that coercive type hints were >> intended for - HTTP is a text-based protocol, so most PHP applications are >> dealing with string input and output *all the time*. >> >> One of the things the language badly needs, and I have been trying to >> come up with a proposal for, is strict type casts, so that this code can >> actually be written safely but still concisely. >> >> >> Regards, >> >> -- >> Rowan Tommins >> [IMSoP] >> >>