SlideShare una empresa de 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

Más contenido relacionado

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

Finance & Testing 2009 Highspeed Testautomation
Finance & Testing 2009 Highspeed TestautomationFinance & Testing 2009 Highspeed Testautomation
Finance & Testing 2009 Highspeed Testautomationguesta64aefc
 
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
 

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

Finance & Testing 2009 Highspeed Testautomation
Finance & Testing 2009 Highspeed TestautomationFinance & Testing 2009 Highspeed Testautomation
Finance & Testing 2009 Highspeed Testautomation
 
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

Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Alkin Tezuysal
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FESTBillieHyde
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2DianaGray10
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)codyslingerland1
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Libraryshyamraj55
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarThousandEyes
 

Último (20)

Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FEST
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Library
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? Webinar
 

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