SlideShare une entreprise Scribd logo
1  sur  15
Code Comments
“Why”, not “What”
Sean Kelly
@StabbyCutyou
About Me
Hi, I’m Stabby
I’ve written code professionally for 13 years or
something like that
I have super strong opinions about seemingly
mundane topics
“Good code documents itself”
- A Filthy Liar, some point in time
Code Comments
A trip through history
Comments - Examples
Fortran
! This is a fortran comment
LISP
(((((((((( ; This is a LISP comment
COBOL
* THIS IS A COBOL COMMENT
C and most other languages (Go, for example!)
// This is a C or C-like comment
/* This is a C or C-like block comment */
Python, Ruby, and some others
# This is a Python or Ruby like comment
Cool things you can do with
comments
You can make them carry hidden meaning for the
compiler
You can use them to generate APIs
You can use them to build online documentation
You can use them to add metadata to generated code
You can keep someone from MURDERING YOU by
using them correctly
Go and Comments
Godoc is cool
But proper commenting is cooler
Comments in Go
Go takes commenting very seriously
Let the lint tools whine at you about missing comments
Comments can be used to change build behavior
Coming soon: There will be a standard comment for
identifying generated files
Generate perfectly acceptable online documentation
Including live examples!
Obligatory section about Godoc
Add the “godoc badge” to your repos
DO NOT NEGLECT YOUR README.MD
Check out your local changes with the local godoc
server: godoc -http=“:6060”
Follow the suggested formatting style for comments
In My Opinion(™): Godoc alone is NOT ENOUGH
Comments in General
Comments require maintenance
They get out of date when code changes - fix them
Comments are not just there for you
Comments are there for other people who have to work on
the code later
They are also there for you in 2 weeks/days/minutes after
you’ve forgotten everything you had in your head about the
design
Comments in General
Providing examples in comments is useful,
but don’t go crazy
// TODO , // HACK, etc are perfectly
acceptable, SO LONG AS YOU’RE
TRACKING THEM
You always have time to write comments
WHAT
// SafetyValve is a threshold that we set to
throttle the number of requests we make to
the FooService
SafetyValve = 80.0 // Only 80 concurrent
requests at a time
WHY
// We set this value so that we don’t overwhelm the FooService.
Currently, it’s resource constrained and unable to handle exceedingly
large request volumes, so we have upstream consumers provide a
throttling mechanism. We eventually plan to replace it (lol)
// After a series of tests, we’ve determined that roughly 80 concurrent
requests at once per consumer will give us both the headroom we
need to handle additional capacity by going wide with consumers
during a large traffic spike, as well as provide an acceptable level of
request queueing under those conditions without overwhelming any of
the servers. Do not change this number without understanding and
benchmarking what the ramifications will be.
“I can always figure out the what, if I look at the
code long enough. But the context of ‘why’ is
lost forever unless written down”
–Me, right now
Thanks!
“Why”, not “What”
Sean Kelly
@StabbyCutyou

Contenu connexe

Similaire à Comments: Why not What

I broke what?!??!? Taking over maintenance on well loved projects
I broke what?!??!? Taking over maintenance on well loved projectsI broke what?!??!? Taking over maintenance on well loved projects
I broke what?!??!? Taking over maintenance on well loved projectsBert JW Regeer
 
I broke what? Taking over maintenance on existing (well loved) projects, by B...
I broke what? Taking over maintenance on existing (well loved) projects, by B...I broke what? Taking over maintenance on existing (well loved) projects, by B...
I broke what? Taking over maintenance on existing (well loved) projects, by B...T. Kim Nguyen
 
Creating and Maintaining an Open Source Library
Creating and Maintaining an Open Source LibraryCreating and Maintaining an Open Source Library
Creating and Maintaining an Open Source LibraryNicholas Schweitzer
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Codemtoppa
 
Softshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineSoftshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineClaire Reynaud
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringAndrew Kirkpatrick
 
Untangling spring week8
Untangling spring week8Untangling spring week8
Untangling spring week8Derek Jacoby
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHPGautam Rege
 
OSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityOSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityGleicon Moraes
 
Building resuable and customizable Vue components
Building resuable and customizable Vue componentsBuilding resuable and customizable Vue components
Building resuable and customizable Vue componentsFilip Rakowski
 
Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016Adrian Roselli
 
Sharepoint Document Conversion
Sharepoint Document ConversionSharepoint Document Conversion
Sharepoint Document ConversionColin Gardner
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?Albert Chen
 
Mike walsh hadr_toomanychoices_20191107
Mike walsh hadr_toomanychoices_20191107Mike walsh hadr_toomanychoices_20191107
Mike walsh hadr_toomanychoices_20191107Mike Walsh
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)alloy020
 
Publishing strategies for API documentation
Publishing strategies for API documentationPublishing strategies for API documentation
Publishing strategies for API documentationTom Johnson
 
From hello world to goodbye code
From hello world to goodbye codeFrom hello world to goodbye code
From hello world to goodbye codeKim Moir
 
Resources For Floss Projects
Resources For Floss ProjectsResources For Floss Projects
Resources For Floss ProjectsJon Spriggs
 

Similaire à Comments: Why not What (20)

I broke what?!??!? Taking over maintenance on well loved projects
I broke what?!??!? Taking over maintenance on well loved projectsI broke what?!??!? Taking over maintenance on well loved projects
I broke what?!??!? Taking over maintenance on well loved projects
 
I broke what? Taking over maintenance on existing (well loved) projects, by B...
I broke what? Taking over maintenance on existing (well loved) projects, by B...I broke what? Taking over maintenance on existing (well loved) projects, by B...
I broke what? Taking over maintenance on existing (well loved) projects, by B...
 
Creating and Maintaining an Open Source Library
Creating and Maintaining an Open Source LibraryCreating and Maintaining an Open Source Library
Creating and Maintaining an Open Source Library
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Code
 
Softshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineSoftshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offline
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
 
Untangling spring week8
Untangling spring week8Untangling spring week8
Untangling spring week8
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHP
 
OSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityOSCon - Performance vs Scalability
OSCon - Performance vs Scalability
 
Building resuable and customizable Vue components
Building resuable and customizable Vue componentsBuilding resuable and customizable Vue components
Building resuable and customizable Vue components
 
Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016
 
From VB Script to PowerShell
From VB Script to PowerShellFrom VB Script to PowerShell
From VB Script to PowerShell
 
Graphql
GraphqlGraphql
Graphql
 
Sharepoint Document Conversion
Sharepoint Document ConversionSharepoint Document Conversion
Sharepoint Document Conversion
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?
 
Mike walsh hadr_toomanychoices_20191107
Mike walsh hadr_toomanychoices_20191107Mike walsh hadr_toomanychoices_20191107
Mike walsh hadr_toomanychoices_20191107
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
Publishing strategies for API documentation
Publishing strategies for API documentationPublishing strategies for API documentation
Publishing strategies for API documentation
 
From hello world to goodbye code
From hello world to goodbye codeFrom hello world to goodbye code
From hello world to goodbye code
 
Resources For Floss Projects
Resources For Floss ProjectsResources For Floss Projects
Resources For Floss Projects
 

Plus de Sean Kelly

Go testunderthehood
Go testunderthehoodGo testunderthehood
Go testunderthehoodSean Kelly
 
Embedding: It sure is weird
Embedding: It sure is weirdEmbedding: It sure is weird
Embedding: It sure is weirdSean Kelly
 
Don't Fear Failure
Don't Fear FailureDon't Fear Failure
Don't Fear FailureSean Kelly
 
Services, dependencies, and you
Services, dependencies, and youServices, dependencies, and you
Services, dependencies, and youSean Kelly
 
Microservices - Please, don't
Microservices - Please, don'tMicroservices - Please, don't
Microservices - Please, don'tSean Kelly
 

Plus de Sean Kelly (8)

Go testunderthehood
Go testunderthehoodGo testunderthehood
Go testunderthehood
 
Broadcasting
BroadcastingBroadcasting
Broadcasting
 
Embedding: It sure is weird
Embedding: It sure is weirdEmbedding: It sure is weird
Embedding: It sure is weird
 
Don't Fear Failure
Don't Fear FailureDon't Fear Failure
Don't Fear Failure
 
Services, dependencies, and you
Services, dependencies, and youServices, dependencies, and you
Services, dependencies, and you
 
Microservices - Please, don't
Microservices - Please, don'tMicroservices - Please, don't
Microservices - Please, don't
 
Messaging
MessagingMessaging
Messaging
 
Messaging
MessagingMessaging
Messaging
 

Dernier

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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

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?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Comments: Why not What

  • 1. Code Comments “Why”, not “What” Sean Kelly @StabbyCutyou
  • 2. About Me Hi, I’m Stabby I’ve written code professionally for 13 years or something like that I have super strong opinions about seemingly mundane topics
  • 3. “Good code documents itself” - A Filthy Liar, some point in time
  • 4. Code Comments A trip through history
  • 5. Comments - Examples Fortran ! This is a fortran comment LISP (((((((((( ; This is a LISP comment COBOL * THIS IS A COBOL COMMENT C and most other languages (Go, for example!) // This is a C or C-like comment /* This is a C or C-like block comment */ Python, Ruby, and some others # This is a Python or Ruby like comment
  • 6. Cool things you can do with comments You can make them carry hidden meaning for the compiler You can use them to generate APIs You can use them to build online documentation You can use them to add metadata to generated code You can keep someone from MURDERING YOU by using them correctly
  • 7. Go and Comments Godoc is cool But proper commenting is cooler
  • 8. Comments in Go Go takes commenting very seriously Let the lint tools whine at you about missing comments Comments can be used to change build behavior Coming soon: There will be a standard comment for identifying generated files Generate perfectly acceptable online documentation Including live examples!
  • 9. Obligatory section about Godoc Add the “godoc badge” to your repos DO NOT NEGLECT YOUR README.MD Check out your local changes with the local godoc server: godoc -http=“:6060” Follow the suggested formatting style for comments In My Opinion(™): Godoc alone is NOT ENOUGH
  • 10. Comments in General Comments require maintenance They get out of date when code changes - fix them Comments are not just there for you Comments are there for other people who have to work on the code later They are also there for you in 2 weeks/days/minutes after you’ve forgotten everything you had in your head about the design
  • 11. Comments in General Providing examples in comments is useful, but don’t go crazy // TODO , // HACK, etc are perfectly acceptable, SO LONG AS YOU’RE TRACKING THEM You always have time to write comments
  • 12. WHAT // SafetyValve is a threshold that we set to throttle the number of requests we make to the FooService SafetyValve = 80.0 // Only 80 concurrent requests at a time
  • 13. WHY // We set this value so that we don’t overwhelm the FooService. Currently, it’s resource constrained and unable to handle exceedingly large request volumes, so we have upstream consumers provide a throttling mechanism. We eventually plan to replace it (lol) // After a series of tests, we’ve determined that roughly 80 concurrent requests at once per consumer will give us both the headroom we need to handle additional capacity by going wide with consumers during a large traffic spike, as well as provide an acceptable level of request queueing under those conditions without overwhelming any of the servers. Do not change this number without understanding and benchmarking what the ramifications will be.
  • 14. “I can always figure out the what, if I look at the code long enough. But the context of ‘why’ is lost forever unless written down” –Me, right now