SlideShare ist ein Scribd-Unternehmen logo
1 von 120
Downloaden Sie, um offline zu lesen
Why you should
document you code!
Lennon Manchester
@leManchester
lennon.manchester@staunchrobots.com
DOCUMENTATION
Let’s start since the
beginning....
Documentation?
Documentation a set of documents
provided on paper, or online, or on digital or
analog media
Documentation?
Documentation a set of documents
provided on paper, or online, or on digital or
analog media
Document?
Document from Latin documentum
"example, proof, lesson," in M.L. "official
written instrument" any means, especially
graphic, proving the existence of a fact, the
accuracy or truth of a statement etc..
CRY!!!
Leonardo
@shivamib
Loren Segal
@lsegal
http://yardoc.org/
Legacy
2.0?
What is a
Legacy?
Why nobody likes to
work with
Legacy CODE?
Is it HARD?
Is it complex?
Is it complex?
Makes no sense?
CAOS?
.... Ahh ok,
did I say does NOT
have
Documentation?
Agile
Methods
All inspired by
the Agile values...
Responding to change
over following a plan
Individuals and interactions
over processes and tools
Working software over
Customer collaboration over
contract negotiation
write any kind of documentation
Responding to change
over following a plan
Individuals and interactions
over processes and tools
Working software over
Customer collaboration over
contract negotiation
write any kind of documentation
Responding to change
over following a plan
Individuals and interactions
over processes and tools
Working software over
Customer collaboration over
contract negotiation
write any kind of documentationcomprehensive documentation
...everyone pay
Attention!
When the class is good....
When the class is good....
README DRIVEN
DEVELOPMENT
WriteME DRIVEN
DEVELOPMENT
CRY!!!
Overhead of
thoughts
Motivation
Hands On
Write it
It s your
guide
CODE DOCUMENTATION
Contract
Contract
Kent
Beck
Kent
Beck
• Communication
• Simplicity
• Flexibility
Programs are read much more often
than written and therefore should
communicate clearly their intent.
Code is primarily means of
communication.
(For a typical enterprise system, a lot of
code will be modified by many
programmers over 5 – 15 years and
they’ll all need to understand it.)
Communication
ELEMENTS
of a
GOOD Doc
- Describe the behaviour (method or class).
ELEMENTS
of a
GOOD Doc
- Describe the behaviour (method or class).
- Avoid the first person ('We', 'I', 'You' is okay?!).
ELEMENTS
of a
GOOD Doc
- Describe the behaviour (method or class).
- Avoid the first person ('We', 'I', 'You' is okay?!).
- The first sentence should summarize the method/class
ELEMENTS
of a
GOOD Doc
- Describe the behaviour (method or class).
- Avoid the first person ('We', 'I', 'You' is okay?!).
- The first sentence should summarize the method/class
- Use note (@note) to say something the user
should know about it.
ELEMENTS
of a
GOOD Doc
- Describe the behaviour (method or class).
- Avoid the first person ('We', 'I', 'You' is okay?!).
- The first sentence should summarize the method/class
- Use note (@note) to say something the user
should know about it.
- References (classes, methods, URLs, @see).
ELEMENTS
of a
GOOD Doc
- List of Parameters and expected returns types.
- Describe the behaviour (method or class).
- Avoid the first person ('We', 'I', 'You' is okay?!).
- The first sentence should summarize the method/class
- Use note (@note) to say something the user
should know about it.
- References (classes, methods, URLs, @see).
ELEMENTS
of a
GOOD Doc
does not tell you
A viarablethe all history....name
def find(name)
does not tell you
A viarablethe all history....name
def find(name)
String? “John”
does not tell you
A viarablethe all history....name
def find(name)
String? “John”
Symbol? :John
does not tell you
A viarablethe all history....name
def find(name)
String? “John”
Hash? { :first => “John”, :last => “Lennon” }
Symbol? :John
does not tell you
A viarablethe all history....name
ocumentation
riven
evelopment
D
D
D
Write Docs
for a Method
Write a
Method
Validate Code
with Docs
Write Docs
for a Method
Write a
Method
Validate Code
with Docs
Write Docs
for a Method
Write a
Method
Validate Code
with Docs
class OS
# Returns a list of String and
# numbers displaying CPU information
# of an OS: the CPU type, architecture, vendor
# clock speed (as integer), temperature (as
# integer) and voltage (as integer)
def processor_info
[ cpu_type, cpu_arch, cpu_vendor, cpu_clock,
cpu_temp, cpu_voltage ]
end
end
Yardhttp://yardoc.org/
class OS
# @return [Array(String, String, String, Integer, Integer, Integer)]
# CPU type, architecture, vendor, clock speed, temp and voltage of an OS
def processor_info
[ cpu_type, cpu_arch, cpu_vendor, cpu_clock,
cpu_temp, cpu_voltage ]
end
end
Hash?
class OS
def processor_info
{ :cpu_type => cpu_type,
:cpu_arch => cpu_arch,
:cpu_vendor => cpu_vendor,
:cpu_clock => cpu_clock,
:cpu_temp => cpu_temp,
:cpu_voltage => cpu_voltage }
end
end
Hash?
class OS
# @return [Hash{Symbol=>[String, Integer]}]
# processor info filled into fields :cpu_type, :cpu_arch, :cpu_vendor,
# :cpu_clock (Integer), :cpu_temp (Integer), :cpu_voltage (Integer)
# representing proc values of a CPU
def processor_info
{ :cpu_type => cpu_type,
:cpu_arch => cpu_arch,
:cpu_vendor => cpu_vendor,
:cpu_clock => cpu_clock,
:cpu_temp => cpu_temp,
:cpu_voltage => cpu_voltage }
end
end
STOP
class OS
# @return [Hash{Symbol=>[String, Integer]}]
# processor info filled into fields :cpu_type, :cpu_arch, :cpu_vendor,
# :cpu_clock (Integer), :cpu_temp (Integer), :cpu_voltage (Integer)
# representing proc values of a CPU
def processor_info
{ :cpu_type => cpu_type,
:cpu_arch => cpu_arch,
:cpu_vendor => cpu_vendor,
:cpu_clock => cpu_clock,
:cpu_temp => cpu_temp,
:cpu_voltage => cpu_voltage }
end
end
class ProcessorInfo
# @return [String] CPU type (AMD, Intel, ...)
attr_accessor :cpu_type
# @return [String] CPU Architeture (x86,ARM)
attr_accessor :cpu_arch
# @return [String] CPU speed in hz (3.4.ghz = 3400)
attr_accessor :cpu_clock
end
class OS
# @return [ProcessorInfo] proc info of current OS
def processor_info
ProcessorInfo.new.tap do |p|
p.cpu_type, p.cpu_arch, p.cpu_ clock = cpu_type, cpu_arch, cpu_clock
end
end
end
Why should
you
document
your code?
- Contribute with your code;
- Improve your experience;
- Think about you and the next;
Does it make
sense?
because is like
Bad Sex...
because is like
Bad Sex...
...still being better
than nothing....
References
Loren Segal - Just Say No To :nodoc: and DocumentYour Code!
http://www.youtube.com/watch?v=tCw7CpRvYOE
Maurício Aniche at QCon SP (2012):
Métodos ágeis: o que é folclore e o que é real?
Krzysztof, Stig, and Jakub - Programming like Kent Beck
http://blog.iterate.no/2012/06/20/programming-like-kent-beck/
Tom Preston-Werner
http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
Jef Raskin
Comments are More Important than Code
Images collected from Google Images®
Lennon Manchester
lennon.manchester@staunchrobots.com
Thank You
Questions?
Lennon Manchester
@leManchester lennon.manchester@staunchrobots.com

