Documentation: Difference between revisions
added ocaml stub |
|||
Line 44: | Line 44: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|OCaml}}== |
|||
[http://caml.inria.fr/pub/docs/manual-ocaml/manual029.html OCamldoc] is a documentation generator that is included with OCaml. Documentation comments all start with <code>(**</code> (but no more than two asterisks) and end with <code>*)</code>. Like Javadoc, "tags" can be embedded starting with <code>@</code>. |
|||
=={{header|Python}}== |
=={{header|Python}}== |
Revision as of 07:58, 19 September 2009
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Show how to insert documentation for classes, functions, and/or variables in your language. If this documentation is built-in to the language, note it. If this documentation requires external tools, note them.
J
Use scripdoc: <lang j>NB. ========================================================= NB.*apply v apply verb x to y apply=: 128!:2
NB. ========================================================= NB.*def c : (explicit definition) def=: :
NB.*define a : 0 (explicit definition script form) define=: : 0
NB.*do v name for ". do=: ".
NB.*drop v name for }. drop=: }.</lang>
Java
Documentation is typically given using Javadoc comments. Documentation is generated from these comments using the Javadoc tool. The default output (from the standard doclet) takes the form of an HTML page with frames, so HTML is frequently embedded in the comments. The comments all start with /**
, end with */
, and usually have "tags" embedded starting with @
.
<lang java>/**
* This is a class documentation comment. This text shows at the top of the page for this class * @author Joe Schmoe */
public class Doc{
/** * This is a field comment for a variable */ private String field;
/** * This is a method comment. It has parameter tags (param), an exception tag (throws), * and a return value tag (return). * * @param num a number with the variable name "num" * @throws BadException when something bad happens * @return another number */ public int method(long num) throws BadException{ //...code here }
}</lang>
OCaml
OCamldoc is a documentation generator that is included with OCaml. Documentation comments all start with (**
(but no more than two asterisks) and end with *)
. Like Javadoc, "tags" can be embedded starting with @
.
Python
A string literal which is the first expression in a class, function, or module definition is called a docstring. It can be subsequently accessed at runtime using the .__doc__
attribute of the class, function, or module.
<lang python>class Doc(object):
""" This is a class docstring. Traditionally triple-quoted strings are used because they can span multiple lines and you can include quotation marks without escaping. """ def method(self, num): """This is a method docstring.""" pass</lang>
pydoc, a module of the Python standard library, can automatically generate documentation gleaned from docstrings of modules. The documentation can be presented as pages of text on a terminal; automatically served to a Web Browser; or saved as HTML. The command line pydoc command , in addition, can display docstring information in a TK based GUI browser.
The built-in help() function uses the pydoc module to display docstring information at the command prompt of the Python interactive shell. <lang python>>>> def somefunction(): "takes no args and returns None after doing not a lot"
>>> help(somefunction)
Help on function somefunction in module __main__:
somefunction()
takes no args and returns None after doing not a lot
>>> </lang>
Ruby
RDoc is the de-facto documentation tool that's bundled with Ruby distributions. From it's documentation:
- Rdoc is an application that produces documentation for one or more Ruby source files. We work similarly to JavaDoc, parsing the source, and extracting the definition for classes, modules, and methods (along with includes and requires). We associate with these optional documentation contained in the immediately preceding comment block, and then render the result using a pluggable output formatter.
RDoc produces output that looks like this.
Translating Java's example: <lang ruby>=begin rdoc RDoc is documented here[1].
This is a class documentation comment. This text shows at the top of the page for the class.
Comments can be written inside "=begin rdoc"/"end" blocks or in normal '#' comment blocks.
There are no '@parameters' like javadoc, but 'name-value' lists can be written: Author:: Joe Schmoe Date:: today =end
class Doc
# This is a comment for a Constant Constant = nil
# This is a method comment. Parameters and return values can be named # with the "call-seq" directive. # # call-seq: # a_method(first_arg, second_arg) -> return_value # def a_method(arg1, arg2='default value') do_stuff end
# Class methods will be shown in a separate section of the generated documentation. def self.class_method Constant end
end
- :include:boilerplate.txt</lang>
Tcl
Documentation for Tcl code is usually prepared in separate files using a tool like doctools, but inline docs (with all their inherent limitations) can be done with the likes of Robodoc. For example: <lang tcl>#****f* RosettaCode/TclDocDemo
- FUNCTION
- TclDocDemo is a simple illustration of how to do documentation
- of Tcl code using Robodoc.
- SYNOPSYS
- TclDocDemo foo bar
- INPUTS
- foo -- the first part of the message to print
- bar -- the last part of the message to print
- RESULT
- No result
- NOTES
- Prints a message based on a template by filling in with the
- supplied strings.
proc TclDocDemo {foo bar} {
puts [format "%s -- %s" $foo $bar]
}</lang> Both doctools and robodoc can produce output in multiple formats.