SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Inclusion Starts

With Docs
A talk about docs, Elixir, and user empathy
by Pete Gamache.
Presented at the first EMPEX LA conference,
10 November 2018.
Hello!
What is this?
• A short guide to getting the most out of Elixir's
built-in docs system, ExDoc
• A love letter to the authors of great docs
Some Ques7ons
• Do you want to have to fully understand someone
else's code in order to use it?
Some Ques7ons
• Do you trust the code of developers who could not or
would not describe it in plain English?
Some Ques7ons
• Do you want to restrict your audience to "geniuses"?
Some Ques7ons
• Do you want other people to fix and improve your
code, at no cost to you??
Name some great docs
Elixir Has Great Docs
• They look good
• Modules explain their purpose
• Functions explain their semantics
• Sample code everywhere
ExDoc Cheat Sheet
• Write your docs in Markdown, inline with your
source code
• Indent sample code four spaces from the rest
• Add ex_doc to your project dependencies in mix.exs
• mix docs generates HTML docs in doc/
• mix hex.publish docs publishes docs for a Hex
module to hexdocs.pm
Write Docs in Markdown
Moduledocs
• Explain the purpose of a module (or project)
• Sample code illustrates common usage
• Installation instructions
• In lesser languages, we'd use a README for this
TIP! Install Instruc7ons
• Scenario: you add a feature and increase the version
number of your project
• Oh no! You forget to change it in the @moduledoc,
so your docs are telling people to install an old
version
• Solution: variable interpolation in @moduledoc,
using ~s sigil (not ~S) and
#{MyApp.Mixfile.project[:version]}
Func7on Docs
• Provide the intent and specification for each
function
• ...So be specific! Esp. input and output types
• Sample code goes deeper than moduledoc
• Use @doc just before function definition
Doctests
• Problem: sample code in docs can go stale
• Elixir's solution: execute sample code as tests
• Rules are fairly simple: code starts with iex>, results
don't, no blank lines allowed
• Just put doctest MyApp.Modulename in one of your
test files
TIP! Doctests
• Always add doctest MyApp.Modulename to your
tests, even when you have no doctests
• Harmless with no doctests
• Avoids having unevaluated doctests later
• Also "good" for test coverage. Don't ask me why
Data Types
• String.starts_with?(string, prefix) is pretty clear already
• Many functions are not so lucky
• In languages with static typing, this is solved
automatically
• We're not using one of those languages, so we need to do
a tiny bit of work in order to ensure that a function's
input and output data types are obvious
• Elixir and Erlang's solution: Typespecs
Dialyzer
• Typespecs aren't only for docs
• Dialyzer is Erlang's "discrepancy analyzer"
• Add dialyxir to your mix.exs deps to use it in Elixir
• TL;DR you write typespecs, then run mix dialyzer,
then Erlang tells you if you were lying
Source Code
• Sometimes you just need to RTFS
• Usually not that hard to Google "<projectname>
github", plow into lib/, find the module in question,
grep for function name
• Come on, are you kidding me? What a PITA
• Elixir's solution: ExDoc supports Github repos
natively, via --source-url option
• ...And with a Mix task alias, automatically
Epilogue
We Have Great Docs
• Module's purpose is explained, with examples
• Functions are explained in depth, with examples
• These examples never go stale
• Dialyzer keeps us honest
• One-click access to source code
• And it all looks sharp
Read All About It!
• https://hexdocs.pm/ex_doc/readme.html
• https://hexdocs.pm/elixir/typespecs.html
• https://github.com/jeremyjh/dialyxir
Thanks!!
Pete Gamache
@gamache
pete@gamache.org

Contenu connexe

Tendances

Lecture 10 software development
Lecture 10 software developmentLecture 10 software development
Lecture 10 software development
Jehanzaib Yousuf
 

Tendances (20)

Zoo of domain-specific languages
Zoo of domain-specific languagesZoo of domain-specific languages
Zoo of domain-specific languages
 
Swift vs. Language X
Swift vs. Language XSwift vs. Language X
Swift vs. Language X
 
Code Generation in Perl
Code Generation in PerlCode Generation in Perl
Code Generation in Perl
 
JetBrains MPS
JetBrains MPSJetBrains MPS
JetBrains MPS
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
5 hs mpostcustomizationrenefonseca
5 hs mpostcustomizationrenefonseca5 hs mpostcustomizationrenefonseca
5 hs mpostcustomizationrenefonseca
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
Xtext beyond the defaults - how to tackle performance problems
Xtext beyond the defaults -  how to tackle performance problemsXtext beyond the defaults -  how to tackle performance problems
Xtext beyond the defaults - how to tackle performance problems
 
How does intellisense work?
How does intellisense work?How does intellisense work?
How does intellisense work?
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Lecture 10 software development
Lecture 10 software developmentLecture 10 software development
Lecture 10 software development
 
