SlideShare uma empresa Scribd logo
1 de 24
THE BEST FEATURE OF GO
A 5-YEAR RETROSPECTIVE
GO & I
▸ Programming since the ‘90s
▸ Former C, C++, PHP, Python, JavaScript, Java programmer
▸ Switched to Go in 2012
▸ Handful of large Go implementations across 2 companies
▸ Have my own shortlist of favorite Go features over the years
▸ One of those features is exceptional
NOTABLE FEATURES
COMPILER & SYNTAX
▸ Avoids historically error prone constructs
▸ Highly assistive error messages
▸ Focus on intention rather than expression
▸ If it compiles, it mostly works
▸ Very high performance with low effort
SMALL FEATURE SET
▸ A tad bigger than C
▸ Orthogonal, Minimal
▸ Easy to Learn
▸ Easy to Remember
▸ Minimized Personal Feature Subsets
STANDARDIZED FORMATTING
▸ 10
x improvement in readability
▸ Improved collaboration between team members
▸ Improved collaboration across teams
▸ More easily accessible Open Source code
SENSIBLE UNICODE & STRINGS
▸ UTF-8 encoded strings
▸ Compatible []byte and string memory layout
▸ Minimized copying between buffers and strings
▸ Rich set of string manipulators available
GOROUTINES & CHANNELS
▸ Declarative Parallel Programming
▸ Based on CSP Principles
▸ Straight-forward procedural logic — no callback mess
▸ Any function/method can be invoked asynchronously
SELECT STATEMENT
▸ Go’s tour de force in parallel programming
▸ Simple, declarative expression of event synchronization
▸ Makes previously complicated flows trivial to implement
▸ Timeouts
▸ Cancellation
▸ Back-pressure handling
▸ Combinations of the above
CAPABILITY
GO CHANGED MY PROGRAMMING
PERFORMANCE AND COMPLEXITY WITH CONFIDENCE
▸ First production system in Go: a Multiplayer Game Engine
▸ Made > $1000,000 in a year
▸ Also, a rate limiter, a reverse proxy, a micro-service simulator,
deployment orchestrator, cluster auto-scaler…
▸ … even a bespoke datastore!
PROGRAMMER
ONE FEATURE CHANGED ME AS A
THE BEST FEATURE OF GO
▸ Acts as a stand-in for the user
▸ Improves documentation
▸ Guides program design
▸ Aids Refactoring & Debugging
▸ Finds unnecessary/dysfunctional code
▸ Gives rapid feedback on performance characteristics
Can you guess what it is?
GO TEST
GO TEST IN DESIGN PHASE
USER SIMULATION
Use package pkg_test to get “3rd Party” view
▸ Allows accessing your package like an end-user
▸ Helps the provider switch mind to that of a consumer
▸ Helps in deciding exported symbols
▸ Improves API Design
GO TEST IN DESIGN PHASE
DOCUMENTATION
▸ Write testable, runnable Examples that show up in the
documentation
▸ Document methods: func ExampleStruct_Method() {…}
▸ Document functions: func ExampleFunction() {…}
▸ Document use cases: func Example_useCase() {…}
GO TEST IN DESIGN PHASE
PROGRAM DESIGN
▸ Monolithic do-it-all functions are hard to test
▸ The need to test improves modularity, functional cohesion
▸ Sample Strategy:
1. Implement business logic as native APIs with native data — test
entire business logic
2. Implement data load/store from native to database — test data
validation and access
3. Implement remoting (HTTP etc.) APIs — test request interpretation
and response serialization
GO TEST IN IMPLEMENTATION PHASE
REFACTORING
▸ Table driven testing helps in basic I/O validation
▸ Top-level tests for checking various scenarios
▸ Subtests help in isolating granular functionality
▸ Non-compilable tests indicate changes in package interface
▸ Failing tests indicate changes in functional behaviours
GO TEST IN IMPLEMENTATION PHASE
DEBUGGING
▸ Parallel tests with race detector for
unsafe concurrent data access
▸ Optional long running tests for
deeper verification
▸ Test cases can be complex enough
to act as simulators. 



E.g. the graph here is from a 1-
million iteration sim of smartcb
Error Rate Learned Rate SmartCB Regular CB
GO TEST IN IMPLEMENTATION PHASE
FINDING USELESS CODE
▸ $ go test -coverprofile to find which lines were executed
by the test
▸ Untouched lines =>
▸ The tests don’t check the logic for which the code is written,
or
▸ The code is untestable because it’s dead or represents a
logically impossible scenario
GO TEST IN OPTIMIZATION PHASE
BENCHMARKING
▸ $ go test -bench to see how fast functions/methods are
▸ $ go test -bench -cpu to observe multi-core scalability
▸ $ go test -bench -cpuprofile to see what parts of the
code are slow
▸ $ go test -bench -memprofile to see what parts of the
code eat up memory
▸ Run go test -bench before every commit to find
performance regressions
GO TEST IS LIKE A PROGRAMMER’S
ASSISTANT. AN IRONMAN’S JARVIS. A
BATMAN’S ALFRED.
IT HAPPENS TO RUN UNIT TESTS TOO
Yours Truly
MORE THAN UNIT TESTING
THANK YOU
TAHIR HASHMI, PT TOKOPEDIA, JAN 2018
FURTHER INFORMATION
▸ talks.golang.org
▸ tour.golang.org
▸ tech.t9i.in
▸ @code_martial

