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
    Design by Contract clearly documented in 1986 by Meyer for Eiffel, well before Java was around. – user40980 Nov 8 '13 at 20:11
  • @MichaelT I never went through the Eiffel classes, but were Eiffel contracts/assumption documented in comments? I always assumed they were a native part of the system – Alan Storm Nov 8 '13 at 21:22
  • I'm not an Eiffel person at all so I'm not sure of the full history of it. As I mentioned that DbC was first written about in 1986, but since then Eiffel has taken out a trademark on "Design by Contract" so it may be part of the core modern language. – user40980 Nov 8 '13 at 21:30
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.

  • #pragma came from Ada (which left of the #, so it was just pragma). – Jerry Coffin Nov 9 '13 at 7:27
  • Actually, like almost everything else of that vintage that didn't come from LISP or FORTRAN, it came from Algol (Algol68, specifically), where it was pragmat (whence Ada, a latecomer in 1977, got pragma). But the point is, it's a really old concept, and to the OP's question, FORTRAN did it without real compiler directives. – Ross Patterson Nov 9 '13 at 14:39
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.