SlideShare a Scribd company logo
1 of 50
Code Documentation. That ugly thing..
Manios Christos
Thessaloniki Java Meetup Group
2014-11-28
1. Introduction
What is code documentation
 Written specifications, instructions, logic, proof of concept of source code
so it is readable by:
– Humans
– machines
Why is it important?
 A contract between callers and implementors.
 We continuously stumble upon it!
 It may be annoying.
 We argue about it!
– Σημείον αντιλεγόμενον.
– The reason of this presentation!
Let's argue!
Opposition arguments
 Running out of time!
 Not my responsibility..
 The others do not document. Why should I do it?
 I remember what I am coding!
 We are not Google! (or Microsoft, Pivotal etc.)
 Who is going to read it?
 If I do not document, I shall be irreplaceable.
Pro documentation arguments (1)
Documentation ..
 reminds you of what you code
 Helps in IDE autocompletion functionality.
 Creates a pleasant mood to your code editor / reviewer / colleague.
 Provides proof of your code quality (run / fail) .
 Reduces time spent on helping colleagues understand your code.
– Res ipsa loquitir (the thing itself speaks)
Pro documentation arguments (2)
Documentation ..
 Generates legible Javadoc output
 Reduces rage, curse “generation” and negative emotions of your code
reviewer / editor / project colleague!
 Helps project documentation writer’s work. (Who is this??)
 Helps building productive, geographically distributed teams.
Pro documentation arguments (3)
Documentation ..
 Advertises your work (and consequently yourself)!
 Makes your product more competitive to other products.
 Makes your code suitable for contributing in Open Source projects.