Mais conteúdo relacionado

Semelhante a The Best Feature of Go – A 5 Year Retrospective

FT 2009 Highspeed Test Automation
FT 2009 Highspeed Test AutomationFT 2009 Highspeed Test Automation
FT 2009 Highspeed Test AutomationMichel Löhr
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerPôle Systematic Paris-Region
 
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08Борис Зора
 
The Mechanics of Testing Large Data Pipelines
The Mechanics of Testing Large Data PipelinesThe Mechanics of Testing Large Data Pipelines
The Mechanics of Testing Large Data PipelinesC4Media
 
Devops (start walking in the same direction) by ops
Devops (start walking in the same direction) by opsDevops (start walking in the same direction) by ops
Devops (start walking in the same direction) by opsDemis Rizzotto
 
The Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI toolThe Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI toolIvo Jimenez
 
Andrea Di Persio
Andrea Di PersioAndrea Di Persio
Andrea Di PersioCodeFest
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at ScaleKris Buytaert
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversiesVictorSzoltysek
 
CIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationCIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationGary Pamparà
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your CodeNate Abele
 
Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0Nate Abele
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOJosh Cypher
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with DjangoRoger Barnes
 
Technical Practices for Agile Engineering - PNSQC 2019
Technical Practices for Agile Engineering - PNSQC 2019Technical Practices for Agile Engineering - PNSQC 2019
Technical Practices for Agile Engineering - PNSQC 2019Moss Drake
 
A Java Developers first Clojure project
A Java Developers first Clojure projectA Java Developers first Clojure project
A Java Developers first Clojure projectCraig Malone
 
Full stack development best practice and toolset
Full stack development best practice and toolsetFull stack development best practice and toolset
Full stack development best practice and toolsetReid Lai
 

Semelhante a The Best Feature of Go – A 5 Year Retrospective (20)

FT 2009 Highspeed Test Automation
FT 2009 Highspeed Test AutomationFT 2009 Highspeed Test Automation
FT 2009 Highspeed Test Automation
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
 
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
 
The Mechanics of Testing Large Data Pipelines
The Mechanics of Testing Large Data PipelinesThe Mechanics of Testing Large Data Pipelines
The Mechanics of Testing Large Data Pipelines
 
Be DevOps Ready
Be DevOps ReadyBe DevOps Ready
Be DevOps Ready
 
Devops (start walking in the same direction) by ops
Devops (start walking in the same direction) by opsDevops (start walking in the same direction) by ops
Devops (start walking in the same direction) by ops
 
The Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI toolThe Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI tool
 
Andrea Di Persio
Andrea Di PersioAndrea Di Persio
Andrea Di Persio
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at Scale
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversies
 
CIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking ImplementationCIlib 2.0: Rethinking Implementation
CIlib 2.0: Rethinking Implementation
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
 
Intro to DevOps
Intro to DevOpsIntro to DevOps
Intro to DevOps
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with Django
 
Technical Practices for Agile Engineering - PNSQC 2019
Technical Practices for Agile Engineering - PNSQC 2019Technical Practices for Agile Engineering - PNSQC 2019
Technical Practices for Agile Engineering - PNSQC 2019
 
A Java Developers first Clojure project
A Java Developers first Clojure projectA Java Developers first Clojure project
A Java Developers first Clojure project
 
Full stack development best practice and toolset
Full stack development best practice and toolsetFull stack development best practice and toolset
Full stack development best practice and toolset
 

Último

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
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
 
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
 
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
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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?
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
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
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

