SlideShare a Scribd company logo
Metaprogramming Go
Weng Wei, Nov 2014
About Me
• Weng Wei, Chinese in Singapore
• Full-stack developer
• .net -> python -> go
• Passionate about code & life
Metaprogramming (MP)
• “writing of computer programs with the ability to
treat programs as their data...program could be
designed to read, generate, analyse and/or
transform other programs”
• allows programmers to minimize the number of
lines of code to express a solution => better
produtivity
MP is everywhere
• Compiler is the most common MP tool, it compile
high level code to lower one
• MP for manipulating other code is also common, for
example: C Macro
C Macro
#define list_for_each(pos, head) 
for (pos = (head)->next; pos != (head);
pos = pos->next)
Metaprogramming Go?
• No macro
• No generic
• Reflection in Go is awful
• “ gopher has been hard working these years… to
solve problems don’t exist in other languages……” -
@laiyonghao
How hard working gopher
solve generic with py?
• StringSet& IntSet has exact code structure, only
types are different
• Classic usage of generic
Simple & Effective
auto generate
• MakeFile?
• Real-time file monitor: github.com/gorakhargosh/
watchdog
How about “ORM”?
We need DSL:

thrift
Same struct definition
• CRUD
• Full-text search
• User Permission
• RPC
Lots of boilerplate code
for obj passing, value
assign, display etc
• Generate them all!
• Generated code won’t have typo
Implementation
Struct Parsing
• ptsd: github.com/wickman/ptsd
• thrift lexer/parser using ply
• ply: www.dabeaz.com/ply/
• An implementation of lex and yacc parsing tools
for Python
code-gen template
• www.cheetahtemplate.org
YAML is very handy
Define workflow
• Similar to ORM: change DSL from thrift to YAML
• YAML
• More flexible
• Non-coder friendly
API
• Needed in different places:
• web
• mobile web
• mobile client
• Business are the same, but may need different
wrapping
Web Form
JSON HTTP
Mobile API
We should be lazy about
writing boilerplate
wrapping code
So, we have 300k80line of code,
mostly generated
• Above are “demo codes”
• Actual code are much more complicated
• ORM:github.com/sipin/xuanwu
• Just for referencing of idea; don’t use it
• No documentation
• No maintain
• We’ve restarted
Customisation?
• Generate once, and change
• Generate whenever template changes:
• Provide callback interface
• Method overwriting
• May use MP for generic, ORM, workflow, API
wrapping, and more
• Consider MP as code-refactoring
• Write the dirty code first
• Abstract similar code repeated to template
• Choose an DSL
• Python is simple & resourceful; handy for
metaprogramming prototype/PoC
Challenge of MP
• Choosing the right DSL
• Provide both:
• high level of abstraction
• low level customization
• www.joelonsoftware.com/articles/
LeakyAbstractions.html
Code generation
• Parse (DSL) & Bind (code-template) are easy
• just like HTML template
• Generated codes are simple, thus easy to debug
• Compiler checking for free
Reflection for LISP way?
• No compilation
• Error checking at runtime
• Implementation needs more challenger
• Codes are more elegant
• Yup, that could be better; so, how?
–Ken Thompson
“When in doubt, use brute force.”
Actually
• Python is not so fast
• After experiencing git’s extreme speed, you can’t tolerate hg’s “not so fast”
• It’s easier to use & analyse the same language in MP
• golang.org/pkg/go/parser/
• go generate in go 1.4
• docs.google.com/document/d/1V03LUfjSADDooDMhe-
_K59EgpTEm3V8uvQRuNMAEnjg
• Metaprogramming Go with GO is the way
• with py only for quick prototype/POC
Q & A

More Related Content

What's hot

Making CLI app in ruby
Making CLI app in rubyMaking CLI app in ruby
Making CLI app in ruby
Huy Do
 
Week 8 intro to python
Week 8   intro to pythonWeek 8   intro to python
Week 8 intro to pythonbrianjihoonlee
 