Weitere ähnliche Inhalte

Ähnlich wie Why you should document your code

lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptSourabhPal46
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptMard Geer
 
Types and Immutability: why you should care
Types and Immutability: why you should careTypes and Immutability: why you should care
Types and Immutability: why you should careJean Carlo Emer
 
Types Working for You, Not Against You
Types Working for You, Not Against YouTypes Working for You, Not Against You
Types Working for You, Not Against YouC4Media
 
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...GeeksLab Odessa
 
Java for android developers
Java for android developersJava for android developers
Java for android developersAly Abdelkareem
 
Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!FRANKLINODURO
 
Creating a dataset of peer review in computer science conferences published b...
Creating a dataset of peer review in computer science conferences published b...Creating a dataset of peer review in computer science conferences published b...
Creating a dataset of peer review in computer science conferences published b...Aliaksandr Birukou
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Codemotion
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpg_hemanth17
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Sachin Singh
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpRaga Vahini
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpSatish Verma
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpsinghadarsh
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharpMody Farouk
 
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and Vocabularies
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and VocabulariesHaystack 2018 - Algorithmic Extraction of Keywords Concepts and Vocabularies
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and VocabulariesMax Irwin
 

Ähnlich wie Why you should document your code (20)

lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
Types and Immutability: why you should care
Types and Immutability: why you should careTypes and Immutability: why you should care
Types and Immutability: why you should care
 
