0

我特别着迷于这种非代码代码的当前用法(如非代码,它不是文件其余部分的语言),以及这种非代码代码的历史。

在某些情况下,这可以称为元编程,但我认为这并不涵盖所有情况。

我已经看到它用于很多事情,可以追溯到 80 年代(根据我的经验),在 C 注释中使用“Autodocs”,用于生成文档,一直到 PHP 等解释语言中非常复杂的现代化身您在注释块中有注释,它们用于文档,在 PHP 语法不足的地方添加额外的含义,以及其他类型的“元”数据。

它似乎是一个大杂烩。我还不确定我对此有何感想。似乎有些不对劲。但我看到它有很大的用处。

我想知道您将使用什么通用术语来涵盖几乎所有代码中的所有这些非代码代码案例,以及是否有任何关于该主题及其历史、最佳实践等的权威著作。如果没有,它让我感兴趣,因为我想自己研究和写作。

例如,在 PHP 领域,我们有这样的事情:

/**
 * This is a "docblock" and PHP can introspect on it
 *
 * The annotation below is common, and is used by processors to generate
 * documentation.  It can also be used by an IDE to provide hints while
 * coding. Its also kinda redundant because in this case PHP is already
 * providing the same information... it also has no effect on the code,
 * unless some code is written to introspect on it and then do something.
 *
 * @param Request $request
 *
 * Another handy one, describing what is returned.  PHP doesn't have
 * a way to do this in the code, so this one is more useful.
 *
 * @return Response
 *
 * Here's some more annotations. The syntax is different, because, well,
 * there's no restrictions...
 *
 * This is for generating Swagger API documentation. Cool huh? Again,
 * it has no effect on the code. Period. Notice how it also specifies the
 * type as a Response object (given that you understand this new syntax).
 * Note also that this duplicates the functionality of @return above, but
 * we need both because different tools are using them each.
 *
 * @SWG\Api(
 *  path="/gettax",
 *  description="Calculate tax",
 *  @SWG\Operation(
 *      method="POST",
 *      type="Response",
 *      @SWG\Parameter(paramType="body",required=true,type="GetTax")
 *   )
 * )
 */
public function calc(Request $request) ....

无论如何,我看到有很多工具使用这些东西,但有很多重叠和碎片化。至少在 PHP 领域。我回想起多年来的编程,我认为这类东西并不是什么新鲜事。

我想搜索该主题,但找不到一个好的搜索词来获得我正在寻找的内容,这是有关此类方法起源的一些历史文档,多年来哪些工作做得好或不好,最佳实践等。这都被认为是元编程吗?

这些东西的演变是什么,它们是在某个时候成为语言的适当部分,还是融入到新的语言中?

我对这个主题很感兴趣,我想知道是否有其他人写过关于这个主题的权威文本?

我突然想到,这些东西实际上是领域特定语言的一种形式。因为宿主语言无法表达某些东西,所以使用 DSL 并将其嵌入到代码中(在注释中或通过宿主语言支持的某些工具,如注释)来表达您希望与代码,而不必对代码流产生任何影响。

4

0 回答 0