5

In certain corners of the PHP meta-programming world, it's become fashionable to use PHPDoc comments as a mechanism for providing semantically meaningful information to a program. That is, other code will parse the doc blocks and do something significant with the information encoded in those comments.

Doctrine's annotations and code generation are an example of this.

What's the earliest (or some early) use of this technique? I have vague memories of some early java Design by Contract implementations doing similar things, but I'm not sure of those folks were inventing the technique, or if they got it from somewhere.

Mainly asking so I can provide some historical context for PHP developers who haven't come across the technique before, and are distrustful of it because it seems a little crazy pants.

2 Answers2

6

Depending on just how far you stretch "semantically meaningfull", it's a concept at least 40 years old. There was a day when Algol, FORTRAN, and COBOL were the only cross-platform languages, and many FORTRAN compilers had ways to declare things that influenced their behavior, usually expressed as comments. The practice was so wide-spread that the Dennis Ritchie introduced the #pragma directive for C, specifically to separate such things from normal comments.

3

The first time I saw it was some early Pascal compilers that used special comments to control compiler code generation. This was documented in the Pascal User Manual and Report at least as far back as 1974:

B. Compiler options

The compiler may be instructed to generate code according to certain options: in particular, it may be requested to insert or omit run-time test instructions. Compiler directives are written as comments and are designated as such by a $-character as the first character of the comment:

{$<option sequence><any comment>}

Example:

{$T+,P+}

[I'll omit the next ~1.5 pages of flags and options it supported.]

Citation: Pascal User Manual and Report, ยง14.B, pages 100, 101, copyright Springer-Verlag, 1974.

Jerry Coffin
  • 44,795