SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Go Best and Bad
Practices
LAGOS, NG. 18 AUGUST, 2018
Anthony Alaribe
Opera (Opay team)
@tonyalaribe
Today’s (glorious) blather.
Handle errors first 01
Use Function adapters
Closures vs Methods
Errors are values
A Concurrency Gotcha
02
03
04
05
How to write code that is:
02. A SIMPLE TYPE SYSTEM
- Simple
- Maintainable
- Readable (Yet powerful)
Disclaimer
02. A SIMPLE TYPE SYSTEM
- This talk is based of a lot of other
resources in the community from
people like
- Francis Campoy,
- Robe Pike,
- Steve Francia, etc
Avoid nesting by
handling errors first
01. AVOID NESTING BY HANDLING ERRORS FIRST
01. AVOID NESTING BY HANDLING ERRORS FIRST
Use function
adapters
02. USE FUNCTION ADAPTERS (HIGH ORDER FUNCTIONS)
02. USE FUNCTION ADAPTERS (HIGH ORDER FUNCTIONS)
Methods vs
Closures in Web
Architectures
03. Methods vs Closures
03. Methods vs Closures
03. Methods vs Closures
03. Methods vs Closures
Errors are
values
03. ERRORS ARE VALUES
TENETS OF GO DESIGN
Errors.
An error can be
anything which
satisfies the
golang interface
03. ERRORS ARE VALUES
03. ERRORS ARE VALUES
03. ERRORS ARE VALUES
NOTE
03. METHODS VS CLOSURES
r.Mount("/api/todo",
todo.Routes(configuration))
Things to Note:
The smaller code surface area.
Using closures, the code feels
more compact
(and in my opinion, elegant).
functionA(argA)(argB)(argC)
Closures can be a little less
unnatural, since you can have
scenarios such as
A few Bad
Practices
Excessive use of inline
functions in concurrent
programming
03. INLINE CONCURRENCY
03. INLINE CONCURRENCY
03. INLINE CONCURRENCY
Debugging is twice as hard as writing the
code in the first place. Therefore, if you
write the code as cleverly as possible,
you are, by definition, not smart enough
to debug it.
BRIAN KERNIGHAN
Thank you

Weitere ähnliche Inhalte

Ähnlich wie Go best (and bad) practices

OpenERP - Building a better, global product with the community
OpenERP - Building a better, global product with the communityOpenERP - Building a better, global product with the community
OpenERP - Building a better, global product with the community
Odoo
 

Ähnlich wie Go best (and bad) practices (20)

Standards Through Interoperability? Really?
Standards Through Interoperability? Really?Standards Through Interoperability? Really?
Standards Through Interoperability? Really?
 
Debugging Apache Hadoop YARN Cluster in Production
Debugging Apache Hadoop YARN Cluster in ProductionDebugging Apache Hadoop YARN Cluster in Production
Debugging Apache Hadoop YARN Cluster in Production
 
Reactive Programming or Reactive Systems? (spoiler: both)
Reactive Programming or Reactive Systems? (spoiler: both)Reactive Programming or Reactive Systems? (spoiler: both)
Reactive Programming or Reactive Systems? (spoiler: both)
 
Copyright, Open Source and APIs (towards an Interface Commons)
Copyright, Open Source and APIs (towards an Interface Commons)Copyright, Open Source and APIs (towards an Interface Commons)
Copyright, Open Source and APIs (towards an Interface Commons)
 
Is Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic GascIs Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic Gasc
 
Android reverse engineering - Analyzing skype
Android reverse engineering - Analyzing skypeAndroid reverse engineering - Analyzing skype
Android reverse engineering - Analyzing skype
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
APIdays Paris 2019 Backend is the new frontend by Antoine Cheron
APIdays Paris 2019 Backend is the new frontend by Antoine CheronAPIdays Paris 2019 Backend is the new frontend by Antoine Cheron
APIdays Paris 2019 Backend is the new frontend by Antoine Cheron
 
Web 2.0: Addressing Institutional Barriers
Web 2.0: Addressing Institutional BarriersWeb 2.0: Addressing Institutional Barriers
Web 2.0: Addressing Institutional Barriers
 
Api desgin
Api desginApi desgin
Api desgin
 
Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)
Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)
Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)
 
OpenERP - Building a better, global product with the community
OpenERP - Building a better, global product with the communityOpenERP - Building a better, global product with the community
OpenERP - Building a better, global product with the community
 
apidays Paris 2022 - The next five years of the API Economy, Paolo Malinverno...
apidays Paris 2022 - The next five years of the API Economy, Paolo Malinverno...apidays Paris 2022 - The next five years of the API Economy, Paolo Malinverno...
apidays Paris 2022 - The next five years of the API Economy, Paolo Malinverno...
 
μ/log and the next 100 log systems
μ/log and the next 100 log systemsμ/log and the next 100 log systems
μ/log and the next 100 log systems
 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
 
An Introduction to Usability
An Introduction to UsabilityAn Introduction to Usability
An Introduction to Usability
 
Ruby codebases in an entropic universe
Ruby codebases in an entropic universeRuby codebases in an entropic universe
Ruby codebases in an entropic universe
 
Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010
 
A Pragmatic Approach
A Pragmatic ApproachA Pragmatic Approach
A Pragmatic Approach
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer 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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
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...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

Go best (and bad) practices