识字编程
文学编程是一种软件开发方式,首先是文档,然后是编码。 首先编写代码片段的文档,然后编写该代码片段的实现。 软件源代码的视觉外观将是一个类似word的普通文档,其中包含代码段落。
我正在尝试将我工作的开发商店转变为仅使用文字编程,因为它为代码可读性和可维护性带来了巨大优势。 然而,由于缺乏工具,LP 在公司内的使用受到限制。 例如,编程识字的理想方法是使用单词标记编写一个段落,然后插入一个带有实现的小段落。 但我似乎找不到任何好的工具可以让 VS200x 执行 LP。
理想情况下,这样的工具看起来就像 Word 2007,但集成到 IDE 中。 当编码器将光标置于代码段落上时,它将拥有提供的所有功能,就像我们现在在 IDE 中一样。
对于 LP 有哪些好的工具,特别是 .NET 和 VS200x?
Literate programming is a way of developing software where documentation comes first, then the coding. One writes the documentation of a code snippet, and then writes the implementation of the snippet. The visual appearance of the software source code would be a plain document like word, with code paragraphs in it.
I am trying to convert the dev shop I work to use only literate programming, as it brings great advantages to code readability and maintenance. However, due to the lack of tools the LP usage is limited in the company. For example, the ideal way to program literate is to write a paragraph using word markup, and then insert a subparagraph with the implementation. But i cannot seem to find any good tools for VS200x to perform LP with.
Ideally, such a tool would look just like Word 2007, but integrated into the IDE. When the coder sets the cursor on a code paragraph, it would have all the functionality provided just like we have now in our IDE.
What are good tools for LP, with .NET and VS200x in particular?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
感谢您尝试改进团队的工作方式。 只要你尝试这样做,你就比那些不这样做的人有优势。
我曾经在一个项目中使用过文学编程。 真的很辛苦,但结果也很好。 似乎是一个合理的权衡。
然而,今天我宁愿采取不同的方法:我宁愿编写清晰到人类不介意阅读的代码,而不是为人类编写散文和为机器编写代码。 当我想写评论时,我想“我可以让这段代码更清晰”。 这意味着我编写的文档更少,而不是更多。
好吧,无论你选择什么道路,祝你好运。
Kudos to you for trying to improve the way your team works. As long as you're trying to do that, you have an advantage over those that do not.
I used Literate Programming for a project once. It was really hard, and the results were really good. Seemed like a reasonable tradeoff.
However, today I'd rather take a different approach: instead of prose for humans and code for machines, I'd rather write code that is so clear that humans don't mind reading it. When I feel the urge to write a comment, I think "I could make this code clearer". That means I'm writing less documentation, not more.
Well, good luck with whatever path you choose.
我只能建议您使用 doxygen 注释标记代码,然后您可以从您的代码生成文档代码,我知道这几乎是做你想做的事情的向后方法,但至少你最终得到了期望的结果:来自相同源文件的代码和文档。 显然,这样做的优点是您可以使用现有的 IDE 进行编码,其中包含所有常见的代码友好功能。
如果你试图改变你的开发团队,这种方法可能比成熟的文学方法更容易被他们接受,他们仍然对相同的编码感到满意,但他们必须编写更好的文档嵌入到代码。
这是我能提供的最好建议,看看你的团队对此想法的看法。
I can only suggest you markup your code with doxygen comments, then you can generate the documentation from your code, which I know is almost a backwards ways of doing what you want, but at least you end up with the desired result: code and documentation that comes from the same source files. Obviously this has the advantage that you use your existing IDE for coding that comes with all the usual code-friendly goodies.
If you're trying to convert your dev team, this approach might be easier for them to swallow than a full-blown literate methodology, they're still happy with the coding being the same, but they have to write better documentation embedded in the code.
That's the best I can suggest, see what your team thinks of the idea.
+1 试图改进团队的流程
-1 走入死胡同
,单元测试比文档更好
+1 for trying to improve your team's process
-1 for going down a dead-end path
with all due respect to Knuth, unit tests are better than documentation
据我所知,唯一真正支持 LP 的非深奥语言是 Haskell,说实话,我还没有听说现代编程语言对 LP 有太多需求。 大多数人似乎对使用内联文档格式(javadoc、rdoc 等)感到满意
The only non-esoteric language I know of which actually has support for LP is Haskell, and to be honest, I haven't heard much demand for LP in modern programming languages. Most people seem to be satisified with using inline documentation formats (javadoc, rdoc, etc.)
我很抱歉。 我应该提到,我们已经在使用 Doxygen 和自动文档构建脚本。 我们尽可能使用 .NET 文档标签,而在 .NET XML 文档标签不足的地方,我们混合使用 doxygen 标签。 这非常有效。 关键是,在编写文档时,产量会大大减少:我们(人类)在没有任何所见即所得编辑器的情况下在生成文档方面非常糟糕。 更不用说错误敏感了。
该团队目前正处于将思维方式从直接编码转变为先编写文档,然后编写代码的阶段。 这是最重要的一步,因为它让编码人员接受 LP 范式。
我想这里有一个 VS 插件可以做到这一点的市场。
此外,Doxygen 似乎确实是一个积极使用 LP 方法解决此问题的好工具。 虽然它的用途非常有限。
My apologies. I should have mentioned that we are already using Doxygen with an automated doc build script. We use the .NET doc tags where possible, and where the .NET XML doc tags come short we mix in doxygen tags. This works quite well. The point is that production decreases quite much when writing documentation: We (humans) are very bad in producing documentation without any WYSIWYG editor. Not to mention error sensitive.
The team is currently in the phase to convert the mindset from coding straight ahead to first writing documentation, then code. This is the most important step, as it lets the coders embrace the LP paradigm.
There is a market here for a VS plugin that does it, i guess.
Also, Doxygen indeed seems to be a nice tool for actively using the LP method solution to this problem. Though it is very limited in use.
我们也是这么做的。 尽管对于我们生成的许多代码来说,编写清晰的、人类可读的代码是不够的。 如果你想解释一个图像渲染函数怎么办? 最好用图像来解释它,而不是写半页纸来描述它。
Thats what we do also. Though for a lot of code we produce, writing clear, human readable code just isn't enough. What if you want to explain an image rendering function? Better explain it using an image, instead of writing half a page describing it.
我不知道有任何用于文学编程的现代工具。 我15年前做过一些WEB编程。
Doxygen 是一个不错的工具,但对 LP 没有任何帮助。 问题在于 LP 专注于编写供人类阅读的代码。 对于后续的细化/披露没有良好的支持。 LP 需要查看源代码,该视图的结构与 VS 中的文件类属性/方法不同。 NSpec 可能会好一些,但也过于自下而上。
I'm not aware of any modern tooling for Literate Programming. I have done some WEB programming 15 years ago.
Doxygen is a nice tool, but doesn't help at all with LP. The problem is that LP focuses on writing code for humans to read. There is no good support for successive refinement/disclosure. LP needs a view on the source code that has a different structure than the file-class-attribute/method in VS. NSpec might be somewhat better, but also is too much bottom-up.
文学编程的主要思想是将程序编写为数学文本。 人们可以尽可能清楚地定义程序中所需的每个概念的含义,然后解释它是如何用语言实现的,以及为什么决定以这种方式而不是其他方式或稍后将要更改的内容。
还可以通过注释要更改的代码段并插入新代码来解释更改的原因来记录更改。
某些更改可能取决于代码的转换以优化其性能。 例如,在某些类似 C 的语言中制作一个循环,而不是 2 个循环,将一个表达式更改为更简单的表达式,等等。或者更复杂的事情,例如更改其他数据结构来表示信息。
每项更改都有充分的理由并记录在案。
只需阅读源代码,深入理解程序就可以了解程序的问题域。 避免因含糊不清而出现错误。
程序的起源是完整记录的,以后可以回忆起一切,因为每一个想法都在程序中。
严格来说,如果程序是开发的,那么可以用纯文本编写有文字的程序,但在 TeX/LaTeX 中排版是最美观、最实用且最简单的方法,因为在大多数编程语言中放置 LaTeX 标记并不困难。
用 Haskell 编写文字程序是很自然的,因为 Haskell 脚本包含一组声明而不是指令。 您可以按任意顺序放置所有声明。 这在其他语言中是不同的,在其他语言中,以特定方式对指令进行排序很重要。
我没有使用过 web 或 cweb 或类似的程序,但这些程序有助于以人类的逻辑顺序排版程序,而可以生成程序模块以进行正确的编译。
有一个名为listings的LaTeX包,它很容易使用,你可以开始每一段代码关闭注释并结束代码打开一个新注释,据我记得,像这样:
在文本的序言中你可以定义startcode*/ 和 /*endofcode 作为关键字,在列表包的额外定义中替换为空格。 请参阅包文档。
在 LaTeX 源代码的末尾只需输入:
这是 LaTeX 中的注释
在开始时你可以放置相反的:
当你想编译程序时删除%LaTeX注释符号,并在使用LaTeX编译时重新放置它。
如果您以前从未使用过 LaTeX,可以先从纯文本开始。
也许将它与 doxigen 结合起来索引所有内容。
LaTeX 不需要 Doxigen,因为它是一个排版系统,您可以在其中创建多个索引、超链接,将文档构建为一本书。
Haskell 程序通常以文字风格编写。 也许浏览一些书或文章来了解一下是个好主意。
The main idea of literate programing is to write programs as mathematical texts. One can define what does it mean every concept needed in the program as clear as possible, then explain how it is implemented in the language and why one decided to do it in such way and not other or what is going to be changed later.
The changes can be also documented by commenting the piece of code to change and inserting the new one explaining the reason for the change.
Some changes may depend on transformations of the code to optimize it's performance. For example making one loop, instead of 2 loops in some C like language, change one expression for a simpler one, etc. Or something more complex like changing other data structure to represent information.
Every change is well justified and documented.
One can understand about the problem domain of the program, just reading the source code, understanding it in depth. Avoiding mistakes due to ambiguities.
The genesis of the program is completely documented, one can recall everything later, because every thought is in the program.
Strictly speaking one can write literate programs with plain text, if the program is developed, but typesetting it in TeX/LaTeX is the most aesthetic, functional and easiest way, because it is not difficult to place LaTeX markup within the most programming languages.
It is natural to write literate programs in Haskell, because a Haskell script contain a set of declarations not instructions. You can place all declarations in any order. That is different in other languages where it is important to order the instructions in a particular way.
I have not used web nor cweb or similar programs, but those programs help to typeset the programs in a logical order for a human, whereas the program modules can be generated for proper compilation.
There is a LaTeX package called listings which is easy to use you can start every piece of code closing the comment and ending the code opening a new comment, as far as I remember, something like this:
in the preamble of the text you can define startcode*/ and /*endofcode as keywords to replace by spaces in the extra definitions for the listings package. See the package documentation.
at the end of the LaTeX source simply type:
which is a comment in LaTeX
in the beginning you can place the opposite:
Removing the % LaTeX comment sign when you want to compile the program, and putting it again when compiling by LaTeX.
If you have never used LaTeX before, you can start with plain text first.
Maybe combining it with doxigen to index everything.
Doxigen is not needed with LaTeX because it is a typesetting system, where you can create several indexes, hyper-links, structure the documentation as a book.
Haskell programs are usually written in literate style. Maybe it is a good idea to browse some book or article to see one.
你好,源小说作者,
正如有人在这里提到DOxygen:虽然这不允许真正的文学编程(作为限制的一个例子,这不允许对来源有重新排序的观点),然而,它似乎被它自己的倡导者(LP倡导者)认为是该领域的一个有价值的工具::它在有关 LP 工具的参考页:文学编程工具
Hello source novel authors,
As some one referred to DOxygen here : although this does not allow real Literate Programming (as an example of limitations, this does not allow to have a reordered view on sources), it however seems to be recognized as a valuable tools in this area, by its own advocates (LP advocates) : it is mentioned right at the top of this reference page about LP tools : Literate Programming Tools
您可以使用 Fundoc 来实现。 它是在文学编程的思想之上创建的
You can use Fundoc for it. It was created on top if the idea of Literate Programming