离线和在书中呈现源代码的最佳方式是什么?
由于对排版有些痴迷,我很好奇:在线和离线呈现代码的最佳方式是什么。 我特别感兴趣的是:
- 什么类型的字体和尺寸最适合在线和离线? 在代码中使用比例字体是否更好(例如,像 Stroustrup 在“C++ 编程语言”中所做的那样)? 衬线、无衬线或混合?
- 代码应该如何注释 - 使用典型的
// comment
标记,或者可能只是使用不同的字体(并且没有注释标签)? - 是否值得绘制箭头(或类似的东西)来显示不同的代码块如何相互关联?
- 在几列中并排显示代码是否有效?
- 有人需要诸如行编号、更改行等之类的东西吗?
Being somewhat typographically obsessed, I am curious: what is the best way to present code - both online and offline. In particular, I'm interested in:
- What kinds of typefaces and sizes work best online and offline? Is it better to use proportional fonts for code (e.g., like Stroustrup does in 'The C++ Programming Language')? Serif, sans-serif, or mixed?
- How should code be annotated - with the typical
// comment
markup, or perhaps just with a different typeface (and no comment tags)? - Is it worth drawing arrows (or something similar) to show how different blocks of code relate to one another?
- Does showing code in several columns side-by-side work at all?
- Does anyone need things like line numbering, altering lines, etc.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这并不能完全回答大多数问题,但您可能有兴趣阅读文学编程。 其要点是您在同一个文档中编写代码和文档,并且它的格式适合网络或打印或其他任何形式。 当我在这里说文档时,它通常不是一行文档片段,而是描述程序中发生的情况的整个段落或页面。
This doesn't exactly answer most of the questions, but you might be interested in reading up on Literate Programming. The gist of it is that you write your code and documentation in the same document, and it is formatted for web or print or whatever. And when I say documentation here, it's not usually one-line snippets of documentation, but whole paragraphs or pages describing what's going on in the program.
好吧,让我投票反对 BS 在 TC++PL 中使用的比例字体。 这真的让我抓狂! 《Effective STL》中的索克特·迈耶斯 (Soctt Meyers) 也有类似的情况,但还添加了一些令人讨厌的突出显示,从而增加了恐怖感。
对我来说,关于编程的经典书籍永远是《K&R》,因为我认为它从未在演示的清晰度方面得到过改进。 所以我建议盲目地复制它。
Well, let me add my vote against proportional fonts, as used by BS in TC++PL. It really drives me nuts! Similarly Soctt Meyers in Effective STL, with the added horror of some nasty hightlighting.
For me, the classic book on programming will always be K&R, as I don't think it has ever been improved on for clarity of presentation. so I would suggest copying it slavishly.
我喜欢在文本中编写虚拟代码时使用扩展字符集。 用于代码和数学标记的 LaTeX 字体效果很好。
一个很好的例子是使用左箭头进行赋值或绑定,而不是
=
。 我见过的书籍中最好的代码示例是《Dragon Book》或《TAOCP》。 我认为由于能够呈现这些字符以及与常见语法的关系而将数学词源混合在一起是很棒的。常见的固定快递类型字体和通过 Computer Modern in LaTeX 提供的高级数学标记的混合,我认为对于具有数学倾向的读者来说效果很好......而且它看起来非常漂亮。
I like the use of an extended character-set when writing dummy code in text. The LaTeX fonts for code and math markup work well.
A good example would be using a left arrow for assignment or binding rather than
=
. The best examples of code in books I have seen has been things like the Dragon Book or TAOCP. I think a mixture of mathematical etymology due to the ability to render those characters and a relation to common syntax is great.A mixture of the usual fixed-courier type fonts and advanced math markup available through Computer Modern in LaTeX I think works well for readers of a mathematical disposition ... and it can look very nice.
我想到的只有几件事:
Just a couple of things that cross my mind:
康索拉斯。
Consolas.