The Best Feature of Go – A 5 Year Retrospective

  • 1. THE BEST FEATURE OF GO A 5-YEAR RETROSPECTIVE
  • 2. GO & I ▸ Programming since the ‘90s ▸ Former C, C++, PHP, Python, JavaScript, Java programmer ▸ Switched to Go in 2012 ▸ Handful of large Go implementations across 2 companies ▸ Have my own shortlist of favorite Go features over the years ▸ One of those features is exceptional
  • 4. COMPILER & SYNTAX ▸ Avoids historically error prone constructs ▸ Highly assistive error messages ▸ Focus on intention rather than expression ▸ If it compiles, it mostly works ▸ Very high performance with low effort
  • 5. SMALL FEATURE SET ▸ A tad bigger than C ▸ Orthogonal, Minimal ▸ Easy to Learn ▸ Easy to Remember ▸ Minimized Personal Feature Subsets
  • 6. STANDARDIZED FORMATTING ▸ 10 x improvement in readability ▸ Improved collaboration between team members ▸ Improved collaboration across teams ▸ More easily accessible Open Source code
  • 7. SENSIBLE UNICODE & STRINGS ▸ UTF-8 encoded strings ▸ Compatible []byte and string memory layout ▸ Minimized copying between buffers and strings ▸ Rich set of string manipulators available
  • 8. GOROUTINES & CHANNELS ▸ Declarative Parallel Programming ▸ Based on CSP Principles ▸ Straight-forward procedural logic — no callback mess ▸ Any function/method can be invoked asynchronously
  • 9. SELECT STATEMENT ▸ Go’s tour de force in parallel programming ▸ Simple, declarative expression of event synchronization ▸ Makes previously complicated flows trivial to implement ▸ Timeouts ▸ Cancellation ▸ Back-pressure handling ▸ Combinations of the above
  • 11. PERFORMANCE AND COMPLEXITY WITH CONFIDENCE ▸ First production system in Go: a Multiplayer Game Engine ▸ Made > $1000,000 in a year ▸ Also, a rate limiter, a reverse proxy, a micro-service simulator, deployment orchestrator, cluster auto-scaler… ▸ … even a bespoke datastore!
  • 13. THE BEST FEATURE OF GO ▸ Acts as a stand-in for the user ▸ Improves documentation ▸ Guides program design ▸ Aids Refactoring & Debugging ▸ Finds unnecessary/dysfunctional code ▸ Gives rapid feedback on performance characteristics Can you guess what it is?
  • 15. GO TEST IN DESIGN PHASE USER SIMULATION Use package pkg_test to get “3rd Party” view ▸ Allows accessing your package like an end-user ▸ Helps the provider switch mind to that of a consumer ▸ Helps in deciding exported symbols ▸ Improves API Design
  • 16. GO TEST IN DESIGN PHASE DOCUMENTATION ▸ Write testable, runnable Examples that show up in the documentation ▸ Document methods: func ExampleStruct_Method() {…} ▸ Document functions: func ExampleFunction() {…} ▸ Document use cases: func Example_useCase() {…}
  • 17. GO TEST IN DESIGN PHASE PROGRAM DESIGN ▸ Monolithic do-it-all functions are hard to test ▸ The need to test improves modularity, functional cohesion ▸ Sample Strategy: 1. Implement business logic as native APIs with native data — test entire business logic 2. Implement data load/store from native to database — test data validation and access 3. Implement remoting (HTTP etc.) APIs — test request interpretation and response serialization
  • 18. GO TEST IN IMPLEMENTATION PHASE REFACTORING ▸ Table driven testing helps in basic I/O validation ▸ Top-level tests for checking various scenarios ▸ Subtests help in isolating granular functionality ▸ Non-compilable tests indicate changes in package interface ▸ Failing tests indicate changes in functional behaviours
  • 19. GO TEST IN IMPLEMENTATION PHASE DEBUGGING ▸ Parallel tests with race detector for unsafe concurrent data access ▸ Optional long running tests for deeper verification ▸ Test cases can be complex enough to act as simulators. 
 
 E.g. the graph here is from a 1- million iteration sim of smartcb Error Rate Learned Rate SmartCB Regular CB
  • 20. GO TEST IN IMPLEMENTATION PHASE FINDING USELESS CODE ▸ $ go test -coverprofile to find which lines were executed by the test ▸ Untouched lines => ▸ The tests don’t check the logic for which the code is written, or ▸ The code is untestable because it’s dead or represents a logically impossible scenario
  • 21. GO TEST IN OPTIMIZATION PHASE BENCHMARKING ▸ $ go test -bench to see how fast functions/methods are ▸ $ go test -bench -cpu to observe multi-core scalability ▸ $ go test -bench -cpuprofile to see what parts of the code are slow ▸ $ go test -bench -memprofile to see what parts of the code eat up memory ▸ Run go test -bench before every commit to find performance regressions
  • 22. GO TEST IS LIKE A PROGRAMMER’S ASSISTANT. AN IRONMAN’S JARVIS. A BATMAN’S ALFRED. IT HAPPENS TO RUN UNIT TESTS TOO Yours Truly MORE THAN UNIT TESTING
  • 23. THANK YOU TAHIR HASHMI, PT TOKOPEDIA, JAN 2018
  • 24. FURTHER INFORMATION ▸ talks.golang.org ▸ tour.golang.org ▸ tech.t9i.in ▸ @code_martial