RubyConf China 2015 - Rails off assets pipeline
RubyConf China 2015 - Rails off assets pipelineRubyConf China 2015 - Rails off assets pipeline
RubyConf China 2015 - Rails off assets pipeline
Florian Dutey
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Viktor Vogel
 
ASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and ToolingASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and Tooling
💻 Spencer Schneidenbach
 
The future of templating and frameworks
The future of templating and frameworksThe future of templating and frameworks
The future of templating and frameworks
Filip Bruun Bech-Larsen
 
Terminal Happiness
Terminal HappinessTerminal Happiness
Terminal Happiness
Liam Dempsey
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
Filip Bruun Bech-Larsen
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHP
Gautam Rege
 
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
Sébastien Levert
 
Joomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiencesJoomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiences
Andy_Gaskell
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
Metosin Oy
 
So you think you can scale
So you think you can scaleSo you think you can scale
So you think you can scale
Dan Beil
 
Reason React
Reason ReactReason React
Reason React
Arnar Þór Sveinsson
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
Marko Heijnen
 
WordPress Development Environments
WordPress Development EnvironmentsWordPress Development Environments
WordPress Development Environments
Josh Cummings
 
How to write bad code using C#
How to write bad code using C#How to write bad code using C#
How to write bad code using C#
Wekoslav Stefanovski
 
Building mobile apps with PhoneGap and Backbone
Building mobile apps with PhoneGap and BackboneBuilding mobile apps with PhoneGap and Backbone
Building mobile apps with PhoneGap and Backbone
Troy Miles
 
Flask and Paramiko for Python VA
Flask and Paramiko for Python VAFlask and Paramiko for Python VA
Flask and Paramiko for Python VA
Enrique Valenzuela
 

What's hot (20)

Making CLI app in ruby
Making CLI app in rubyMaking CLI app in ruby
Making CLI app in ruby
 
Week 8 intro to python
Week 8   intro to pythonWeek 8   intro to python
Week 8 intro to python
 
RubyConf China 2015 - Rails off assets pipeline
RubyConf China 2015 - Rails off assets pipelineRubyConf China 2015 - Rails off assets pipeline
RubyConf China 2015 - Rails off assets pipeline
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
 
ASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and ToolingASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and Tooling
 
The future of templating and frameworks
The future of templating and frameworksThe future of templating and frameworks
The future of templating and frameworks
 
Terminal Happiness
Terminal HappinessTerminal Happiness
Terminal Happiness
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHP
 
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
 
Joomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiencesJoomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiences
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
So you think you can scale
So you think you can scaleSo you think you can scale
So you think you can scale
 
Reason React
Reason ReactReason React
Reason React
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
 
WordPress Development Environments
WordPress Development EnvironmentsWordPress Development Environments
WordPress Development Environments
 
How to write bad code using C#
How to write bad code using C#How to write bad code using C#
How to write bad code using C#
 
Building mobile apps with PhoneGap and Backbone
Building mobile apps with PhoneGap and BackboneBuilding mobile apps with PhoneGap and Backbone
Building mobile apps with PhoneGap and Backbone
 
Flask and Paramiko for Python VA
Flask and Paramiko for Python VAFlask and Paramiko for Python VA
Flask and Paramiko for Python VA
 

Viewers also liked

διαγων ιστορ γεν 4
διαγων ιστορ γεν 4διαγων ιστορ γεν 4
διαγων ιστορ γεν 4fan Mel
 
Traveling: The Places I've Been
Traveling: The Places I've BeenTraveling: The Places I've Been
Traveling: The Places I've Been
MikeLikesIE
 
Indicadores de medición
Indicadores de mediciónIndicadores de medición
Indicadores de mediciónAndres Martin
 
Manual de serviço ch125 spacy (1993) mskv8931 p chassi
Manual de serviço ch125 spacy (1993)   mskv8931 p chassiManual de serviço ch125 spacy (1993)   mskv8931 p chassi
Manual de serviço ch125 spacy (1993) mskv8931 p chassi
Thiago Huari
 
pnsr_the_power_of_people_report
pnsr_the_power_of_people_reportpnsr_the_power_of_people_report
pnsr_the_power_of_people_reportSharon Czarnek
 
