3 ms·
PHP has its flaws, no doubt. It's little known that doccomments are a PHP language construct that can be reflected over just as Python's doc strings can be int
by KrisJordan 17y ago
PHP has its flaws, no doubt.
It's little known that doccomments are a PHP language construct that can be reflected over just as Python's doc strings can be introspected with __doc__.
http://us3.php.net/manual/en/language.oop5.reflection.php#language.oop5.reflection.reflectionclass http://us3.php.net/manual/en/language.oop5.reflection.php#la...
Thus !Route GET, a/good/$programmer is just as much a language construct in a PHP program as @route('a/good/:programmer') is in a Python program. The key difference is Python defines at the language level how that particular bit of script is expanded as a decorator. Recess does its expansion of annotations at the framework level.
Python is a much better and more thoughtfully designed programming language than PHP, for sure. PHP has loop holes, doccomments is one of them. PHP does not do anything, by default, with a doccomment, but it does give an opportunity to introduce meta-data on classes, methods, and properties and easily reflect over that meta-data and then it's up to the programmer to define a 'DSL'.
In this sense PHP offers something powerful and dangerous. Recess choose a simple data format, such that parsing can be expressed in a regexp that is then processed by essentially 'Constructing a class of type [FirstWord] and call init method with array of [Following words as a PHP array] - finally make these annotations available through reflection'. Not too much different than annotations in Java/C#. Simple enough that the danger is mostly negated and the utility makes the 'hack' justifiable.
For a better-written justification of why this design decision was made for Recess: http://www.recessframework.org/page/on-hiding-our-dick-tracy-underwear-under-annotations http://www.recessframework.org/page/on-hiding-our-dick-tracy...
(Aside: This is why I'm a huge fan of Scala - extending a language with the language is awesome.)
- intranation 17y agoJust an aside, @someting(blah) isn't a comment or docstring--it's a decorator. So apples to oranges and all that. The equivalent in Python would be: def my_controller(request): """route: /thing/:var/""" pass or similar.