Haskell Tour (Part 1)
Haskell Tour (Part 1)Haskell Tour (Part 1)
Haskell Tour (Part 1)
 
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
 
DSL explained _
DSL explained _DSL explained _
DSL explained _
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
A great clash of symbols
A great clash of symbolsA great clash of symbols
A great clash of symbols
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and Fable
 

Similaire à EMPEX LA 2018 - Inclusion Starts with Docs

Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
Iván Montes
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 

Similaire à EMPEX LA 2018 - Inclusion Starts with Docs (20)

Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should CareJOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 
Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...
Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...
Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
Getting Started with the TypeScript Language
Getting Started with the TypeScript LanguageGetting Started with the TypeScript Language
Getting Started with the TypeScript Language
 
Like SpecFlow
Like SpecFlowLike SpecFlow
Like SpecFlow
 
l2-es6-160830040119.pdf
l2-es6-160830040119.pdfl2-es6-160830040119.pdf
l2-es6-160830040119.pdf
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Lecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 SlideLecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 Slide
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
presentation
presentationpresentation
presentation
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Dernier (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
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 🔝✔️✔️
 
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
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
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
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 

EMPEX LA 2018 - Inclusion Starts with Docs

  • 1. Inclusion Starts
 With Docs A talk about docs, Elixir, and user empathy by Pete Gamache. Presented at the first EMPEX LA conference, 10 November 2018.
  • 3. What is this? • A short guide to getting the most out of Elixir's built-in docs system, ExDoc • A love letter to the authors of great docs
  • 4. Some Ques7ons • Do you want to have to fully understand someone else's code in order to use it?
  • 5. Some Ques7ons • Do you trust the code of developers who could not or would not describe it in plain English?
  • 6. Some Ques7ons • Do you want to restrict your audience to "geniuses"?
  • 7. Some Ques7ons • Do you want other people to fix and improve your code, at no cost to you??
  • 9. Elixir Has Great Docs • They look good • Modules explain their purpose • Functions explain their semantics • Sample code everywhere
  • 10.
  • 11.
  • 12. ExDoc Cheat Sheet • Write your docs in Markdown, inline with your source code • Indent sample code four spaces from the rest • Add ex_doc to your project dependencies in mix.exs • mix docs generates HTML docs in doc/ • mix hex.publish docs publishes docs for a Hex module to hexdocs.pm
  • 13. Write Docs in Markdown
  • 14.
  • 15.
  • 16. Moduledocs • Explain the purpose of a module (or project) • Sample code illustrates common usage • Installation instructions • In lesser languages, we'd use a README for this
  • 17. TIP! Install Instruc7ons • Scenario: you add a feature and increase the version number of your project • Oh no! You forget to change it in the @moduledoc, so your docs are telling people to install an old version • Solution: variable interpolation in @moduledoc, using ~s sigil (not ~S) and #{MyApp.Mixfile.project[:version]}
  • 18.
  • 19. Func7on Docs • Provide the intent and specification for each function • ...So be specific! Esp. input and output types • Sample code goes deeper than moduledoc • Use @doc just before function definition
  • 20.
  • 21. Doctests • Problem: sample code in docs can go stale • Elixir's solution: execute sample code as tests • Rules are fairly simple: code starts with iex>, results don't, no blank lines allowed • Just put doctest MyApp.Modulename in one of your test files
  • 22. TIP! Doctests • Always add doctest MyApp.Modulename to your tests, even when you have no doctests • Harmless with no doctests • Avoids having unevaluated doctests later • Also "good" for test coverage. Don't ask me why
  • 23. Data Types • String.starts_with?(string, prefix) is pretty clear already • Many functions are not so lucky • In languages with static typing, this is solved automatically • We're not using one of those languages, so we need to do a tiny bit of work in order to ensure that a function's input and output data types are obvious • Elixir and Erlang's solution: Typespecs
  • 24.
  • 25.
  • 26. Dialyzer • Typespecs aren't only for docs • Dialyzer is Erlang's "discrepancy analyzer" • Add dialyxir to your mix.exs deps to use it in Elixir • TL;DR you write typespecs, then run mix dialyzer, then Erlang tells you if you were lying
  • 27. Source Code • Sometimes you just need to RTFS • Usually not that hard to Google "<projectname> github", plow into lib/, find the module in question, grep for function name • Come on, are you kidding me? What a PITA • Elixir's solution: ExDoc supports Github repos natively, via --source-url option • ...And with a Mix task alias, automatically
  • 28.
  • 29.
  • 30.
  • 32. We Have Great Docs • Module's purpose is explained, with examples • Functions are explained in depth, with examples • These examples never go stale • Dialyzer keeps us honest • One-click access to source code • And it all looks sharp
  • 33. Read All About It! • https://hexdocs.pm/ex_doc/readme.html • https://hexdocs.pm/elixir/typespecs.html • https://github.com/jeremyjh/dialyxir