Hi Lester,
Lester Caine wrote on 29/04/2016 16:18:
I think that is part of the problem here. IDE's are currently making
quite good use of existing annotation text, but if they have to be
switched to modes where some other option takes priority then once again
all the code has to be reworked ... which is where I'm stuck at the moment.
To be absolutely 100% clear, the attributes / annotations being
discussed are NOT for use in documentation, they are NOT for use by
IDEs, they are for use AT RUNTIME, by libraries which want to
programmatically access them INSIDE PHP ITSELF.
And if your code has no machine-readable annotations, I can virtually
guarantee that you won't need to make a single change to your docblocks
for your IDEs to carry on using them in exactly the way they're using
them now. Of course,
As with 'strict typing' we add different styles of working which in some
longer term world may be an elegant solution but short term just creates
an annoying different way of doing a bit of the job?
To an extent, I agree with this. Most modern programming language
features are just sugar on top of more general functionality. But again,
let's be clear: the functionality this is duplicating is not docblocks,
it is executable code. So an imaginary attribute "<<test($a < 42>)>>"
above a function might replace the code "if ( $a < 42 ) { throw new
Exception; }" inside the function.
There is some merit to saying that annotations already de facto exist
inside docblocks, but that discussion has been had many times, and there
is a brief summary in the current RFC:
https://wiki.php.net/rfc/attributes#criticism_and_alternative_approach
The most compelling argument to me is that since these aren't
standardised, a lot of incompatible syntax exists out there that the
parser would have to cope with (or force people to rewrite).
The comments go hand in hand with the validation so
why not keep them together?
This is true of any code. If I write "if ( $foo < 42 )", I might put a
comment next to it, but I wouldn't put the if statement in the comment.
So it would be with attributes/annotations: you would write the code
that means something to the engine, and then you would put a comment
next to it.
/**
* @test($a < 42) Must not reach The Answer
*/
function foo($a) { ... }
vs
function foo($a) {
if ( $a < 42 ) { throw new Exception; } // Must not reach The Answer
...
}
vs
<<test($a < 42)>> // Must not reach The Answer
function foo($a) { ... }
All of these examples have a mixture of code and comments, positioned
next to each other, but nonetheless separate.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php