Подумай о новогодних подарках СЕЙЧАС
Подумай о новогодних подарках СЕЙЧАСПодумай о новогодних подарках СЕЙЧАС
Подумай о новогодних подарках СЕЙЧАСDmitry Myskov
 
Selection of an appropriate classification technique for coastal biomass mapp...
Selection of an appropriate classification technique for coastal biomass mapp...Selection of an appropriate classification technique for coastal biomass mapp...
Selection of an appropriate classification technique for coastal biomass mapp...Urooj Saeed
 
Biotecnología
BiotecnologíaBiotecnología
Biotecnología
Joshebeth Reyes
 
Tecnologías de punta
Tecnologías de puntaTecnologías de punta
Tecnologías de punta
damarys12345
 
Presentation - Omega-3 PUFAs and Metabolic Syndrome
Presentation - Omega-3 PUFAs and Metabolic SyndromePresentation - Omega-3 PUFAs and Metabolic Syndrome
Presentation - Omega-3 PUFAs and Metabolic SyndromeJosh Nooner
 
Humor business
Humor businessHumor business
Humor business
Anand singh
 
Service: Meine kleine Kundenreise nach Texas. @smcst
Service: Meine kleine Kundenreise nach Texas. @smcstService: Meine kleine Kundenreise nach Texas. @smcst
Service: Meine kleine Kundenreise nach Texas. @smcst
Andreas H. Bock
 
Demand analysis
Demand analysisDemand analysis
Demand analysis
Simran Kaur
 
skoleledermøde
skoleledermødeskoleledermøde
skoleledermøde
citadeljazz
 

Viewers also liked (19)

διαγων ιστορ γεν 4
διαγων ιστορ γεν 4διαγων ιστορ γεν 4
διαγων ιστορ γεν 4
 
Traveling: The Places I've Been
Traveling: The Places I've BeenTraveling: The Places I've Been
Traveling: The Places I've Been
 
Q3 Evaluation
Q3 EvaluationQ3 Evaluation
Q3 Evaluation
 
Moz trip 09
Moz trip 09Moz trip 09
Moz trip 09
 
Indicadores de medición
Indicadores de mediciónIndicadores de medición
Indicadores de medición
 
Manual de serviço ch125 spacy (1993) mskv8931 p chassi
Manual de serviço ch125 spacy (1993)   mskv8931 p chassiManual de serviço ch125 spacy (1993)   mskv8931 p chassi
Manual de serviço ch125 spacy (1993) mskv8931 p chassi
 
pnsr_the_power_of_people_report
pnsr_the_power_of_people_reportpnsr_the_power_of_people_report
pnsr_the_power_of_people_report
 
Подумай о новогодних подарках СЕЙЧАС
Подумай о новогодних подарках СЕЙЧАСПодумай о новогодних подарках СЕЙЧАС
Подумай о новогодних подарках СЕЙЧАС
 
Selection of an appropriate classification technique for coastal biomass mapp...
Selection of an appropriate classification technique for coastal biomass mapp...Selection of an appropriate classification technique for coastal biomass mapp...
Selection of an appropriate classification technique for coastal biomass mapp...
 
Biotecnología
BiotecnologíaBiotecnología
Biotecnología
 
Khan Saeed Doc Files In PDF
Khan Saeed Doc Files In PDFKhan Saeed Doc Files In PDF
Khan Saeed Doc Files In PDF
 
Tecnologías de punta
Tecnologías de puntaTecnologías de punta
Tecnologías de punta
 
Presentation - Omega-3 PUFAs and Metabolic Syndrome
Presentation - Omega-3 PUFAs and Metabolic SyndromePresentation - Omega-3 PUFAs and Metabolic Syndrome
Presentation - Omega-3 PUFAs and Metabolic Syndrome
 
Resume
ResumeResume
Resume
 
Humor business
Humor businessHumor business
Humor business
 
Service: Meine kleine Kundenreise nach Texas. @smcst
Service: Meine kleine Kundenreise nach Texas. @smcstService: Meine kleine Kundenreise nach Texas. @smcst
Service: Meine kleine Kundenreise nach Texas. @smcst
 
