SlideShare a Scribd company logo
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
EMPEX LA 2018 - Inclusion Starts with Docs
EMPEX LA 2018 - Inclusion Starts with Docs
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
EMPEX LA 2018 - Inclusion Starts with Docs
EMPEX LA 2018 - Inclusion Starts with Docs
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]}
EMPEX LA 2018 - Inclusion Starts with Docs
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
EMPEX LA 2018 - Inclusion Starts with Docs
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
EMPEX LA 2018 - Inclusion Starts with Docs
EMPEX LA 2018 - Inclusion Starts with Docs
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
EMPEX LA 2018 - Inclusion Starts with Docs
EMPEX LA 2018 - Inclusion Starts with Docs
EMPEX LA 2018 - Inclusion Starts with Docs
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

More Related Content

PPTX
Building Your Own DSL with Xtext
PDF
Language Workbenches
PDF
Implementing DSLs in practice
PDF
Java and effective programming. Is it possible? - IAESTE Case Week 2016
PDF
DSLs: what, why, how
PDF
Effective programming in Java - Kronospan Job Fair 2016
ODP
PDF
Internal domain-specific languages
Building Your Own DSL with Xtext
Language Workbenches
Implementing DSLs in practice
Java and effective programming. Is it possible? - IAESTE Case Week 2016
DSLs: what, why, how
Effective programming in Java - Kronospan Job Fair 2016
Internal domain-specific languages

What's hot (19)

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

Similar to EMPEX LA 2018 - Inclusion Starts with Docs (20)

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

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Cost to Outsource Software Development in 2025
PPTX
history of c programming in notes for students .pptx
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
System and Network Administration Chapter 2
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Transform Your Business with a Software ERP System
PTS Company Brochure 2025 (1).pdf.......
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Digital Strategies for Manufacturing Companies
Wondershare Filmora 15 Crack With Activation Key [2025
Which alternative to Crystal Reports is best for small or large businesses.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Cost to Outsource Software Development in 2025
history of c programming in notes for students .pptx
Designing Intelligence for the Shop Floor.pdf
System and Network Administration Chapter 2
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Upgrade and Innovation Strategies for SAP ERP Customers
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Choose the Right IT Partner for Your Business in Malaysia
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Transform Your Business with a Software ERP System

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
  • 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
  • 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]}
  • 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
  • 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
  • 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
  • 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