SlideShare a Scribd company logo
1 of 80
Analyzing Code Comments
Pooja Rani
PhD student
Software Composition Group
University of Bern, Switzerland
Roadmap
■ Code comment types
■ What is a good comment?
■ Challenges
■ Address the challenges
2
We use different tools and
techniques to understand code.
3
4
In GT, try to understand the class “BrLook”, “BlElement”
without class comments.
5
6
7
Code can describe how but it can
not explain why.
Code comment types
■ Documentation (/** … */)
(also used for packages / classes / methods
■ Block comments (/* … */)
■ Inline comments (//…)
8
Programming languages follow different
syntaxes for comments.
9
However, most languages support a distinct delimiter for
comments.
10
Java class comment
11
Java class comment
Python class comment
12
Java class comment Python class comment
GT class comment
13
Java method comment
14
Java method comment Python method comment
15
Java method comment Python method comment
GT method comment
What is a good comment?
16
/*
* Dear Maintainer
*
* Once you are done trying to ‘optimize’ this routine,
* and you have realized what a terrible mistake that was,
* please increment the following counter as a warning
* to the next guy.
*
* total_hours_wasted_here = 73
*
// When I wrote this, only God and I understood what I was doing
// Now, God only knows
#This is brilliant
#Thanks. It’s nap time.
What is a good comment?
17
// format matched kk:mm:ss EEE, MMM dd, yyy
Pattern timePattern = Pattern.compile("d*:d*:d* w*, w*, d*, d*");
Note that to encode a String as Base64, you first have to encode the characters as bytes
using character encoder.
It makes sense to use me if scalable element has fixed or matching parent horizontal size
but fits content vertically.
Examples
Preconditions
Warnings
■ Helps other developers in working with your code
■ Describes why, and not how
■ Reveals intent, limitation, assumptions, design decisions
■ Justifies the violation of a programming style
18
What is a good comment?
Coding style guidelines
■ To write consistent & informative comments
■ “Write a one-line summary of the class in the class
comment”.
19
Coding style guidelines
■ Java: Oracle, Apache, Google
■ Python: Pep, Google, Numpy
■ Smalltalk: Smalltalk style guide, comment template
■ Ruby: RubyStyle
20
Oracle: https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html
Numpy:https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
Smalltalk:http://sdmeta.gforge.inria.fr/FreeBooks/WithStyle/SmalltalkWithStyle.pdf
21
Pharo class comment template
Smalltalk:http://sdmeta.gforge.inria.fr/FreeBooks/WithStyle/SmalltalkWithStyle.pdf
Challenges
■ Missing comments
■ Inconsistent & Incomplete
■ Duplicate comments
■ Outdated comments
■ Takes time to write
■ Complex to understand
22
Impact overall quality of
comments
23
We use different tools and
techniques to analyze comment
quality.
Code analysis tools
■ Syntax
■ Semantics
■ Style
24
C de
Te i g
C
a a i
C di g e
chec e
S a ic a a i
R i e
Da a
A a i
IDE
25
But what about comments?
Comment analysis tools
■ Syntax
■ Semantics
■ Style
26
Da a
A a i
C e
Te i g
C
a a i
C di g e
chec e
S a ic a a i
R i e
IDE
Comment analysis tools
■ Syntax
■ Semantics
■ Style
27
Da a
A a i
C e
Te i g
C
a a i
C di g e
chec e
S a ic a a i
R i e
IDE
Javadoc, pydoc
C
heckstyle, Pylint
Documentation tools
■ Check syntax of comments
■ Do not check the content
28
Coding style checkers
■ Java: Checkstyle, PMD
■ Python: pylint, pycodestyle
■ Smalltalk: No linter
■ Ruby: RuboCop
29
Coding style checkers
■ Detect presence/absence of comments
■ Check whether comments follow style guidelines or not
to some extent.
■ Limited to selected metrics (code/comment ratio)
30
31
Comment Content Analysis
32
Information types in Java code comments
■ Analyze code comments of
big and diverse projects
■ Identified the information
types using machine
learning approaches.
33
Information types in Java code comments
34
Information types in Python code
35
Information types in Pharo code comments
1
1
2
3
4
3
5
4
8
10
11
21
29
34
33
43
40
51
57
75
134
231
256
0 50 100 150 200 250 300
License
TODO comments
Links
Coding Guidelines
Extensions
Other
Naming conventions
Observations
Subclasses explanation
Recommendations
Discourse
ReferencesOtherResources
Dependencies
Contracts
Key Messages
Instance Variables
Warnings
Implementation Points
Examples
Class References
Collaborators
Responsibility
Intent
Number of classes
Categories
36
Information types in Pharo code comments
1
1
2
3
4
3
5
4
8
10
11
21
29
34
33
43
40
51
57
75
134
231
256
0 50 100 150 200 250 300
License
TODO comments
Links
Coding Guidelines
Extensions
Other
Naming conventions
Observations
Subclasses explanation
Recommendations
Discourse
ReferencesOtherResources
Dependencies
Contracts
Key Messages
Instance Variables
Warnings
Implementation Points
Examples
Class References
Collaborators
Responsibility
Intent
Number of classes
Categories
37
Information types across Pharo projects
38
Class: FTTreeItem
I am an abstract class to define an Item use by a tree data source of Fast table.
Description
-------------------------------------------------
I define the basics methods needed by a FTTreeDataSource.
I use FTTreeItem to manage my elements and I am use by a FTFastTable.
Public API and Key Messages
-------------------------------------------------
• #data. anObject from: aFTTreeDataSource
This is my constructor that is use by FTTreeDataSource and myself
Example
-------------------------------------------------
Should not be instanciate.
Internal Representation and Key Implementation Points.
-------------------------------------------------
Instance Variables
dataSource: I am the dataSource that holds this Item.
children: I am a collection of Items calculate by the item. I contains the chldren of the
Item.
Collected data
39
Class: FTTreeItem
I am an abstract class to define an Item use by a tree data source of Fast table.
Description
-------------------------------------------------
I define the basics methods needed by a FTTreeDataSource.
I use FTTreeItem to manage my elements and I am use by a FTFastTable.
Public API and Key Messages
-------------------------------------------------
• #data. anObject from: aFTTreeDataSource
This is my constructor that is use by FTTreeDataSource and myself
Example
-------------------------------------------------
Should not be instanciate.
Internal Representation and Key Implementation Points.
-------------------------------------------------
Instance Variables
dataSource: I am the dataSource that holds this Item.
children: I am a collection of Items calculate by the item. I contains the chldren of the
Item.
Intent
Responsibility
Key	Messages
Warning
Instance	variables
Collaborator
Collected data
40
Taxonomy
41
Class: FTTreeItem
I am an abstract class to define an Item use by a tree data source of Fast table.
Description
-------------------------------------------------
I define the basics methods needed by a FTTreeDataSource.
I use FTTreeItem to manage my elements and I am use by a FTFastTable.
Public API and Key Messages
-------------------------------------------------
• #data. anObject from: aFTTreeDataSource
This is my constructor that is use by FTTreeDataSource and myself
Example
-------------------------------------------------
Should not be instanciate.
Internal Representation and Key Implementation Points.
-------------------------------------------------
Instance Variables
dataSource: I am the dataSource that holds this Item.
children: I am a collection of Items calculate by the item. I contains the chldren of the
Item.
Intent
Responsibility
Key	Messages
Warning
Instance	variables
Collaborator
Identification of patterns
42
Techniques
43
Training & Testing
44
Workflow
Comments do change over time
45
We need to understand their change behaviour.
46
Comment Evolution
Java code comment co-evolution
47
48
Java code comment co-evolution
Source: Analyzing the co-evolution of comments and source code, fig 1
Java code comment co-evolution
■ Over 50% of the comment
changes are related to
source code changes
■ Newly added code gets
barely commented
49
Pharo class comment co-evolution
50
Pharo Comment Evolution
51
Pharo Comment Evolution
52
Pharo class comment evolution
53
■ Over 50% of the comment
changes are related to
source code changes
■ Newly added code gets
commented often
54
Pharo class comment co-evolution
Not all comments need to be changed
when the code is changed & vice versa
55
We need to identify such cases when a comment needs to be changed
Automatic generation and
summarization of comments
56
Code summaries
57
■ “Automatically generated, short, yet accurate descriptions of
source code entities”.
■ They give more information than just the header or the name
of an artifact.
■ Significantly shorter and faster to read than the source code
they summarise
Example of natural language summaries
58
35
https://www.textcompactor.com/
Example of natural language summaries
59
35
https://www.textcompactor.com/
60
Example of Natural Language Summaries
MILAN, Italy, April 18. A small airplane crashed into a government
building in heart of Milan, setting the top floors on fire, Italian
police reported. There were no immediate reports on casualties as
rescue workers attempted to clear the area in the city's financial
district. Few details of the crash were available, but news reports
about it immediately set off fears that it might be a terrorist act
akin to the Sept. 11 attacks in the United States. Those fears sent
U.S. stocks tumbling to session lows in late morning trading.
Witnesses reported hearing a loud explosion from the 30-story
office building, which houses the administrative offices of the local
Lombardy region and sits next to the city's central train station.
Italian state television said the crash put a hole in the 25th floor
of the Pirelli building. News reports said smoke poured from the
opening. Police and ambulances rushed to the building in downtown
Milan. No further details were immediately available.
61
Example of natural language summaries
MILAN, Italy, April 18. A small airplane crashed into a government
building in heart of Milan, setting the top floors on fire, Italian
police reported. There were no immediate reports on casualties as
rescue workers attempted to clear the area in the city's financial
district. Few details of the crash were available, but news reports
about it immediately set off fears that it might be a terrorist act
akin to the Sept. 11 attacks in the United States. Those fears sent
U.S. stocks tumbling to session lows in late morning trading.
Witnesses reported hearing a loud explosion from the 30-story
office building, which houses the administrative offices of the local
Lombardy region and sits next to the city's central train station.
Italian state television said the crash put a hole in the 25th floor
of the Pirelli building. News reports said smoke poured from the
opening. Police and ambulances rushed to the building in downtown
Milan. No further details were immediately available.
How many victims?
Was it a terrorist act?
What was the target?
What happened?
Says who?
When, where?
Comment summaries
62
https://www.textcompactor.com/
63
https://www.textcompactor.com/
Comment summaries
Navigating classes
64
https://github.com/larsb/atunesplus/blob/master/aTunes/src/main/java/net/sourceforge/atunes/kernel/modules/repository/audio/AudioFile.java
Navigating classes
65
https://github.com/larsb/atunesplus/blob/master/aTunes/src/main/java/net/sourceforge/atunes/kernel/modules/repository/audio/AudioFile.java
We look at:
- Name of the class
- Attributes
- Methods
- Dependencies between classes
Java class summaries
■ Identify the stereotypes.
■ Gather the heuristics
■ Generate the class
summary
66
Workflow
67
JSummarizer: An automatic generator of natural language summaries for Java classes by Moreno
Summary
68
■ Missing some information
■ Not easy to understand
69
Content adequacy vs. expressiveness
To overcome these limitations…
70
Researchers proposed to detect source code
descriptions from external sources:

■ Mailing list and issue trackers

■ StackOverflow discussions
What information to include, how much,
and how to generate and present it.
71
Linguistic Analysis
72
73
TAACO
Linguistic analysis for English
74
TAACO TAALES
Linguistic analysis for English
75
TAACO TAALES ARTE
Linguistic analysis for English
76
Style analysis of Java comments
■ Metric-based methods
■ Comment too short, too long
■ Check documentable items
(tags) of a code entity
■ Readability of the comments
77
Style analysis of Java comments
■ Metric-based method
■ Check whether comments
are similar to method names
Adjust the metrics and their thresholds
according to comment.
78
Future work
■ Evaluate if a comment is good or not
■ Detect the inconsistency in the comment
■ Propose refactoring of the comment, if required.
79
Summary
80

More Related Content

Recently uploaded

Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdfSelfMade bd
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmuxevmux96
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Clinic
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Lisi Hocke
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jNeo4j
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...drm1699
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxNeo4j
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphNeo4j
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 

Recently uploaded (20)

Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Analyzing code comment aspects

  • 1. Analyzing Code Comments Pooja Rani PhD student Software Composition Group University of Bern, Switzerland
  • 2. Roadmap ■ Code comment types ■ What is a good comment? ■ Challenges ■ Address the challenges 2
  • 3. We use different tools and techniques to understand code. 3
  • 4. 4 In GT, try to understand the class “BrLook”, “BlElement” without class comments.
  • 5. 5
  • 6. 6
  • 7. 7 Code can describe how but it can not explain why.
  • 8. Code comment types ■ Documentation (/** … */) (also used for packages / classes / methods ■ Block comments (/* … */) ■ Inline comments (//…) 8
  • 9. Programming languages follow different syntaxes for comments. 9 However, most languages support a distinct delimiter for comments.
  • 12. 12 Java class comment Python class comment GT class comment
  • 14. 14 Java method comment Python method comment
  • 15. 15 Java method comment Python method comment GT method comment
  • 16. What is a good comment? 16 /* * Dear Maintainer * * Once you are done trying to ‘optimize’ this routine, * and you have realized what a terrible mistake that was, * please increment the following counter as a warning * to the next guy. * * total_hours_wasted_here = 73 * // When I wrote this, only God and I understood what I was doing // Now, God only knows #This is brilliant #Thanks. It’s nap time.
  • 17. What is a good comment? 17 // format matched kk:mm:ss EEE, MMM dd, yyy Pattern timePattern = Pattern.compile("d*:d*:d* w*, w*, d*, d*"); Note that to encode a String as Base64, you first have to encode the characters as bytes using character encoder. It makes sense to use me if scalable element has fixed or matching parent horizontal size but fits content vertically. Examples Preconditions Warnings
  • 18. ■ Helps other developers in working with your code ■ Describes why, and not how ■ Reveals intent, limitation, assumptions, design decisions ■ Justifies the violation of a programming style 18 What is a good comment?
  • 19. Coding style guidelines ■ To write consistent & informative comments ■ “Write a one-line summary of the class in the class comment”. 19
  • 20. Coding style guidelines ■ Java: Oracle, Apache, Google ■ Python: Pep, Google, Numpy ■ Smalltalk: Smalltalk style guide, comment template ■ Ruby: RubyStyle 20 Oracle: https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html Numpy:https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard Smalltalk:http://sdmeta.gforge.inria.fr/FreeBooks/WithStyle/SmalltalkWithStyle.pdf
  • 21. 21 Pharo class comment template Smalltalk:http://sdmeta.gforge.inria.fr/FreeBooks/WithStyle/SmalltalkWithStyle.pdf
  • 22. Challenges ■ Missing comments ■ Inconsistent & Incomplete ■ Duplicate comments ■ Outdated comments ■ Takes time to write ■ Complex to understand 22 Impact overall quality of comments
  • 23. 23 We use different tools and techniques to analyze comment quality.
  • 24. Code analysis tools ■ Syntax ■ Semantics ■ Style 24 C de Te i g C a a i C di g e chec e S a ic a a i R i e Da a A a i IDE
  • 25. 25 But what about comments?
  • 26. Comment analysis tools ■ Syntax ■ Semantics ■ Style 26 Da a A a i C e Te i g C a a i C di g e chec e S a ic a a i R i e IDE
  • 27. Comment analysis tools ■ Syntax ■ Semantics ■ Style 27 Da a A a i C e Te i g C a a i C di g e chec e S a ic a a i R i e IDE Javadoc, pydoc C heckstyle, Pylint
  • 28. Documentation tools ■ Check syntax of comments ■ Do not check the content 28
  • 29. Coding style checkers ■ Java: Checkstyle, PMD ■ Python: pylint, pycodestyle ■ Smalltalk: No linter ■ Ruby: RuboCop 29
  • 30. Coding style checkers ■ Detect presence/absence of comments ■ Check whether comments follow style guidelines or not to some extent. ■ Limited to selected metrics (code/comment ratio) 30
  • 32. 32 Information types in Java code comments ■ Analyze code comments of big and diverse projects ■ Identified the information types using machine learning approaches.
  • 33. 33 Information types in Java code comments
  • 34. 34 Information types in Python code
  • 35. 35 Information types in Pharo code comments 1 1 2 3 4 3 5 4 8 10 11 21 29 34 33 43 40 51 57 75 134 231 256 0 50 100 150 200 250 300 License TODO comments Links Coding Guidelines Extensions Other Naming conventions Observations Subclasses explanation Recommendations Discourse ReferencesOtherResources Dependencies Contracts Key Messages Instance Variables Warnings Implementation Points Examples Class References Collaborators Responsibility Intent Number of classes Categories
  • 36. 36 Information types in Pharo code comments 1 1 2 3 4 3 5 4 8 10 11 21 29 34 33 43 40 51 57 75 134 231 256 0 50 100 150 200 250 300 License TODO comments Links Coding Guidelines Extensions Other Naming conventions Observations Subclasses explanation Recommendations Discourse ReferencesOtherResources Dependencies Contracts Key Messages Instance Variables Warnings Implementation Points Examples Class References Collaborators Responsibility Intent Number of classes Categories
  • 37. 37 Information types across Pharo projects
  • 38. 38 Class: FTTreeItem I am an abstract class to define an Item use by a tree data source of Fast table. Description ------------------------------------------------- I define the basics methods needed by a FTTreeDataSource. I use FTTreeItem to manage my elements and I am use by a FTFastTable. Public API and Key Messages ------------------------------------------------- • #data. anObject from: aFTTreeDataSource This is my constructor that is use by FTTreeDataSource and myself Example ------------------------------------------------- Should not be instanciate. Internal Representation and Key Implementation Points. ------------------------------------------------- Instance Variables dataSource: I am the dataSource that holds this Item. children: I am a collection of Items calculate by the item. I contains the chldren of the Item. Collected data
  • 39. 39 Class: FTTreeItem I am an abstract class to define an Item use by a tree data source of Fast table. Description ------------------------------------------------- I define the basics methods needed by a FTTreeDataSource. I use FTTreeItem to manage my elements and I am use by a FTFastTable. Public API and Key Messages ------------------------------------------------- • #data. anObject from: aFTTreeDataSource This is my constructor that is use by FTTreeDataSource and myself Example ------------------------------------------------- Should not be instanciate. Internal Representation and Key Implementation Points. ------------------------------------------------- Instance Variables dataSource: I am the dataSource that holds this Item. children: I am a collection of Items calculate by the item. I contains the chldren of the Item. Intent Responsibility Key Messages Warning Instance variables Collaborator Collected data
  • 41. 41 Class: FTTreeItem I am an abstract class to define an Item use by a tree data source of Fast table. Description ------------------------------------------------- I define the basics methods needed by a FTTreeDataSource. I use FTTreeItem to manage my elements and I am use by a FTFastTable. Public API and Key Messages ------------------------------------------------- • #data. anObject from: aFTTreeDataSource This is my constructor that is use by FTTreeDataSource and myself Example ------------------------------------------------- Should not be instanciate. Internal Representation and Key Implementation Points. ------------------------------------------------- Instance Variables dataSource: I am the dataSource that holds this Item. children: I am a collection of Items calculate by the item. I contains the chldren of the Item. Intent Responsibility Key Messages Warning Instance variables Collaborator Identification of patterns
  • 45. Comments do change over time 45 We need to understand their change behaviour.
  • 47. Java code comment co-evolution 47
  • 48. 48 Java code comment co-evolution Source: Analyzing the co-evolution of comments and source code, fig 1
  • 49. Java code comment co-evolution ■ Over 50% of the comment changes are related to source code changes ■ Newly added code gets barely commented 49
  • 50. Pharo class comment co-evolution 50
  • 53. Pharo class comment evolution 53
  • 54. ■ Over 50% of the comment changes are related to source code changes ■ Newly added code gets commented often 54 Pharo class comment co-evolution
  • 55. Not all comments need to be changed when the code is changed & vice versa 55 We need to identify such cases when a comment needs to be changed
  • 57. Code summaries 57 ■ “Automatically generated, short, yet accurate descriptions of source code entities”. ■ They give more information than just the header or the name of an artifact. ■ Significantly shorter and faster to read than the source code they summarise
  • 58. Example of natural language summaries 58 35 https://www.textcompactor.com/
  • 59. Example of natural language summaries 59 35 https://www.textcompactor.com/
  • 60. 60 Example of Natural Language Summaries MILAN, Italy, April 18. A small airplane crashed into a government building in heart of Milan, setting the top floors on fire, Italian police reported. There were no immediate reports on casualties as rescue workers attempted to clear the area in the city's financial district. Few details of the crash were available, but news reports about it immediately set off fears that it might be a terrorist act akin to the Sept. 11 attacks in the United States. Those fears sent U.S. stocks tumbling to session lows in late morning trading. Witnesses reported hearing a loud explosion from the 30-story office building, which houses the administrative offices of the local Lombardy region and sits next to the city's central train station. Italian state television said the crash put a hole in the 25th floor of the Pirelli building. News reports said smoke poured from the opening. Police and ambulances rushed to the building in downtown Milan. No further details were immediately available.
  • 61. 61 Example of natural language summaries MILAN, Italy, April 18. A small airplane crashed into a government building in heart of Milan, setting the top floors on fire, Italian police reported. There were no immediate reports on casualties as rescue workers attempted to clear the area in the city's financial district. Few details of the crash were available, but news reports about it immediately set off fears that it might be a terrorist act akin to the Sept. 11 attacks in the United States. Those fears sent U.S. stocks tumbling to session lows in late morning trading. Witnesses reported hearing a loud explosion from the 30-story office building, which houses the administrative offices of the local Lombardy region and sits next to the city's central train station. Italian state television said the crash put a hole in the 25th floor of the Pirelli building. News reports said smoke poured from the opening. Police and ambulances rushed to the building in downtown Milan. No further details were immediately available. How many victims? Was it a terrorist act? What was the target? What happened? Says who? When, where?
  • 66. Java class summaries ■ Identify the stereotypes. ■ Gather the heuristics ■ Generate the class summary 66
  • 67. Workflow 67 JSummarizer: An automatic generator of natural language summaries for Java classes by Moreno
  • 69. ■ Missing some information ■ Not easy to understand 69 Content adequacy vs. expressiveness
  • 70. To overcome these limitations… 70 Researchers proposed to detect source code descriptions from external sources: ■ Mailing list and issue trackers ■ StackOverflow discussions
  • 71. What information to include, how much, and how to generate and present it. 71
  • 75. 75 TAACO TAALES ARTE Linguistic analysis for English
  • 76. 76 Style analysis of Java comments ■ Metric-based methods ■ Comment too short, too long ■ Check documentable items (tags) of a code entity ■ Readability of the comments
  • 77. 77 Style analysis of Java comments ■ Metric-based method ■ Check whether comments are similar to method names
  • 78. Adjust the metrics and their thresholds according to comment. 78
  • 79. Future work ■ Evaluate if a comment is good or not ■ Detect the inconsistency in the comment ■ Propose refactoring of the comment, if required. 79