SlideShare una empresa de Scribd logo
1 de 30
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Dark side of the reflect
Masaki Hitonishi
Common Support Services Dept.
DeNA Co., Ltd.
Copyright © DeNA Co.,Ltd. All Rights Reserved.
About me
 Masaki Hitonishi
 Software Engineer
⁃ Golang Enthusiast
⁃ Contributor to Gin the framework
⁃ HTML5 Game Developer
 twitter.com/@sairoutine
 github.com/sairoutine
Copyright © DeNA Co.,Ltd. All Rights Reserved.
DeNA.go will be held!
 https://dena.connpass.com/event/128034/
 Join registration is acceptable until 5/21 (Tue) !
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Today’s topic
 Introduction to reflect
 Building ORM by using reflect
 reflect or code generation?
Copyright © DeNA Co.,Ltd. All Rights Reserved.
What is reflect?
Copyright © DeNA Co.,Ltd. All Rights Reserved.
golang’s reflect
 Treats any types at runtime
⁃ Examines types
⁃ Creates and modifies it’s value
 makes us enable to do 2 things
⁃ Finding variables types
⁃ Getting field information
Copyright © DeNA Co.,Ltd. All Rights Reserved.
reflect package
 Provides the way to use reflect
 Defines the important 2 types
⁃ reflect.Type
⁃ reflect.Value
Copyright © DeNA Co.,Ltd. All Rights Reserved.
reflect.Type
 A Type represents golang’s type
 An interface with methods to distinguish
among types
⁃ Map? Struct? Slice? Function?
⁃ String? Int? Ptr?
Copyright © DeNA Co.,Ltd. All Rights Reserved.
reflect.Value
 A value represents golang’s all value
 It can hold a value of any type
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Reason to use reflect
 To manipulate dynamic types and values
⁃ Works with variables at runtime using
information that didn’t exist when the
program was written.
 To get meta information through struct tag
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Example of dynamic types and values
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Example of struct tag information
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Example of use case in the real world
 ORM like gorm, xorm, gorp and so on...
⁃ Object Relational Mapper
⁃ Gets and sets the structure the user
defined
 JSON Encoder/Decoder
⁃ Parse any value to JSON value
 etc...
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Writing ORM with reflect
Copyright © DeNA Co.,Ltd. All Rights Reserved.
DeNA Game dept.
 Using golang in some products
 Example
⁃ Game server framework
⁃ Development workflow platform
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Game server framework
 Next generation server framework under
development
 Golang + GCP
 Using Google Cloud Spanner as a backend
database
 Original ORM “Span” to treat Spanner
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Development workflow platform
 Named “Oyakata”
 Written in golang
 Using Noms as a backend database
 Original ORM “Norm” to use Noms database
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Noms
 Decentralized database
 https://github.com/attic-labs/noms
 No-SQL
 With Git like version control system
 Commit/Merge/Diff and so on in database
layer
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm
 ORM for Noms.
⁃ ORM is a library to convert data between
incompatible type systems to do object-
oriented programming.
 Users can define their own model struct.
 Maps their original struct to Noms data.
 Create/Read/Update/Delete.
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm Internal
 Create/Update
⁃ Any struct to any data
 Read
⁃ Any data to struct
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm Internal
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm Internal
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm Internal
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Norm Internal
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Continue to use reflect?
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Span
 O/R Mapper for Google Spanner.
 Users can define their own model struct.
 Create/Read/Update/Delete.
 Currently, It’s implemented by code generator,
not by reflect.
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Why stop using reflect?
 Difficult to read source code
⁃ The reflect code tends to be complexity.
 Performance issue
⁃ Reflect is slow
 Now, Span generates CRUD code by parsing
definition the users defines.
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Pros/Cons
 Pros
⁃ Even if struct field is changed, there is no
need to regenerate code
 Cons
⁃ The library code tends to be complexity
⁃ Reflect is slow
 Norm is still using reflect approach, Span has
changed to use code generation approach
Copyright © DeNA Co.,Ltd. All Rights Reserved.
Conclusions
 There are some cases the golang’s reflect is
efficient.
 However, code with reflect is a little difficult to
read.
 Consider code generating approach by your
use cases.
 Compare user comfortable and code
maintainability to decide either.

Más contenido relacionado

Similar a Dark side of the reflect

NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...
NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...
NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...GetInData
 
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...Dremio Corporation
 
Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Future Insights
 
Hardware Prototyping for Software Developers
Hardware Prototyping for Software DevelopersHardware Prototyping for Software Developers
Hardware Prototyping for Software DevelopersKinoma
 
