SlideShare a Scribd company logo
1 of 30
Dutch Perl Workshop 2016
Documenting Code
Patterns and Anti-patterns
Søren Lund (slu)
slu@369.dk
Content of This Talk
 Introduction
 About Me
 Documentation
 What Documentation Do We Need?
 Comments in Code
 Comment Patterns
 Comment Anti-Patterns
Inspiration Strikes
 During a code review I saw a comment
 The comment tried to document the code,
which was not easy to understand
 I suggested refactoring the code, thus
eliminating the need of the comment.
 The developer agreed and did the refactoring
 I got inspiration for this talk
Rewriting the Title of the Talk
 First title was
“Please don't comment your Perl code”
 I found it too negative, so I changed it to
“Don't comment code, document it”
 Still starting of negative, so I came up with
“Documenting Code, Patterns and Anti-
patterns”
 I.e. writing (coding) is hard; and you need to
constantly rewrite (refactor).
This Talk is for Developers
 It's about documenting code
 How to make it easier for the (next) developer
About Me
 I'm a freelance consultant
 Web Development, later years mainly Back-End
 Build & Release Mgnt, Testing & CI, DevOps
 Professional developer for more than 20 years
 Programmed in Perl for almost as long
 Generalist, work with everything from
infrastructure to front-end-development
 I enjoy writing (the right) documentation
Documentation
The Problem with Documentation
 Documentation must be in sync with the code
 It's extra work. Often missed/skipped.
 Minimize the amount of documentation, will
results in less work
 Write code that is self-explanatory
 We'll still need some documentation
Self-Explanatory Code
 Meaningful naming is important
 Short subs
 Minimize block level
 A module/sub should do only one thing
 Don't be afraid of one-liner subs
 Comments are rarely/never needed
Ensuring Self-Explanatory Code 1
 Create Tests (which is a form of
documentation)
 Unit Tests (prove)
 Function/Integration Tests (JMeter, Postman,
Selenium)
 When you create tests, you mindset changes
 You'll be using your own code
 Remember to run test daily in CI (Jenkins)
Ensuring Self-Explanatory Code 2
 Peer Review (Crucible, Gerrit, PRs)
 Remember to review tests and documentation
 An effective way to knowledge share
(eliminating the need for documentation
somewhat)
 Project of the Month/Sprint
 Review/clean-up/elimination of technical debt
Do the damn peer reviews!
“… software testing alone has limited
effectiveness — the average defect detection
rate is only 25 percent for unit testing, 35
percent for function testing, and 45 percent for
integration testing. In contrast, the average
effectiveness of design and code inspections
are 55 and 60 percent”
—Steve McConnell, Code Complete
What Documentation Do We Need?
The README file
 Placed in the top level directory of the code
 This is what e.g. CPAN and GitHub wants
 Content should include
 Short description incl. copyright information
 How to build/install
 Links to issue tracker, wiki, etc.
The Issue Tracker
 JIRA, Redmine, Bugzilla, Trac, GitHub...
 Use it to
 document known bugs
 describe wishes (coming features)
 prioritize what to do next
 Should support your development process
A Wiki
 Confluence, Redmine, Trac, GitHub…
 Use it to
 write Technical Notes
 communicate ideas (drafts of e.g. APIs)
 maintain a FAQ, knowledge base, etc.
 write User Documentation (not always an option)
Specific Documents We Need
 Architectural Notes (hows and whys)
 Code Style Guidelines (maybe just point to
http://perldoc.perl.org/perlstyle.html)
 Server/Deployment diagram (simplified)
 E/R Diagram (auto generated, SchemaSpy)
 Should all be (available) in the Wiki
 Note: Customer/Company might require you to
write other documentation.
Comments in Code
Don't Comment Code
 “The proper use of comments is to compensate
for our failure to express ourself in code.” –
Robert C. Martin, Clean Code: A Handbook of
Agile Software Craftmanship
 You should fix the code by refactoring it, not by
commenting it
 But comments can be used for good
 I.e. there are patterns and anti-patterns
Comment Patterns
File Header
 Comments at the top of (each) source file
 Can contain a short description and/or
 include copyright information (which should be
auto inserted)
 The README file might suffice
 Mainly useful for procedural scripts
Why-And
 Used when you're adding Technical Debt
 The code might not be self-explanatory
 Document why you had to do it and how to
eliminate it
 The next developer wont think badly about you
Helpful Links
 Use when implementing an algorithm or very
specific requirement
 Insert a link or reference
 Example:
# Calculate PI using Bellard's formula
# See http://en.wikipedia.org/wiki/Bellard%27s_formula
Public APIs
 Used when creating a (CPAN) module/script
that's used by others
 Use POD markup
(http://perldoc.perl.org/perlpod.html)
 This is documentation, which needs to be in
sync with the code
 it's close to the code, thus a little easier to keep it in
sync
Comment Anti-Patterns
Stating the Obvious
 Example:
# initialize counter
$count = 0;
 Problem: It's just noise
 Solution: Just remove the comment
Refactoring in Comments
 Example:
# n is number of files
my $n;
 Problem: You spotted an issue, but didn't fix it
 Refactor, example:
my $number_of_files;
Issue Tracking
 Example:
# TODO: will crash if configuration file is empty
 Called Source Code Task Tags (variants:
FIXME and XXX)
 Create corresponding issues in Issue Tracker
 And perhaps convert to Why-And comment
Disabling Code
 Example:
# say “count = $count”
 Problem: it's old/unused code
 remove it (if it's not needed anymore)
 commit to a branch (it you might need it)
 and remove it from mainline
 put it behind a feature/debug flag
The End
 Write self-explanatory code with tests
 Do formal peer reviews
 Eliminate the comments
 Maintain a minimal set of documentation
 Any Questions?

More Related Content

What's hot

FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09Pyxis Technologies
 
Topic production code
Topic production codeTopic production code
Topic production codeKavi Kumar
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelinesLalit Kale
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptMark Daggett
 
A Brief Introduction to Zend_Form
A Brief Introduction to Zend_FormA Brief Introduction to Zend_Form
A Brief Introduction to Zend_FormJeremy Kendall
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 
Code Review tool for personal effectiveness and waste analysis
Code Review tool for personal effectiveness and waste analysisCode Review tool for personal effectiveness and waste analysis
Code Review tool for personal effectiveness and waste analysisMikalai Alimenkou
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Aditya Bhuyan
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...VincitOy
 
Git branching policy and review comment's prefix
Git branching policy and review comment's prefixGit branching policy and review comment's prefix
Git branching policy and review comment's prefixKumaresh Chandra Baruri
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentEffective
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentEffectiveUI
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentJohn Blanco
 
Code review in practice
Code review in practiceCode review in practice
Code review in practiceEdorian
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 

What's hot (20)

FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09
 
Code Review
Code ReviewCode Review
Code Review
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelines
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScript
 
A Brief Introduction to Zend_Form
A Brief Introduction to Zend_FormA Brief Introduction to Zend_Form
A Brief Introduction to Zend_Form
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Code Review tool for personal effectiveness and waste analysis
Code Review tool for personal effectiveness and waste analysisCode Review tool for personal effectiveness and waste analysis
Code Review tool for personal effectiveness and waste analysis
 
Code Quality
Code QualityCode Quality
Code Quality
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)
 
Debugging C# Applications
Debugging C# ApplicationsDebugging C# Applications
Debugging C# Applications
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
 
Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
Git branching policy and review comment's prefix
Git branching policy and review comment's prefixGit branching policy and review comment's prefix
Git branching policy and review comment's prefix
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
 
Let's Explore C# 6
Let's Explore C# 6Let's Explore C# 6
Let's Explore C# 6
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 

Viewers also liked

Playing with Hadoop 2013-10-31
Playing with Hadoop 2013-10-31Playing with Hadoop 2013-10-31
Playing with Hadoop 2013-10-31Søren Lund
 
hello
hellohello
hellomojir
 
Apache JMeter Introduction
Apache JMeter IntroductionApache JMeter Introduction
Apache JMeter IntroductionSøren Lund
 
E-books and App::Pod2Epub
E-books and App::Pod2EpubE-books and App::Pod2Epub
E-books and App::Pod2EpubSøren Lund
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with seleniumSøren Lund
 
E2 meetup paris 16 0 ct-2013
E2 meetup paris 16 0 ct-2013E2 meetup paris 16 0 ct-2013
E2 meetup paris 16 0 ct-2013Jane McConnell
 

Viewers also liked (6)

Playing with Hadoop 2013-10-31
Playing with Hadoop 2013-10-31Playing with Hadoop 2013-10-31
Playing with Hadoop 2013-10-31
 
hello
hellohello
hello
 
Apache JMeter Introduction
Apache JMeter IntroductionApache JMeter Introduction
Apache JMeter Introduction
 
E-books and App::Pod2Epub
E-books and App::Pod2EpubE-books and App::Pod2Epub
E-books and App::Pod2Epub
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
E2 meetup paris 16 0 ct-2013
E2 meetup paris 16 0 ct-2013E2 meetup paris 16 0 ct-2013
E2 meetup paris 16 0 ct-2013
 

Similar to Documenting Code - Patterns and Anti-patterns - NLPW 2016

Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
APIs And SDKs  Breaking Into And Succeeding In A Specialty MarketAPIs And SDKs  Breaking Into And Succeeding In A Specialty Market
APIs And SDKs Breaking Into And Succeeding In A Specialty MarketBill Dubie
 
Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Siddhesh Bhobe
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovSvetlin Nakov
 
Agile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingAgile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingUtkarsh Khare
 
Code review best practice
Code review best practiceCode review best practice
Code review best practiceOren Digmi
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.DrupalCampDN
 
TDD - Cultivating a Beginner's Mind
TDD -  Cultivating a Beginner's MindTDD -  Cultivating a Beginner's Mind
TDD - Cultivating a Beginner's MindShai Yallin
 
Class 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurshipClass 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurshipallanchao
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiarMatiar Rahman
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development EnvironmentsShahar Evron
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationBlue Elephant Consulting
 
Interactive Development Environments
Interactive Development EnvironmentsInteractive Development Environments
Interactive Development EnvironmentsPhilip Johnson
 
API Workshop: Deep dive into code samples
API Workshop: Deep dive into code samplesAPI Workshop: Deep dive into code samples
API Workshop: Deep dive into code samplesTom Johnson
 
The OpenOffice.org specification process demystified
The OpenOffice.org specification process demystifiedThe OpenOffice.org specification process demystified
The OpenOffice.org specification process demystifiedAlexandro Colorado
 

Similar to Documenting Code - Patterns and Anti-patterns - NLPW 2016 (20)

Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
APIs And SDKs  Breaking Into And Succeeding In A Specialty MarketAPIs And SDKs  Breaking Into And Succeeding In A Specialty Market
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
 
Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin Nakov
 
Agile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingAgile Methodologies And Extreme Programming
Agile Methodologies And Extreme Programming
 
Code review best practice
Code review best practiceCode review best practice
Code review best practice
 
Unit iv
Unit ivUnit iv
Unit iv
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.
 
Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)
 
TDD - Cultivating a Beginner's Mind
TDD -  Cultivating a Beginner's MindTDD -  Cultivating a Beginner's Mind
TDD - Cultivating a Beginner's Mind
 
Class 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurshipClass 6: Introduction to web technology entrepreneurship
Class 6: Introduction to web technology entrepreneurship
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiar
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development Environments
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 
Ensuring code quality
Ensuring code qualityEnsuring code quality
Ensuring code quality
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
 
Interactive Development Environments
Interactive Development EnvironmentsInteractive Development Environments
Interactive Development Environments
 
API Workshop: Deep dive into code samples
API Workshop: Deep dive into code samplesAPI Workshop: Deep dive into code samples
API Workshop: Deep dive into code samples
 
The OpenOffice.org specification process demystified
The OpenOffice.org specification process demystifiedThe OpenOffice.org specification process demystified
The OpenOffice.org specification process demystified
 
Testing and symfony2
Testing and symfony2Testing and symfony2
Testing and symfony2
 

Recently uploaded

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
 
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
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
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
 

Recently uploaded (20)

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 ...
 
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...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
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
 

Documenting Code - Patterns and Anti-patterns - NLPW 2016

  • 1. Dutch Perl Workshop 2016 Documenting Code Patterns and Anti-patterns Søren Lund (slu) slu@369.dk
  • 2. Content of This Talk  Introduction  About Me  Documentation  What Documentation Do We Need?  Comments in Code  Comment Patterns  Comment Anti-Patterns
  • 3. Inspiration Strikes  During a code review I saw a comment  The comment tried to document the code, which was not easy to understand  I suggested refactoring the code, thus eliminating the need of the comment.  The developer agreed and did the refactoring  I got inspiration for this talk
  • 4. Rewriting the Title of the Talk  First title was “Please don't comment your Perl code”  I found it too negative, so I changed it to “Don't comment code, document it”  Still starting of negative, so I came up with “Documenting Code, Patterns and Anti- patterns”  I.e. writing (coding) is hard; and you need to constantly rewrite (refactor).
  • 5. This Talk is for Developers  It's about documenting code  How to make it easier for the (next) developer
  • 6. About Me  I'm a freelance consultant  Web Development, later years mainly Back-End  Build & Release Mgnt, Testing & CI, DevOps  Professional developer for more than 20 years  Programmed in Perl for almost as long  Generalist, work with everything from infrastructure to front-end-development  I enjoy writing (the right) documentation
  • 8. The Problem with Documentation  Documentation must be in sync with the code  It's extra work. Often missed/skipped.  Minimize the amount of documentation, will results in less work  Write code that is self-explanatory  We'll still need some documentation
  • 9. Self-Explanatory Code  Meaningful naming is important  Short subs  Minimize block level  A module/sub should do only one thing  Don't be afraid of one-liner subs  Comments are rarely/never needed
  • 10. Ensuring Self-Explanatory Code 1  Create Tests (which is a form of documentation)  Unit Tests (prove)  Function/Integration Tests (JMeter, Postman, Selenium)  When you create tests, you mindset changes  You'll be using your own code  Remember to run test daily in CI (Jenkins)
  • 11. Ensuring Self-Explanatory Code 2  Peer Review (Crucible, Gerrit, PRs)  Remember to review tests and documentation  An effective way to knowledge share (eliminating the need for documentation somewhat)  Project of the Month/Sprint  Review/clean-up/elimination of technical debt
  • 12. Do the damn peer reviews! “… software testing alone has limited effectiveness — the average defect detection rate is only 25 percent for unit testing, 35 percent for function testing, and 45 percent for integration testing. In contrast, the average effectiveness of design and code inspections are 55 and 60 percent” —Steve McConnell, Code Complete
  • 14. The README file  Placed in the top level directory of the code  This is what e.g. CPAN and GitHub wants  Content should include  Short description incl. copyright information  How to build/install  Links to issue tracker, wiki, etc.
  • 15. The Issue Tracker  JIRA, Redmine, Bugzilla, Trac, GitHub...  Use it to  document known bugs  describe wishes (coming features)  prioritize what to do next  Should support your development process
  • 16. A Wiki  Confluence, Redmine, Trac, GitHub…  Use it to  write Technical Notes  communicate ideas (drafts of e.g. APIs)  maintain a FAQ, knowledge base, etc.  write User Documentation (not always an option)
  • 17. Specific Documents We Need  Architectural Notes (hows and whys)  Code Style Guidelines (maybe just point to http://perldoc.perl.org/perlstyle.html)  Server/Deployment diagram (simplified)  E/R Diagram (auto generated, SchemaSpy)  Should all be (available) in the Wiki  Note: Customer/Company might require you to write other documentation.
  • 19. Don't Comment Code  “The proper use of comments is to compensate for our failure to express ourself in code.” – Robert C. Martin, Clean Code: A Handbook of Agile Software Craftmanship  You should fix the code by refactoring it, not by commenting it  But comments can be used for good  I.e. there are patterns and anti-patterns
  • 21. File Header  Comments at the top of (each) source file  Can contain a short description and/or  include copyright information (which should be auto inserted)  The README file might suffice  Mainly useful for procedural scripts
  • 22. Why-And  Used when you're adding Technical Debt  The code might not be self-explanatory  Document why you had to do it and how to eliminate it  The next developer wont think badly about you
  • 23. Helpful Links  Use when implementing an algorithm or very specific requirement  Insert a link or reference  Example: # Calculate PI using Bellard's formula # See http://en.wikipedia.org/wiki/Bellard%27s_formula
  • 24. Public APIs  Used when creating a (CPAN) module/script that's used by others  Use POD markup (http://perldoc.perl.org/perlpod.html)  This is documentation, which needs to be in sync with the code  it's close to the code, thus a little easier to keep it in sync
  • 26. Stating the Obvious  Example: # initialize counter $count = 0;  Problem: It's just noise  Solution: Just remove the comment
  • 27. Refactoring in Comments  Example: # n is number of files my $n;  Problem: You spotted an issue, but didn't fix it  Refactor, example: my $number_of_files;
  • 28. Issue Tracking  Example: # TODO: will crash if configuration file is empty  Called Source Code Task Tags (variants: FIXME and XXX)  Create corresponding issues in Issue Tracker  And perhaps convert to Why-And comment
  • 29. Disabling Code  Example: # say “count = $count”  Problem: it's old/unused code  remove it (if it's not needed anymore)  commit to a branch (it you might need it)  and remove it from mainline  put it behind a feature/debug flag
  • 30. The End  Write self-explanatory code with tests  Do formal peer reviews  Eliminate the comments  Maintain a minimal set of documentation  Any Questions?