Well it depends on which style guide your paper is being written to comply to...
Usually code should be written in a monotype font so that it is easily readable (E.g. Lucida Sans Console or Courier New). This means that all letters take up the same space on the page.
When I have written bits for publishing I have indented the code 2.5cm from the side and given it a light grey background, in a Lucida Sans Console font... Following C style code indenting.
I would ask your institution if they have a style guide, but as you have a lack of this ability go with a popular style guide such as the Harvard system and make sure you follow the same format throughout.
When writing inline, get rid of code that is irrelevant to the explanation (such as import statements as previously mentioned, but potentially also variable declarations that are "obvious" and the like). The goal of code placed inline should be for easy crossreference with the paragraph describing that code block.
Code placed in appendices should be complete (as in - you can put this into your compiler and press go).
Don't be scared of placing heavily cut down code in snippets, along with a reference to the appendix containing the full code - the appendix code is for someone to read/run separately. the inline code is for people to glance at and help understand the specific point of that section.
I would say Courier font with standard text spacing and standard line spacing, all black text, proper indentation.
In terms of the code itself, omit import statements, comments are okay. You may want to add foot notes like {1}, {2}, inline in the code as a comment and reference below in the text that explains the code.
I realise that this is an old question, but do not forget to number the lines in your code! For one-liners, it's okay to skip numbers, but anything larger, they're almost required.
If you are writing a research report, you should be using LaTeX.
I typically use the LaTeX vancyvrb package and the Verbatim.
However, another option is to use the listings package. It can input a file directly using the lstinputlisting command. It automatically numbers your lines and uses the _ character instead of the space character, but this is programmable. It's really quite nice.
You should use appropriate, established syntax highlighting. Latex's listings package, mentioned by vy32, has syntax highlighting styles for both Javascript and PHP, as does the Pygments program, which outputs to, among others, Latex, HTML, and RTF.
发布评论
评论(6)
好吧,这取决于您的论文编写时要遵循哪种风格指南...
通常代码应该以单色字体编写,以便于阅读(例如 Lucida Sans Console 或 Courier New)。这意味着所有字母在页面上占据相同的空间。
当我编写用于发布的内容时,我将代码从侧面缩进 2.5 厘米,并以 Lucida Sans Console 字体为其提供浅灰色背景...遵循 C 样式代码缩进。
我会问您的机构是否有风格指南,但由于您缺乏这种能力,因此请使用流行的风格指南(例如哈佛系统),并确保自始至终遵循相同的格式。
以下是来自 Google Scholar 的显示风格的期刊列表:
http://scholar.google.com.au/scholar?hl=en&q=PHP+SQL+programming+journal&btnG=Search&as_sdt=2000&as_ylo=&as_vis=0
Well it depends on which style guide your paper is being written to comply to...
Usually code should be written in a monotype font so that it is easily readable (E.g. Lucida Sans Console or Courier New). This means that all letters take up the same space on the page.
When I have written bits for publishing I have indented the code 2.5cm from the side and given it a light grey background, in a Lucida Sans Console font... Following C style code indenting.
I would ask your institution if they have a style guide, but as you have a lack of this ability go with a popular style guide such as the Harvard system and make sure you follow the same format throughout.
Here is a list of journals from Google Scholar which display style:
http://scholar.google.com.au/scholar?hl=en&q=PHP+SQL+programming+journal&btnG=Search&as_sdt=2000&as_ylo=&as_vis=0
这是我的偏好:
在内联编写时,去掉与解释无关的代码(例如 import
如前所述的语句,但也可能是“显而易见的”变量声明等)。内联放置代码的目的应该是为了与描述该代码块的段落轻松交叉引用。
附录中的代码应该是完整的(如 - 您可以将其放入编译器中并按“执行”)。
不要害怕将大量删减的代码放入片段中,并引用包含完整代码的附录 - 附录代码供某人单独阅读/运行。内联代码供人们浏览并帮助理解该部分的具体要点。
This is my preference:
When writing inline, get rid of code that is irrelevant to the explanation (such as import
statements as previously mentioned, but potentially also variable declarations that are "obvious" and the like). The goal of code placed inline should be for easy crossreference with the paragraph describing that code block.
Code placed in appendices should be complete (as in - you can put this into your compiler and press go).
Don't be scared of placing heavily cut down code in snippets, along with a reference to the appendix containing the full code - the appendix code is for someone to read/run separately. the inline code is for people to glance at and help understand the specific point of that section.
我想说的是具有标准文本间距和标准行间距的 Courier 字体,全黑文本,适当的缩进。
就代码本身而言,省略import语句、注释就可以了。您可能需要在代码中内嵌添加脚注,例如 {1}、{2},作为注释并在下面解释代码的文本中引用。
本文第 6 页有一个示例:
http:// /www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf
I would say Courier font with standard text spacing and standard line spacing, all black text, proper indentation.
In terms of the code itself, omit import statements, comments are okay. You may want to add foot notes like {1}, {2}, inline in the code as a comment and reference below in the text that explains the code.
This paper has an example on page 6:
http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf
我意识到这是一个老问题,但不要忘记对代码中的行进行编号!对于单行文字来说,跳过数字是可以的,但是对于更大的数字,它们几乎是必需的。
I realise that this is an old question, but do not forget to number the lines in your code! For one-liners, it's okay to skip numbers, but anything larger, they're almost required.
如果您正在撰写研究报告,您应该使用 LaTeX。
我通常使用 LaTeX
vancyvrb
包和Verbatim
。但是,另一种选择是使用
listings
包。它可以使用lstinputlisting
命令直接输入文件。它会自动对行进行编号并使用 _ 字符而不是空格字符,但这是可编程的。真的很不错。If you are writing a research report, you should be using LaTeX.
I typically use the LaTeX
vancyvrb
package and theVerbatim
.However, another option is to use the
listings
package. It can input a file directly using thelstinputlisting
command. It automatically numbers your lines and uses the _ character instead of the space character, but this is programmable. It's really quite nice.JD 和 Ben 说的话。
您应该使用适当的、既定的语法突出显示。 vy32 提到的 Latex 的 listings 包有Javascript 和 PHP 的语法高亮样式,Pygments 程序也是如此,它输出到 Latex、HTML 等和 RTF。
What JD and Ben said.
You should use appropriate, established syntax highlighting. Latex's listings package, mentioned by vy32, has syntax highlighting styles for both Javascript and PHP, as does the Pygments program, which outputs to, among others, Latex, HTML, and RTF.