2. Javadoc
What is Javadoc
Javadoc is the style guide, tag and image conventions we use in
documentation comments for programs written in Java.
Javadoc guidelines
The following slides contain standards, guidelines and tips from:
 Oracle Javadoc
 Google Java Code style
 Joda Time (Stephen Colebourne's notes)
Javadoc guidelines (2)
Be aware of the following:
 Write Javadoc to be read as source code
 Use standard style for Javadoc comment: /** bob */
 Define a punchy first sentence
 Define clearly the required/allowed variations across
platform/implementations.
Package documentation
Create a file named package-info.java in every package:
(Example from Android SDK)
/**
* Contains the SQLite database management classes
* that an application would use to manage its own
* private database.
* Applications use these classes to manage private
* databases.
*/
package android.system.sqlite;
Documenting classes
 The Javadoc for each class and member begins with a brief summary
fragment.
 This is a fragment—a noun phrase or verb phrase, not a complete
sentence
 It does not begin with A {@code Foo} is a..., or This method
returns...
 nor does it form a complete imperative sentence like Save the
record..
 However, the fragment is capitalized and punctuated as if it were a
complete sentence.
Documenting classes
Lets see an example:
(Example from Android SDK)
/**
* Exposes methods to manage a SQLite database.
* <!-- skipped some content -->
* <p>In addition to SQLite's default <code>BINARY</code>
* collator, Android supplies
* two more, <code>LOCALIZED</code></p>
* <!-- […] --->
*/
public class SQLiteDatabase extends SQLiteClosable {
Documenting interfaces
Same as class javadoc. Specify a brief definition :
/**
* Interface for generic CRUD operations on a repository
for a specific type.
*
* @author Oliver Gierke
* @author Eberhard Wolff
*/
@NoRepositoryBean
public interface CrudRepository<T, ID extends
Serializable> extendsRepository<T, ID> {
}
(example from spring-data-commons)
Documenting Methods
 Use a striking first sentence
 Method descriptions begin with a verb phrase.
 Use 3rd person (descriptive) not 2nd person (prescriptive).
 Use @param, @return and @throws
 Javadoc has to be present at the minimum in every public or protected
member of the class.
 Exceptions:
 Self explanatory methods (handle with caution!!).
 Overrides of supertype members.
Documenting Methods: Example 1 (bad)
 Do not forget to use standard javadoc comments
(Example from Android SDK)
// Begins a transaction. Transactions can be nested
public void beginTransaction() {
// your code
}
Documenting Methods: Example 1 (good)
 Do not forget to use standard javadoc comments
(Example from Android SDK)
/**
* Begins a transaction. Transactions can be nested.
*/
public void beginTransaction() {
// your code
}
Documenting Methods: Example 2 (bad)
 Avoid - The description below says nothing beyond what you know from reading
the method name.
 Lazy use of JAutoDoc.
(Example from Oracle Javadoc guidelines)
/**
* Sets the tool tip text.
*
* @param text
* the text of the tool tip
*/
public void setToolTipText(String text) {
// your code
}
Documenting Methods: Example 2 (Good)
(Example from Oracle Javadoc guidelines)
/**
* Registers the text to display in a tool tip.
* The text displays when the cursor lingers
* over the component.
*
* @param text the string to display. If the text is
* null, the tool tip is turned off for
* this component.
*/
public void setToolTipText(String text) {
// your code
}
Documenting Methods: Example 3 (bad)
 Do not forget to mention extra capabilities of the parameters.
/**
* @param zkHost The client endpoint of the zookeeper quorum
* containing the cloud state, in the form HOST:PORT.
*/
public CloudSolrServer(String zkHost) {
// SolrJ code for constructor
}
(Example from CloudSolrServer (SolrJ 4.9.0). )
Documenting Methods: Example 3 (better)
 Personal modification: Clarify parameter variations.
/**
* @param zkHost
* The client endpoint of the zookeeper quorum
* containing the cloud state, in the form HOST:PORT.
*
* <p>It can contain multiple definitions in the form of
* <code>HOST1:PORT1, HOST1:PORT2, HOST2:PORT2<code></p>
*/
public CloudSolrServer(String zkHost) {
// SolrJ code for constructor
}
(Example from CloudSolrServer (SolrJ 4.9.0). )
Documenting Methods: Null handling
 Define null-handling for all parameters and return types
 “not null" means that null is not accepted and passing in null will
probably throw an exception , typically NullPointerException
 "may be null" means that null may be passed in. In general the
behaviour of the passed in null should be defined
 "null treated as xxx" means that a null input is equivalent to the
specified value
 "null returns xxx" means that a null input always returns the specified
value
Documenting Methods: Null handling example
/**
* Javadoc text.
*
* @param foo
* the foo parameter, not null
* @param bar
* the bar parameter, null returns null
* @return the baz content, null if not processed
*/
public String process(String foo, String bar) {
// code
}
Documenting Methods: Exceptions
 Document the following exceptions with the @throws tag:
 All checked exceptions.
 Those unchecked exceptions that the caller might reasonably want
to catch
Documenting Methods: Exceptions example
/**
* Adds a collection of documents, specifying max time before they
become committed
* @param docs the collection of documents
* @param commitWithinMs max time (in ms) before a commit will
happen
* @throws IOException If there is a low-level I/O error.
* @since solr 3.5
*/
public UpdateResponse add(Collection<SolrInputDocument> docs, int
commitWithinMs) throws SolrServerException, IOException {
// code
}
(Example from CloudSolrServer (SolrJ 4.9.0). )
Documenting Constants: Bad
 Do not forget to document constants
 Use standard javadoc
// dial a phone number
public static final String ACTION_DIAL="android.intent.action.DIAL";
Documenting Constants: Good
 Make your user feel comfortable, even if you think that the constant is
seld explanatory
(Example from Android SDK Intent class)
/**
* Activity Action: Dial a number as specified by the data. This shows a
UI
* with the number being dialed, allowing the user to explicitly
initiate
* the call.
* <!-- some content is skipped -->
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_DIAL = "android.intent.action.DIAL";
Documenting Enums
 There is no official reference for Enums
 Enums are classes, so treat them as classes!
3. Doclets
What is a doclet
Doclet is a program which works with the Javadoc tool to generate
documentation from code written in Java. Doclets :
 Are written in Java
 format the presentation of the content.
 create the file(s) that contains the documentation.
Java standard doclet
 Comes inside JDK distribution with Javadoc tool. :
 Format for Java S.E. 1.6
 Format for Java S.E. 1.7
 If you use Maven you can invoke it using:
 mvn javadoc:javadoc
Doclava
 Custom Javadoc doclet
 Refreshed look and feel
 Search capabilities
 Embeds versioning information (example: Android SDK reference)
 Use of templating engine for user customizations.
 More information in Google Code or Atlassian Bitbucket fork
 If you use Maven you can invoke it using:
 mvn javadoc:javadoc
4. Real world examples
(of well documented projects!)
Inspired by real world projects
 This presentation would not come into life without real world examples.
 Inspired by well known commercial projects.
 Inspired by well known open source projects.
Microsoft Development Network
 Also known as MSDN
 Commercial
 BUT .NET framework has became an Open Source project!!
 More to come!!
 Fully documented with tones of examples:
 Example: C# Reference documentation
 HEEEEY !!! This is not Java !!! BUT it is a lucid example of well
documenting software projects and programming languages.
Android OS
 Open source
 Fully documented, with examples and tutorials:
 Developer Portal
 Reference documentation
 SDK Javadoc
Apache Lucene / Solr
 Open source index / search engine
 Project sites:
 http://lucene.apache.org/
 http://lucene.apache.org/solr/
 SolrJ client reference: http://lucene.apache.org/solr/4_10_0/solr-
solrj/
Spring Framework
 Open source Java framework
 Fully documented: See http://spring.io/projects
5. One step forward:
Project documentation
Moving forward: Project documentation
 Code documentation is not a replacement of project documentation.
 Javadoc may have links to project documentation.
 Every project should be documented.
 Written and updated by documentation writers (Bazinga!)
 Collaboration between developers and writers.
 Use documentation tools (not MS Word files).
 Use source control for documentation (Git, SVN, Mercurial)
Documentation tools
Well known documentation tools:
 Markdown
 AsciiDoc
 reStructuredText
 Confluence
Markdown
 text-to-HTML conversion tool for web writers
 Markdown allows you to:
 write using an easy-to-read
 write easy-to-write plain text format
 then convert it to structurally valid XHTML (or HTML).Markdown
 Examples:
 Github pages
 Facebook osquery wiki
AsciiDoctor
 Asciidoctor is a fast text processor and publishing toolchain for converting
AsciiDoc content to HTML5, DocBook 5 (or 4.5) and other formats.
 Characteristics:
 Open source project
 Easier than XML based DocBook
 Example: Spring Data Solr Documentation
reStructuredText
 an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax
and parser system
 Easy to convert and export to other formats
 file format for textual data used primarily in the Python community for
technical documentation.
 used primarly in Sphinx documentation tool
 Example projects:
 Python documentation
 MongoDB docs
 Varnish cache docs
Confluence
 Commercial team collaboration software
 Used in corporate environments not only for documentation
 Free for Open Source Projects
 Example projects:
 Apache Foundation Wiki
Conclusion
 Do not hesitate to document your code.
 Establish a documentation strategy in your project / team / company.
 Use successful projects as examples.
 Let your good work speak for you.
Question Time

More Related Content

What's hot

Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreEsha Yadav
 
A great clash of symbols
A great clash of symbolsA great clash of symbols
A great clash of symbolsGreg Sohl
 
Manage software dependencies with ioc and aop
Manage software dependencies with ioc and aopManage software dependencies with ioc and aop
Manage software dependencies with ioc and aopStefano Leli
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With XtextSven Efftinge
 
Preparing Your Source Code for Distribution
Preparing Your Source Code for DistributionPreparing Your Source Code for Distribution
Preparing Your Source Code for DistributionOW2
 
THE CLR AND THE .NET FRAMEWORK, C#
THE CLR AND THE .NET FRAMEWORK, C#THE CLR AND THE .NET FRAMEWORK, C#
THE CLR AND THE .NET FRAMEWORK, C#MANOJ BURI
 
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181Mahmoud Samir Fayed
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)Shoaib Ghachi
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185Mahmoud Samir Fayed
 
Secure Ftp Java Style Rev004
Secure Ftp  Java Style Rev004Secure Ftp  Java Style Rev004
Secure Ftp Java Style Rev004Rich Helton
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programmingStoian Kirov
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol BuffersMatt O'Keefe
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# IntroductionSiraj Memon
 
Continuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanContinuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanCypress Data Defense
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 

What's hot (16)

Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya Rathore
 
A great clash of symbols
A great clash of symbolsA great clash of symbols
A great clash of symbols
 
Manage software dependencies with ioc and aop
Manage software dependencies with ioc and aopManage software dependencies with ioc and aop
Manage software dependencies with ioc and aop
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With Xtext
 
Protocol buffers
Protocol buffersProtocol buffers
Protocol buffers
 
Preparing Your Source Code for Distribution
Preparing Your Source Code for DistributionPreparing Your Source Code for Distribution
Preparing Your Source Code for Distribution
 
THE CLR AND THE .NET FRAMEWORK, C#
THE CLR AND THE .NET FRAMEWORK, C#THE CLR AND THE .NET FRAMEWORK, C#
THE CLR AND THE .NET FRAMEWORK, C#
 
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.2 book - Part 176 of 181
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185
 
Secure Ftp Java Style Rev004
Secure Ftp  Java Style Rev004Secure Ftp  Java Style Rev004
Secure Ftp Java Style Rev004
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programming
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Continuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanContinuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma Scan
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 

Similar to Code Documentation. That ugly thing...

Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lineslokeshG38
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Global objects in Node.pdf
Global objects in Node.pdfGlobal objects in Node.pdf
Global objects in Node.pdfSudhanshiBakre1
 
Android coding standard
Android coding standard Android coding standard
Android coding standard Rakesh Jha
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java CodingRahul Bhutkar
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introductionPeter Gfader
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the BeastBastian Feder
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09Bastian Feder
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into JavaTom Johnson
 
R:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java developmentR:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java developmentKen Kretsch
 
1 2 java development
1 2 java development1 2 java development
1 2 java developmentKen Kretsch
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix Solutions
 

Similar to Code Documentation. That ugly thing... (20)

Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Global objects in Node.pdf
Global objects in Node.pdfGlobal objects in Node.pdf
Global objects in Node.pdf
 
Android coding standard
Android coding standard Android coding standard
Android coding standard
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Readme
ReadmeReadme
Readme
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java Coding
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
Introduction
IntroductionIntroduction
Introduction
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 
R:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java developmentR:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java development
 
1 2 java development
1 2 java development1 2 java development
1 2 java development
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding Standards
 
Java se7 features
Java se7 featuresJava se7 features
Java se7 features
 

Recently uploaded

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Code Documentation. That ugly thing...

  • 1. Code Documentation. That ugly thing.. Manios Christos Thessaloniki Java Meetup Group 2014-11-28
  • 3. What is code documentation  Written specifications, instructions, logic, proof of concept of source code so it is readable by: – Humans – machines
  • 4. Why is it important?  A contract between callers and implementors.  We continuously stumble upon it!  It may be annoying.  We argue about it! – Σημείον αντιλεγόμενον. – The reason of this presentation!
  • 6. Opposition arguments  Running out of time!  Not my responsibility..  The others do not document. Why should I do it?  I remember what I am coding!  We are not Google! (or Microsoft, Pivotal etc.)  Who is going to read it?  If I do not document, I shall be irreplaceable.
  • 7. Pro documentation arguments (1) Documentation ..  reminds you of what you code  Helps in IDE autocompletion functionality.  Creates a pleasant mood to your code editor / reviewer / colleague.  Provides proof of your code quality (run / fail) .  Reduces time spent on helping colleagues understand your code. – Res ipsa loquitir (the thing itself speaks)
  • 8. Pro documentation arguments (2) Documentation ..  Generates legible Javadoc output  Reduces rage, curse “generation” and negative emotions of your code reviewer / editor / project colleague!  Helps project documentation writer’s work. (Who is this??)  Helps building productive, geographically distributed teams.
  • 9. Pro documentation arguments (3) Documentation ..  Advertises your work (and consequently yourself)!  Makes your product more competitive to other products.  Makes your code suitable for contributing in Open Source projects.
  • 11. What is Javadoc Javadoc is the style guide, tag and image conventions we use in documentation comments for programs written in Java.
  • 12. Javadoc guidelines The following slides contain standards, guidelines and tips from:  Oracle Javadoc  Google Java Code style  Joda Time (Stephen Colebourne's notes)
  • 13. Javadoc guidelines (2) Be aware of the following:  Write Javadoc to be read as source code  Use standard style for Javadoc comment: /** bob */  Define a punchy first sentence  Define clearly the required/allowed variations across platform/implementations.
  • 14. Package documentation Create a file named package-info.java in every package: (Example from Android SDK) /** * Contains the SQLite database management classes * that an application would use to manage its own * private database. * Applications use these classes to manage private * databases. */ package android.system.sqlite;
  • 15. Documenting classes  The Javadoc for each class and member begins with a brief summary fragment.  This is a fragment—a noun phrase or verb phrase, not a complete sentence  It does not begin with A {@code Foo} is a..., or This method returns...  nor does it form a complete imperative sentence like Save the record..  However, the fragment is capitalized and punctuated as if it were a complete sentence.
  • 16. Documenting classes Lets see an example: (Example from Android SDK) /** * Exposes methods to manage a SQLite database. * <!-- skipped some content --> * <p>In addition to SQLite's default <code>BINARY</code> * collator, Android supplies * two more, <code>LOCALIZED</code></p> * <!-- […] ---> */ public class SQLiteDatabase extends SQLiteClosable {
  • 17. Documenting interfaces Same as class javadoc. Specify a brief definition : /** * Interface for generic CRUD operations on a repository for a specific type. * * @author Oliver Gierke * @author Eberhard Wolff */ @NoRepositoryBean public interface CrudRepository<T, ID extends Serializable> extendsRepository<T, ID> { } (example from spring-data-commons)
  • 18. Documenting Methods  Use a striking first sentence  Method descriptions begin with a verb phrase.  Use 3rd person (descriptive) not 2nd person (prescriptive).  Use @param, @return and @throws  Javadoc has to be present at the minimum in every public or protected member of the class.  Exceptions:  Self explanatory methods (handle with caution!!).  Overrides of supertype members.
  • 19. Documenting Methods: Example 1 (bad)  Do not forget to use standard javadoc comments (Example from Android SDK) // Begins a transaction. Transactions can be nested public void beginTransaction() { // your code }
  • 20. Documenting Methods: Example 1 (good)  Do not forget to use standard javadoc comments (Example from Android SDK) /** * Begins a transaction. Transactions can be nested. */ public void beginTransaction() { // your code }
  • 21. Documenting Methods: Example 2 (bad)  Avoid - The description below says nothing beyond what you know from reading the method name.  Lazy use of JAutoDoc. (Example from Oracle Javadoc guidelines) /** * Sets the tool tip text. * * @param text * the text of the tool tip */ public void setToolTipText(String text) { // your code }
  • 22. Documenting Methods: Example 2 (Good) (Example from Oracle Javadoc guidelines) /** * Registers the text to display in a tool tip. * The text displays when the cursor lingers * over the component. * * @param text the string to display. If the text is * null, the tool tip is turned off for * this component. */ public void setToolTipText(String text) { // your code }
  • 23. Documenting Methods: Example 3 (bad)  Do not forget to mention extra capabilities of the parameters. /** * @param zkHost The client endpoint of the zookeeper quorum * containing the cloud state, in the form HOST:PORT. */ public CloudSolrServer(String zkHost) { // SolrJ code for constructor } (Example from CloudSolrServer (SolrJ 4.9.0). )
  • 24. Documenting Methods: Example 3 (better)  Personal modification: Clarify parameter variations. /** * @param zkHost * The client endpoint of the zookeeper quorum * containing the cloud state, in the form HOST:PORT. * * <p>It can contain multiple definitions in the form of * <code>HOST1:PORT1, HOST1:PORT2, HOST2:PORT2<code></p> */ public CloudSolrServer(String zkHost) { // SolrJ code for constructor } (Example from CloudSolrServer (SolrJ 4.9.0). )
  • 25. Documenting Methods: Null handling  Define null-handling for all parameters and return types  “not null" means that null is not accepted and passing in null will probably throw an exception , typically NullPointerException  "may be null" means that null may be passed in. In general the behaviour of the passed in null should be defined  "null treated as xxx" means that a null input is equivalent to the specified value  "null returns xxx" means that a null input always returns the specified value
  • 26. Documenting Methods: Null handling example /** * Javadoc text. * * @param foo * the foo parameter, not null * @param bar * the bar parameter, null returns null * @return the baz content, null if not processed */ public String process(String foo, String bar) { // code }
  • 27. Documenting Methods: Exceptions  Document the following exceptions with the @throws tag:  All checked exceptions.  Those unchecked exceptions that the caller might reasonably want to catch
  • 28. Documenting Methods: Exceptions example /** * Adds a collection of documents, specifying max time before they become committed * @param docs the collection of documents * @param commitWithinMs max time (in ms) before a commit will happen * @throws IOException If there is a low-level I/O error. * @since solr 3.5 */ public UpdateResponse add(Collection<SolrInputDocument> docs, int commitWithinMs) throws SolrServerException, IOException { // code } (Example from CloudSolrServer (SolrJ 4.9.0). )
  • 29. Documenting Constants: Bad  Do not forget to document constants  Use standard javadoc // dial a phone number public static final String ACTION_DIAL="android.intent.action.DIAL";
  • 30. Documenting Constants: Good  Make your user feel comfortable, even if you think that the constant is seld explanatory (Example from Android SDK Intent class) /** * Activity Action: Dial a number as specified by the data. This shows a UI * with the number being dialed, allowing the user to explicitly initiate * the call. * <!-- some content is skipped --> */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_DIAL = "android.intent.action.DIAL";
  • 31. Documenting Enums  There is no official reference for Enums  Enums are classes, so treat them as classes!
  • 33. What is a doclet Doclet is a program which works with the Javadoc tool to generate documentation from code written in Java. Doclets :  Are written in Java  format the presentation of the content.  create the file(s) that contains the documentation.
  • 34. Java standard doclet  Comes inside JDK distribution with Javadoc tool. :  Format for Java S.E. 1.6  Format for Java S.E. 1.7  If you use Maven you can invoke it using:  mvn javadoc:javadoc
  • 35. Doclava  Custom Javadoc doclet  Refreshed look and feel  Search capabilities  Embeds versioning information (example: Android SDK reference)  Use of templating engine for user customizations.  More information in Google Code or Atlassian Bitbucket fork  If you use Maven you can invoke it using:  mvn javadoc:javadoc
  • 36. 4. Real world examples (of well documented projects!)
  • 37. Inspired by real world projects  This presentation would not come into life without real world examples.  Inspired by well known commercial projects.  Inspired by well known open source projects.
  • 38. Microsoft Development Network  Also known as MSDN  Commercial  BUT .NET framework has became an Open Source project!!  More to come!!  Fully documented with tones of examples:  Example: C# Reference documentation  HEEEEY !!! This is not Java !!! BUT it is a lucid example of well documenting software projects and programming languages.
  • 39. Android OS  Open source  Fully documented, with examples and tutorials:  Developer Portal  Reference documentation  SDK Javadoc
  • 40. Apache Lucene / Solr  Open source index / search engine  Project sites:  http://lucene.apache.org/  http://lucene.apache.org/solr/  SolrJ client reference: http://lucene.apache.org/solr/4_10_0/solr- solrj/
  • 41. Spring Framework  Open source Java framework  Fully documented: See http://spring.io/projects
  • 42. 5. One step forward: Project documentation
  • 43. Moving forward: Project documentation  Code documentation is not a replacement of project documentation.  Javadoc may have links to project documentation.  Every project should be documented.  Written and updated by documentation writers (Bazinga!)  Collaboration between developers and writers.  Use documentation tools (not MS Word files).  Use source control for documentation (Git, SVN, Mercurial)
  • 44. Documentation tools Well known documentation tools:  Markdown  AsciiDoc  reStructuredText  Confluence
  • 45. Markdown  text-to-HTML conversion tool for web writers  Markdown allows you to:  write using an easy-to-read  write easy-to-write plain text format  then convert it to structurally valid XHTML (or HTML).Markdown  Examples:  Github pages  Facebook osquery wiki
  • 46. AsciiDoctor  Asciidoctor is a fast text processor and publishing toolchain for converting AsciiDoc content to HTML5, DocBook 5 (or 4.5) and other formats.  Characteristics:  Open source project  Easier than XML based DocBook  Example: Spring Data Solr Documentation
  • 47. reStructuredText  an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system  Easy to convert and export to other formats  file format for textual data used primarily in the Python community for technical documentation.  used primarly in Sphinx documentation tool  Example projects:  Python documentation  MongoDB docs  Varnish cache docs
  • 48. Confluence  Commercial team collaboration software  Used in corporate environments not only for documentation  Free for Open Source Projects  Example projects:  Apache Foundation Wiki
  • 49. Conclusion  Do not hesitate to document your code.  Establish a documentation strategy in your project / team / company.  Use successful projects as examples.  Let your good work speak for you.