UplinQ - qualcomm® snapdragon™ processors a super gaming platform
UplinQ - qualcomm® snapdragon™ processors a super gaming platformUplinQ - qualcomm® snapdragon™ processors a super gaming platform
UplinQ - qualcomm® snapdragon™ processors a super gaming platformSatya Harish
 
Qualcomm Snapdragon Processors: A Super Gaming Platform
Qualcomm Snapdragon Processors: A Super Gaming Platform Qualcomm Snapdragon Processors: A Super Gaming Platform
Qualcomm Snapdragon Processors: A Super Gaming Platform Qualcomm Developer Network
 
Test Engineering on Mobage
Test Engineering on MobageTest Engineering on Mobage
Test Engineering on MobageMasaki Nakagawa
 
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataModel serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataGetInData
 
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...VirtualTech Japan Inc.
 
CodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering labCodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering labRon Munitz
 
Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Hirokazu Egashira
 
【Primer】WebApp release in 3 hours! Programming from scratch Rails course
【Primer】WebApp release in 3 hours! Programming from scratch Rails course【Primer】WebApp release in 3 hours! Programming from scratch Rails course
【Primer】WebApp release in 3 hours! Programming from scratch Rails courseDIVE INTO CODE Corp.
 
Top 13 best front end web development tools to consider in 2021
Top 13 best front end web development tools to consider in 2021Top 13 best front end web development tools to consider in 2021
Top 13 best front end web development tools to consider in 2021Samaritan InfoTech
 
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023Pedro Vicente
 
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...Building a Recommender System Using Amazon SageMaker's Factorization Machine ...
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...Amazon Web Services
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Embarcadero Technologies
 
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabVoxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabRon Munitz
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataTaro L. Saito
 

Similar a Dark side of the reflect (20)

NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...
NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...
NLP for videos: Understanding customers' feelings in videos - Albert Lewandow...
 
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...
The Future of Column-Oriented Data Processing With Apache Arrow and Apache Pa...
 
Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)
 
Hardware Prototyping for Software Developers
Hardware Prototyping for Software DevelopersHardware Prototyping for Software Developers
Hardware Prototyping for Software Developers
 
Intel open mp
Intel open mpIntel open mp
Intel open mp
 
UplinQ - qualcomm® snapdragon™ processors a super gaming platform
UplinQ - qualcomm® snapdragon™ processors a super gaming platformUplinQ - qualcomm® snapdragon™ processors a super gaming platform
UplinQ - qualcomm® snapdragon™ processors a super gaming platform
 
Qualcomm Snapdragon Processors: A Super Gaming Platform
Qualcomm Snapdragon Processors: A Super Gaming Platform Qualcomm Snapdragon Processors: A Super Gaming Platform
Qualcomm Snapdragon Processors: A Super Gaming Platform
 
Test Engineering on Mobage
Test Engineering on MobageTest Engineering on Mobage
Test Engineering on Mobage
 
Application Deployment on IBM i
Application Deployment on IBM iApplication Deployment on IBM i
Application Deployment on IBM i
 
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInDataModel serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
Model serving made easy using Kedro pipelines - Mariusz Strzelecki, GetInData
 
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...
NTT Docomo's Challenge looking ahead the world pf 5G × OpenStack - OpenStack最...
 
CodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering labCodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering lab
 
Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Google ARが提供する WebAR 101
Google ARが提供する WebAR 101
 
【Primer】WebApp release in 3 hours! Programming from scratch Rails course
【Primer】WebApp release in 3 hours! Programming from scratch Rails course【Primer】WebApp release in 3 hours! Programming from scratch Rails course
【Primer】WebApp release in 3 hours! Programming from scratch Rails course
 
Top 13 best front end web development tools to consider in 2021
Top 13 best front end web development tools to consider in 2021Top 13 best front end web development tools to consider in 2021
Top 13 best front end web development tools to consider in 2021
 
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
 
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...Building a Recommender System Using Amazon SageMaker's Factorization Machine ...
Building a Recommender System Using Amazon SageMaker's Factorization Machine ...
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework
 
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabVoxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
 

Más de sairoutine

How to manage parameters for gacha games
How to manage parameters for gacha gamesHow to manage parameters for gacha games
How to manage parameters for gacha gamessairoutine
 
DeNAの最新のマスタデータ管理システム Oyakata の全容
DeNAの最新のマスタデータ管理システム Oyakata の全容DeNAの最新のマスタデータ管理システム Oyakata の全容
DeNAの最新のマスタデータ管理システム Oyakata の全容sairoutine
 
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例sairoutine
 
