Question about adding !function_identifier

php.internals

M. W. Moe

7 years ago
Hello people, I have a quick question before any formal proposal; would it be complex to add an exclamation mark indicatorin front a function identifier to indicate that function throws; like the nullable question mark for types however without any runtime check something like a pure syntax indicator to make the code clearer? Have a good day.

Sara Golemon

7 years ago
On Wed, Apr 3, 2019 at 11:07 AM M. W. Moe <mo.mu.wss@gmail.com> wrote:
> I have a quick question before any formal proposal; would it be complex to > add an exclamation mark indicatorin front a function identifier to indicate > that function throws; like the nullable question mark for types however > without any runtime check something like a pure syntax indicator to make > the code clearer? > > If you're suggesting something with no runtime validation, then why not
simply use docblock annotations? They're widely supported and understood already. Basically, what will having that syntax give you that not having it won't? -Sara

M. W. Moe

7 years ago
Hello, yes this is very true; but usually on complex design with a lot of folks working on it you start coding before documenting; I was thinking like c++ `nothrow` identifie (I do know does more than informal), I am the kind of people who like languages which are explicit before any documentation and a throw vs nothrow is an important contextual information, it will forcibly change the way you engage it. On Wed, Apr 3, 2019 at 9:20 AM Sara Golemon <pollita@php.net> wrote:

Rowan Collins

7 years ago
On Wed, 3 Apr 2019 at 17:27, M. W. Moe <mo.mu.wss@gmail.com> wrote:
> yes this is very true; but usually on complex design with a lot of folks > working on it you start coding before documenting; >
If it's just syntax that doesn't change behaviour, it's really just documentation anyway, and if people are so desperate to dig into the code that they can't write a minimal docblock (or so lazy that they won't), how likely is it that they'll correctly add this new indicator? If you want to be explicit, don't put off docblocks until later (writing them before you've even implemented the function can be a great way of clarifying your design), and use an IDE or CI tool that will tell you when they're missing or incorrect. Regards,
-- Rowan Collins [IMSoP]

M. W. Moe

7 years ago
Hello, not documenting at first is not really a question of laziness or so, as things are still moving around you absolutely need this agility; a good design layout between theory and stable state will refactored discussed a thousand times; that what I expect from engineers; filling the gaps between assumptions and reality. And for me-self throw vs no throw is important language information and part of internal behaviors; to clarify, for instance, would be more useful to have such indicator rather than having having abstract and interface which are cumbersome; same as the extra public keyword; you can do without especially with the new traits construct. Best. On Wed, Apr 3, 2019 at 9:42 AM Rowan Collins <rowan.collins@gmail.com> wrote:

Stijn Peeters

7 years ago
I think the issue here is that there is no functional difference between an exclamation mark prefix and a docblock attribute, and the latter has the advantage of being more explicit, not requiring changes to the language syntax itself, and being an already-existing standard.  Of course things may move around during the development process, but I don't really see how you can't move around the docblocks with the functions they belong to... A decent IDE will make this easy and can also use the @throws tag to provide the contextual information you're looking for, again, without having to change the language itself. Best, Stijn Op 3 april 2019 bij 18:52:58, M. W. Moe (mo.mu.wss@gmail.com) schreef: Hello, not documenting at first is not really a question of laziness or so, as things are still moving around you absolutely need this agility; a good design layout between theory and stable state will refactored discussed a thousand times; that what I expect from engineers; filling the gaps between assumptions and reality. And for me-self throw vs no throw is important language information and part of internal behaviors; to clarify, for instance, would be more useful to have such indicator rather than having having abstract and interface which are cumbersome; same as the extra public keyword; you can do without especially with the new traits construct. Best. On Wed, Apr 3, 2019 at 9:42 AM Rowan Collins <rowan.collins@gmail.com> wrote:

Claude Pache

7 years ago
> Le 3 avr. 2019 à 18:52, M. W. Moe <mo.mu.wss@gmail.com> a écrit : > > Hello, > > not documenting at first is not really a question of laziness or so, as > things are still moving around > you absolutely need this agility; a good design layout between theory and > stable state will refactored > discussed a thousand times; that what I expect from engineers; filling the > gaps between assumptions > and reality. > > And for me-self throw vs no throw is important language information and > part of internal behaviors; > to clarify, for instance, would be more useful to have such indicator > rather than having having > abstract and interface which are cumbersome; same as the extra public > keyword; you can do without > especially with the new traits construct. > > Best.
If you’re unwilling to write a docblock for some good reason, why not just use the built-in, user-extensible way that most programming languages have to add annotations without runtime effect, namely unstructured comments? Something like /* nothrow */ is both forward- and backward-compatible... Am I missing something? —Claude