Types Working for You, Not Against You
Types Working for You, Not Against YouTypes Working for You, Not Against You
Types Working for You, Not Against You
 
R tutorial
R tutorialR tutorial
R tutorial
 
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!
 
Creating a dataset of peer review in computer science conferences published b...
Creating a dataset of peer review in computer science conferences published b...Creating a dataset of peer review in computer science conferences published b...
Creating a dataset of peer review in computer science conferences published b...
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
 
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and Vocabularies
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and VocabulariesHaystack 2018 - Algorithmic Extraction of Keywords Concepts and Vocabularies
Haystack 2018 - Algorithmic Extraction of Keywords Concepts and Vocabularies
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Why you should document your code

  • 1. Why you should document you code! Lennon Manchester @leManchester lennon.manchester@staunchrobots.com
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Let’s start since the beginning....
  • 12.
  • 13. Documentation? Documentation a set of documents provided on paper, or online, or on digital or analog media
  • 14. Documentation? Documentation a set of documents provided on paper, or online, or on digital or analog media Document? Document from Latin documentum "example, proof, lesson," in M.L. "official written instrument" any means, especially graphic, proving the existence of a fact, the accuracy or truth of a statement etc..
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 29. Why nobody likes to work with Legacy CODE?
  • 34. CAOS?
  • 35. .... Ahh ok, did I say does NOT have Documentation?
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. All inspired by the Agile values...
  • 49. Responding to change over following a plan Individuals and interactions over processes and tools Working software over Customer collaboration over contract negotiation write any kind of documentation
  • 50. Responding to change over following a plan Individuals and interactions over processes and tools Working software over Customer collaboration over contract negotiation write any kind of documentation
  • 51. Responding to change over following a plan Individuals and interactions over processes and tools Working software over Customer collaboration over contract negotiation write any kind of documentationcomprehensive documentation
  • 53. When the class is good....
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 69.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 83. Programs are read much more often than written and therefore should communicate clearly their intent. Code is primarily means of communication. (For a typical enterprise system, a lot of code will be modified by many programmers over 5 – 15 years and they’ll all need to understand it.) Communication
  • 84.
  • 86. - Describe the behaviour (method or class). ELEMENTS of a GOOD Doc
  • 87. - Describe the behaviour (method or class). - Avoid the first person ('We', 'I', 'You' is okay?!). ELEMENTS of a GOOD Doc
  • 88. - Describe the behaviour (method or class). - Avoid the first person ('We', 'I', 'You' is okay?!). - The first sentence should summarize the method/class ELEMENTS of a GOOD Doc
  • 89. - Describe the behaviour (method or class). - Avoid the first person ('We', 'I', 'You' is okay?!). - The first sentence should summarize the method/class - Use note (@note) to say something the user should know about it. ELEMENTS of a GOOD Doc
  • 90. - Describe the behaviour (method or class). - Avoid the first person ('We', 'I', 'You' is okay?!). - The first sentence should summarize the method/class - Use note (@note) to say something the user should know about it. - References (classes, methods, URLs, @see). ELEMENTS of a GOOD Doc
  • 91. - List of Parameters and expected returns types. - Describe the behaviour (method or class). - Avoid the first person ('We', 'I', 'You' is okay?!). - The first sentence should summarize the method/class - Use note (@note) to say something the user should know about it. - References (classes, methods, URLs, @see). ELEMENTS of a GOOD Doc
  • 92.
  • 93. does not tell you A viarablethe all history....name
  • 94. def find(name) does not tell you A viarablethe all history....name
  • 95. def find(name) String? “John” does not tell you A viarablethe all history....name
  • 96. def find(name) String? “John” Symbol? :John does not tell you A viarablethe all history....name
  • 97. def find(name) String? “John” Hash? { :first => “John”, :last => “Lennon” } Symbol? :John does not tell you A viarablethe all history....name
  • 99. Write Docs for a Method Write a Method Validate Code with Docs
  • 100. Write Docs for a Method Write a Method Validate Code with Docs Write Docs for a Method Write a Method Validate Code with Docs
  • 101.
  • 102. class OS # Returns a list of String and # numbers displaying CPU information # of an OS: the CPU type, architecture, vendor # clock speed (as integer), temperature (as # integer) and voltage (as integer) def processor_info [ cpu_type, cpu_arch, cpu_vendor, cpu_clock, cpu_temp, cpu_voltage ] end end
  • 104.
  • 105. class OS # @return [Array(String, String, String, Integer, Integer, Integer)] # CPU type, architecture, vendor, clock speed, temp and voltage of an OS def processor_info [ cpu_type, cpu_arch, cpu_vendor, cpu_clock, cpu_temp, cpu_voltage ] end end
  • 106.
  • 107. Hash?
  • 108. class OS def processor_info { :cpu_type => cpu_type, :cpu_arch => cpu_arch, :cpu_vendor => cpu_vendor, :cpu_clock => cpu_clock, :cpu_temp => cpu_temp, :cpu_voltage => cpu_voltage } end end Hash?
  • 109. class OS # @return [Hash{Symbol=>[String, Integer]}] # processor info filled into fields :cpu_type, :cpu_arch, :cpu_vendor, # :cpu_clock (Integer), :cpu_temp (Integer), :cpu_voltage (Integer) # representing proc values of a CPU def processor_info { :cpu_type => cpu_type, :cpu_arch => cpu_arch, :cpu_vendor => cpu_vendor, :cpu_clock => cpu_clock, :cpu_temp => cpu_temp, :cpu_voltage => cpu_voltage } end end
  • 110. STOP
  • 111.
  • 112. class OS # @return [Hash{Symbol=>[String, Integer]}] # processor info filled into fields :cpu_type, :cpu_arch, :cpu_vendor, # :cpu_clock (Integer), :cpu_temp (Integer), :cpu_voltage (Integer) # representing proc values of a CPU def processor_info { :cpu_type => cpu_type, :cpu_arch => cpu_arch, :cpu_vendor => cpu_vendor, :cpu_clock => cpu_clock, :cpu_temp => cpu_temp, :cpu_voltage => cpu_voltage } end end
  • 113. class ProcessorInfo # @return [String] CPU type (AMD, Intel, ...) attr_accessor :cpu_type # @return [String] CPU Architeture (x86,ARM) attr_accessor :cpu_arch # @return [String] CPU speed in hz (3.4.ghz = 3400) attr_accessor :cpu_clock end class OS # @return [ProcessorInfo] proc info of current OS def processor_info ProcessorInfo.new.tap do |p| p.cpu_type, p.cpu_arch, p.cpu_ clock = cpu_type, cpu_arch, cpu_clock end end end
  • 115. - Contribute with your code; - Improve your experience; - Think about you and the next;
  • 118. because is like Bad Sex... ...still being better than nothing....
  • 119. References Loren Segal - Just Say No To :nodoc: and DocumentYour Code! http://www.youtube.com/watch?v=tCw7CpRvYOE Maurício Aniche at QCon SP (2012): Métodos ágeis: o que é folclore e o que é real? Krzysztof, Stig, and Jakub - Programming like Kent Beck http://blog.iterate.no/2012/06/20/programming-like-kent-beck/ Tom Preston-Werner http://tom.preston-werner.com/2010/08/23/readme-driven-development.html Jef Raskin Comments are More Important than Code Images collected from Google Images®
  • 120. Lennon Manchester lennon.manchester@staunchrobots.com Thank You Questions? Lennon Manchester @leManchester lennon.manchester@staunchrobots.com