マジック・ザ・ギャザリングの背景世界とストーリー
マジック・ザ・ギャザリングの背景世界とストーリーマジック・ザ・ギャザリングの背景世界とストーリー
マジック・ザ・ギャザリングの背景世界とストーリーsairoutine
 
flow による型のある世界入門
flow による型のある世界入門flow による型のある世界入門
flow による型のある世界入門sairoutine
 
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れる
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れるレガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れる
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れるsairoutine
 
Mithril - 軽量/高速なMVCフレームワーク
Mithril - 軽量/高速なMVCフレームワークMithril - 軽量/高速なMVCフレームワーク
Mithril - 軽量/高速なMVCフレームワークsairoutine
 
Touhou Project on JavaScript
Touhou Project on JavaScriptTouhou Project on JavaScript
Touhou Project on JavaScriptsairoutine
 
JSでファミコンエミュレータを作った時の話
JSでファミコンエミュレータを作った時の話JSでファミコンエミュレータを作った時の話
JSでファミコンエミュレータを作った時の話sairoutine
 
JS と Canvas で作るシューティングゲーム
JS と Canvas で作るシューティングゲームJS と Canvas で作るシューティングゲーム
JS と Canvas で作るシューティングゲームsairoutine
 
ゲームエンジニアのためのデータベース設計
ゲームエンジニアのためのデータベース設計ゲームエンジニアのためのデータベース設計
ゲームエンジニアのためのデータベース設計sairoutine
 
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をする
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をするSlack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をする
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をするsairoutine
 

Más de sairoutine (13)

How to manage parameters for gacha games
How to manage parameters for gacha gamesHow to manage parameters for gacha games
How to manage parameters for gacha games
 
DeNAの最新のマスタデータ管理システム Oyakata の全容
DeNAの最新のマスタデータ管理システム Oyakata の全容DeNAの最新のマスタデータ管理システム Oyakata の全容
DeNAの最新のマスタデータ管理システム Oyakata の全容
 
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例
CEDEC2019 大規模モバイルゲーム運用におけるマスタデータ管理事例
 
マジック・ザ・ギャザリングの背景世界とストーリー
マジック・ザ・ギャザリングの背景世界とストーリーマジック・ザ・ギャザリングの背景世界とストーリー
マジック・ザ・ギャザリングの背景世界とストーリー
 
em-dosbox
em-dosboxem-dosbox
em-dosbox
 
flow による型のある世界入門
flow による型のある世界入門flow による型のある世界入門
flow による型のある世界入門
 
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れる
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れるレガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れる
レガシーな Perl システムに DDD (ドメイン駆動設計)を取り入れる
 
Mithril - 軽量/高速なMVCフレームワーク
Mithril - 軽量/高速なMVCフレームワークMithril - 軽量/高速なMVCフレームワーク
Mithril - 軽量/高速なMVCフレームワーク
 
Touhou Project on JavaScript
Touhou Project on JavaScriptTouhou Project on JavaScript
Touhou Project on JavaScript
 
JSでファミコンエミュレータを作った時の話
JSでファミコンエミュレータを作った時の話JSでファミコンエミュレータを作った時の話
JSでファミコンエミュレータを作った時の話
 
JS と Canvas で作るシューティングゲーム
JS と Canvas で作るシューティングゲームJS と Canvas で作るシューティングゲーム
JS と Canvas で作るシューティングゲーム
 
ゲームエンジニアのためのデータベース設計
ゲームエンジニアのためのデータベース設計ゲームエンジニアのためのデータベース設計
ゲームエンジニアのためのデータベース設計
 
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をする
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をするSlack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をする
Slack + Hubot でお前の一番好きな二次元嫁キャラと一緒に仕事をする
 