M. W. Moe

7 years ago
Hello, yes this is very true, but still foreign to the language construct; empty contextual indicators it's what we usually do in C and assembly (it has no cost) especially on extra sensitive code to make it short. On Wed, Apr 3, 2019 at 10:00 AM Claude Pache <claude.pache@gmail.com> wrote:

M. W. Moe

7 years ago
The argument sits there. function handle(int $cmd, ...$arg) : int /* throw */ function !handle(int $cmd, ...$arg) : int On Wed, Apr 3, 2019 at 10:10 AM M. W. Moe <mo.mu.wss@gmail.com> wrote:

Rowan Collins

7 years ago
On 03/04/2019 18:13, M. W. Moe wrote:
> The argument sits there. > > function handle(int $cmd, ...$arg) : int /* throw */ > function !handle(int $cmd, ...$arg) : int
The first example is unambiguous, easy to understand by anyone with a basic knowledge of the language, easy to spot when reading the code, easy to grep for, and will be recognised as a comment by any tool for parsing PHP. The second example is hard to spot, completely opaque in meaning, and would break any tool which didn't have it added as a feature. I'm really struggling to see any advantages at all, other than saving a few key presses. Of course, neither documents what type of exceptions will be thrown, so it's a bit like documenting every return type as either "void" or "mixed"; which is why the more common practice would look more like this: /** @throws InvalidFooException */ function handle(int $cmd, ...$arg): int
> you seems not having the experience of working on the same code base > with basically literally dozen of people which can at > some point intervene; this is reality, this not wrong or bad; you deal > with it.
You're right, I haven't worked in a team that size, but if I did, I would expect strict coding standards that emphasise clear intent and documented behaviour to be absolutely essential for everyone to know what was going on.
> either you enforce extra qualifiers in term of signature or you don't > encourage it
I'm struggling to see the difference between enforcing "add an ! before the name if it throws" and "add a comment next to the name if it throws", or even "add X to the name if it throws", unless the language itself is going to perform some extra check. Regards,
-- Rowan Collins [IMSoP]

M. W. Moe

7 years ago
Hello, you are very kind and trying hard but that's not the topic; the commenting section suggestion was some kind of decoy or trap; it does not address the original request and its scope; what's behind is more fundamental; I may have a polite discussion and argument with people; not bulls, they belong to the prairies. and what about ?String (cynicism) Have a good day. On Wed, Apr 3, 2019 at 11:42 AM Rowan Collins <rowan.collins@gmail.com> wrote:

Rowan Collins

7 years ago
On Wed, 3 Apr 2019 at 17:52, M. W. Moe <mo.mu.wss@gmail.com> wrote:
> not documenting at first is not really a question of laziness or so, as > things are still moving around > you absolutely need this agility; a good design layout between theory and > stable state will refactored > discussed a thousand times; that what I expect from engineers; filling the > gaps between assumptions > and reality. >
I think we have different assumptions about what "documentation" means here. I'm not saying you have to write a 500-word paragraph explaining the theory and edge-cases in the code; just that you should write a quick comment saying what the function expects, and what it will return, beyond the ability of the language's syntax. You *could* write every function like this: function tbc(...$args) { } That way, you can change the visibility, the argument types, the return types, and the name, without "documenting" it in advance. Clearly, that would be ridiculous, so you probably actually write this: public function convertFooToBar(Foo $foo): Bar { } What I mean by "documentation first" is to go a small step further and write: /** * Convert using the lookup tables * * @param Foo $foo Should only be given pre-validated Foo * @return Bar Will always be pre-validated * @throws InvalidFooTypeException */ public function convertFooToBar(Foo $foo): Bar { } This is all part of the *current* design of this function. It might change, but if it changes, you change the docblock, just as you'd change the signature if you realised it should actually be private, or accept a PreValidatedFoo object, or the name is wrong. You seem to want to do this same job, but with as few characters as possible, and I don't really understand why, if your aim is to be explicit and clear. If you just want to type less, use an IDE or editor with good auto-complete support. Regards,
-- Rowan Collins [IMSoP]

M. W. Moe

7 years ago
Hello, quick commenting usually ends up in a `circus`; either you enforce extra qualifiers in term of signature or you don't encourage it you seems not having the experience of working on the same code base with basically literally dozen of people which can at some point intervene; this is reality, this not wrong or bad; you deal with it. We are a shop where people are using terminal emulators; vim or emacs not cumbersome IDEs or for some not even a window manager ; reality; you deal with it. Moreover an exception state is not really like a status; this is an internal language behavior, should be carried by the syntax even if informal, anyhow could evolve over time. On Wed, Apr 3, 2019 at 10:24 AM Rowan Collins <rowan.collins@gmail.com> wrote: