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

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
 

Semelhante 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

From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)IES VE
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveIES VE
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingMAGNIntelligence
 
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
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTxtailishbaloch
 
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
 
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
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameKapil Thakar
 
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
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 
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
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Muhammad Tiham Siddiqui
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxKaustubhBhavsar6
 
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
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 

Último (20)

From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced Computing
 
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
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
 
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
 
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
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First Frame
 
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
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 
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
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)
 
How to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptxHow to become a GDSC Lead GDSC MI AOE.pptx
How to become a GDSC Lead GDSC MI AOE.pptx
 
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
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 

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