Demand analysis
Demand analysisDemand analysis
Demand analysis
 
skoleledermøde
skoleledermødeskoleledermøde
skoleledermøde
 
Fotografico
FotograficoFotografico
Fotografico
 

Similar to Metaprogramming Go

Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
SanjeedaPraween
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
Mike Harris
 
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
GauravGamer2
 
Communication tool & Environment for Remote Worker
Communication tool & Environment for Remote WorkerCommunication tool & Environment for Remote Worker
Communication tool & Environment for Remote Worker
Shotaro Sakamaki
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
SingleStore
 
How Different are MongoDB Drivers
How Different are MongoDB DriversHow Different are MongoDB Drivers
How Different are MongoDB Drivers
Norberto Leite
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandonMaslowB
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET Dmytro Mindra
 
Web APIs: The future of software
Web APIs: The future of softwareWeb APIs: The future of software
Web APIs: The future of software
Reuven Lerner
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
Why Plone Will Die
Why Plone Will DieWhy Plone Will Die
Why Plone Will Die
Andreas Jung
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming Basics
Dhana malar
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013Iván Montes
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
Ron Barabash
 
Writing code for others
Writing code for othersWriting code for others
Writing code for othersAmol Pujari
 
Monorepo at Pinterest
Monorepo at PinterestMonorepo at Pinterest
Monorepo at Pinterest
Suman Karumuri
 
Unlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdfUnlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdf
Inexture Solutions
 
Half-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code RecoveryHalf-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code Recovery
Joxean Koret
 
Week 5
Week 5Week 5
Week 5A VD
 

Similar to Metaprogramming Go (20)

Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
 
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
 
Communication tool & Environment for Remote Worker
Communication tool & Environment for Remote WorkerCommunication tool & Environment for Remote Worker
Communication tool & Environment for Remote Worker
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
 
How Different are MongoDB Drivers
How Different are MongoDB DriversHow Different are MongoDB Drivers
How Different are MongoDB Drivers
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Web APIs: The future of software
Web APIs: The future of softwareWeb APIs: The future of software
Web APIs: The future of software
 
computer languages
computer languagescomputer languages
computer languages
 
Why Plone Will Die
Why Plone Will DieWhy Plone Will Die
Why Plone Will Die
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming Basics
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
Writing code for others
Writing code for othersWriting code for others
Writing code for others
 
Monorepo at Pinterest
Monorepo at PinterestMonorepo at Pinterest
Monorepo at Pinterest
 
Unlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdfUnlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdf
 
Half-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code RecoveryHalf-automatic Compilable Source Code Recovery
Half-automatic Compilable Source Code Recovery
 
Week 5
Week 5Week 5
Week 5
 

More from Weng Wei

About Caching
About CachingAbout Caching
About Caching
Weng Wei
 
谈谈缓存
谈谈缓存谈谈缓存
谈谈缓存
Weng Wei
 
用PY实现"Go元编程"
用PY实现"Go元编程"用PY实现"Go元编程"
用PY实现"Go元编程"
Weng Wei
 
Go for web
Go for webGo for web
Go for web
Weng Wei
 
Go for web
Go for webGo for web
Go for web
Weng Wei
 
论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性Weng Wei
 
Zalora php to_go
Zalora php to_goZalora php to_go
Zalora php to_goWeng Wei
 
A byte of git
A byte of gitA byte of git
A byte of gitWeng Wei
 
My understanding of Git
My understanding of GitMy understanding of Git
My understanding of GitWeng Wei
 
Inside Zend Framework
Inside Zend FrameworkInside Zend Framework
Inside Zend Framework
Weng Wei
 

More from Weng Wei (11)

About Caching
About CachingAbout Caching
About Caching
 
谈谈缓存
谈谈缓存谈谈缓存
谈谈缓存
 
用PY实现"Go元编程"
用PY实现"Go元编程"用PY实现"Go元编程"
用PY实现"Go元编程"
 
Go for web
Go for webGo for web
Go for web
 
Go for web
Go for webGo for web
Go for web
 
论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性
 