Último

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+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...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Dark side of the reflect

  • 1. Copyright © DeNA Co.,Ltd. All Rights Reserved. Dark side of the reflect Masaki Hitonishi Common Support Services Dept. DeNA Co., Ltd.
  • 2. Copyright © DeNA Co.,Ltd. All Rights Reserved. About me  Masaki Hitonishi  Software Engineer ⁃ Golang Enthusiast ⁃ Contributor to Gin the framework ⁃ HTML5 Game Developer  twitter.com/@sairoutine  github.com/sairoutine
  • 3. Copyright © DeNA Co.,Ltd. All Rights Reserved. DeNA.go will be held!  https://dena.connpass.com/event/128034/  Join registration is acceptable until 5/21 (Tue) !
  • 4. Copyright © DeNA Co.,Ltd. All Rights Reserved. Today’s topic  Introduction to reflect  Building ORM by using reflect  reflect or code generation?
  • 5. Copyright © DeNA Co.,Ltd. All Rights Reserved. What is reflect?
  • 6. Copyright © DeNA Co.,Ltd. All Rights Reserved. golang’s reflect  Treats any types at runtime ⁃ Examines types ⁃ Creates and modifies it’s value  makes us enable to do 2 things ⁃ Finding variables types ⁃ Getting field information
  • 7. Copyright © DeNA Co.,Ltd. All Rights Reserved. reflect package  Provides the way to use reflect  Defines the important 2 types ⁃ reflect.Type ⁃ reflect.Value
  • 8. Copyright © DeNA Co.,Ltd. All Rights Reserved. reflect.Type  A Type represents golang’s type  An interface with methods to distinguish among types ⁃ Map? Struct? Slice? Function? ⁃ String? Int? Ptr?
  • 9. Copyright © DeNA Co.,Ltd. All Rights Reserved. reflect.Value  A value represents golang’s all value  It can hold a value of any type
  • 10. Copyright © DeNA Co.,Ltd. All Rights Reserved. Reason to use reflect  To manipulate dynamic types and values ⁃ Works with variables at runtime using information that didn’t exist when the program was written.  To get meta information through struct tag
  • 11. Copyright © DeNA Co.,Ltd. All Rights Reserved. Example of dynamic types and values
  • 12. Copyright © DeNA Co.,Ltd. All Rights Reserved. Example of struct tag information
  • 13. Copyright © DeNA Co.,Ltd. All Rights Reserved. Example of use case in the real world  ORM like gorm, xorm, gorp and so on... ⁃ Object Relational Mapper ⁃ Gets and sets the structure the user defined  JSON Encoder/Decoder ⁃ Parse any value to JSON value  etc...
  • 14. Copyright © DeNA Co.,Ltd. All Rights Reserved. Writing ORM with reflect
  • 15. Copyright © DeNA Co.,Ltd. All Rights Reserved. DeNA Game dept.  Using golang in some products  Example ⁃ Game server framework ⁃ Development workflow platform
  • 16. Copyright © DeNA Co.,Ltd. All Rights Reserved. Game server framework  Next generation server framework under development  Golang + GCP  Using Google Cloud Spanner as a backend database  Original ORM “Span” to treat Spanner
  • 17. Copyright © DeNA Co.,Ltd. All Rights Reserved. Development workflow platform  Named “Oyakata”  Written in golang  Using Noms as a backend database  Original ORM “Norm” to use Noms database
  • 18. Copyright © DeNA Co.,Ltd. All Rights Reserved. Noms  Decentralized database  https://github.com/attic-labs/noms  No-SQL  With Git like version control system  Commit/Merge/Diff and so on in database layer
  • 19. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm  ORM for Noms. ⁃ ORM is a library to convert data between incompatible type systems to do object- oriented programming.  Users can define their own model struct.  Maps their original struct to Noms data.  Create/Read/Update/Delete.
  • 20. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm
  • 21. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm Internal  Create/Update ⁃ Any struct to any data  Read ⁃ Any data to struct
  • 22. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm Internal
  • 23. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm Internal
  • 24. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm Internal
  • 25. Copyright © DeNA Co.,Ltd. All Rights Reserved. Norm Internal
  • 26. Copyright © DeNA Co.,Ltd. All Rights Reserved. Continue to use reflect?
  • 27. Copyright © DeNA Co.,Ltd. All Rights Reserved. Span  O/R Mapper for Google Spanner.  Users can define their own model struct.  Create/Read/Update/Delete.  Currently, It’s implemented by code generator, not by reflect.
  • 28. Copyright © DeNA Co.,Ltd. All Rights Reserved. Why stop using reflect?  Difficult to read source code ⁃ The reflect code tends to be complexity.  Performance issue ⁃ Reflect is slow  Now, Span generates CRUD code by parsing definition the users defines.
  • 29. Copyright © DeNA Co.,Ltd. All Rights Reserved. Pros/Cons  Pros ⁃ Even if struct field is changed, there is no need to regenerate code  Cons ⁃ The library code tends to be complexity ⁃ Reflect is slow  Norm is still using reflect approach, Span has changed to use code generation approach
  • 30. Copyright © DeNA Co.,Ltd. All Rights Reserved. Conclusions  There are some cases the golang’s reflect is efficient.  However, code with reflect is a little difficult to read.  Consider code generating approach by your use cases.  Compare user comfortable and code maintainability to decide either.

Notas del editor

  1. most of them can listen to understand English