Zalora php to_go
Zalora php to_goZalora php to_go
Zalora php to_go
 
A byte of git
A byte of gitA byte of git
A byte of git
 
My understanding of Git
My understanding of GitMy understanding of Git
My understanding of Git
 
Sharding
ShardingSharding
Sharding
 
Inside Zend Framework
Inside Zend FrameworkInside Zend Framework
Inside Zend Framework
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
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
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
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
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 

Metaprogramming Go

  • 2.
  • 3. About Me • Weng Wei, Chinese in Singapore • Full-stack developer • .net -> python -> go • Passionate about code & life
  • 4. Metaprogramming (MP) • “writing of computer programs with the ability to treat programs as their data...program could be designed to read, generate, analyse and/or transform other programs” • allows programmers to minimize the number of lines of code to express a solution => better produtivity
  • 5. MP is everywhere • Compiler is the most common MP tool, it compile high level code to lower one • MP for manipulating other code is also common, for example: C Macro
  • 6. C Macro #define list_for_each(pos, head) for (pos = (head)->next; pos != (head); pos = pos->next)
  • 7. Metaprogramming Go? • No macro • No generic • Reflection in Go is awful • “ gopher has been hard working these years… to solve problems don’t exist in other languages……” - @laiyonghao
  • 8. How hard working gopher solve generic with py?
  • 9.
  • 10. • StringSet& IntSet has exact code structure, only types are different • Classic usage of generic
  • 11.
  • 12.
  • 14. auto generate • MakeFile? • Real-time file monitor: github.com/gorakhargosh/ watchdog
  • 17.
  • 18.
  • 19.
  • 20. Same struct definition • CRUD • Full-text search • User Permission • RPC
  • 21. Lots of boilerplate code for obj passing, value assign, display etc
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. • Generate them all! • Generated code won’t have typo
  • 28. Struct Parsing • ptsd: github.com/wickman/ptsd • thrift lexer/parser using ply • ply: www.dabeaz.com/ply/ • An implementation of lex and yacc parsing tools for Python
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. YAML is very handy
  • 41.
  • 42.
  • 43. • Similar to ORM: change DSL from thrift to YAML • YAML • More flexible • Non-coder friendly
  • 44. API • Needed in different places: • web • mobile web • mobile client • Business are the same, but may need different wrapping
  • 45.
  • 49. We should be lazy about writing boilerplate wrapping code
  • 50.
  • 51. So, we have 300k80line of code, mostly generated
  • 52. • Above are “demo codes” • Actual code are much more complicated • ORM:github.com/sipin/xuanwu • Just for referencing of idea; don’t use it • No documentation • No maintain • We’ve restarted
  • 53. Customisation? • Generate once, and change • Generate whenever template changes: • Provide callback interface • Method overwriting
  • 54.
  • 55.
  • 56. • May use MP for generic, ORM, workflow, API wrapping, and more • Consider MP as code-refactoring • Write the dirty code first • Abstract similar code repeated to template • Choose an DSL • Python is simple & resourceful; handy for metaprogramming prototype/PoC
  • 57. Challenge of MP • Choosing the right DSL • Provide both: • high level of abstraction • low level customization • www.joelonsoftware.com/articles/ LeakyAbstractions.html
  • 58. Code generation • Parse (DSL) & Bind (code-template) are easy • just like HTML template • Generated codes are simple, thus easy to debug • Compiler checking for free
  • 59. Reflection for LISP way? • No compilation • Error checking at runtime • Implementation needs more challenger • Codes are more elegant • Yup, that could be better; so, how?
  • 60. –Ken Thompson “When in doubt, use brute force.”
  • 61. Actually • Python is not so fast • After experiencing git’s extreme speed, you can’t tolerate hg’s “not so fast” • It’s easier to use & analyse the same language in MP • golang.org/pkg/go/parser/ • go generate in go 1.4 • docs.google.com/document/d/1V03LUfjSADDooDMhe- _K59EgpTEm3V8uvQRuNMAEnjg • Metaprogramming Go with GO is the way • with py only for quick prototype/POC
  • 62. Q & A