SlideShare a Scribd company logo
Designing
Auto Generated Codes
17 Nov 2015 Roppongi.aar #2
@kikuchy
• Hiroshi Kikuchi (@kikuchy)
• Belonging to , inc , Working on , inc (mixi group)
• Making Dating App for Android
• Strict review OJISAN
Who am I
APT made our work
reduced!!
So, you use APT,
and be happy!!
\\٩( 'ω' )‫و‬ ////
… I was going to talk about
like that, but
Designing Auto Generated Codes
Designing Auto Generated Codes
Oh, you are already using
APT.
fin.
\(^o^)/
So, I ll talk about
Designing
Auto Generated Codes
What is the best way to use
Generated Code in our project?
Please consider and discuss.
The Problem
Make Us Wakeful
Case 1 (/2)
If you make an awesome library
hiding generated codes…
// Fields
@ExecuteSomething
String foo;
// Executor class “ThisClass$$Executor” is
generated.
// My library loads executor class automatically!
AwesomeLibrary.execute(this);
Alice changes Naming Rule
of Generated Class.
ex) (ClassName)$$Executor -> (ClassName)$$Doer
proguard-rules.pro ????
< Hey, I obfuscated your code!
Proguard
@ Production Build
Designing Auto Generated Codes
Designing Auto Generated Codes
Designing Auto Generated Codes
Case 2 (/2)
If you make awesome proguard-safe library…
// Fields
@ExecuteSomething
String foo;
// Executor class “ThisClassExecutor” is
generated.
// There are no reflection, no
ClassNotFoundException!!
new ThisClassExecutor().execute(this);
Bob often asks you
What s the name of Generated Classes and methods and constructor arguments and
interfaces will use in Generated Code blablabla…
Why ask me repeatedly ?
Why I have to remember
invisible codes?
Bob
<
https://www.flickr.com/photos/greeblie/2190709020/
 / / / /    / |  /    `、 i  !  |i   i  ,  l
  / / //   /   | /       | |  |  l !  i  |  |
`/ー- 、 / /    | /       | l   |  l l  !  !  i
/ ,,,,- ニ=x- 、_   !/       |i  _, +十'イ  i  !  !
''" / :;;r jヽ ` ̄  リ      ,, -=、 レ | / /  :|
 /:::::;;;;;;;:`::::::l          / :;;r ヽヽ   |/| /   :!
 |::::::::;;;;;;;;:::::::l             l:::;;;;;` ::| l  //    :!
  '、:_ ''''  ノ          l  '''' ノ |  /    :|
::::::::..  ̄               ` ー '   ,'      :|
::::::::::::            ,    ..::::::::::::..l  .:|   :|
::::::::::                :::::::::::::::::::|  :|   :| Mmmm…
                    ::::::::::::::: l .:|  l  :|
                         /  :| :l  :|
                      , '   :::| :|  :|
` 、     ⊂ニ==ー‐-     , イ    ::::| :|  :|
hiding generated codes
no reflection
vs
Butter Knife pattern
Dagger2 pattern
vs
Compare patterns
Butter Knife pattern
(hiding generated codes)
Dagger2 pattern

(no reflection)
How to load generated
codes
Library dose everything Developers have to import
Proguard configuration is needed not needed
Developers have to learn only usage of library
+ generated class naming
rules
Type-Safe No Yes
Which we should adopt?
case by case
My Recommend:
Dagger2 pattern
Don’t forget
proguard conf?
Start
↓
Like beautiful
API?
Is not solidity
app necessary?
→ →
Yes
No↓
“Dagger2” pattern
→
No
Yes
↓ No↓
“Dagger2” pattern “Dagger2” pattern
“Butter
Knife”
pattern
Yes
No proguard,
and save the team
https://www.flickr.com/photos/katrinasagemuller/3751402009/
Appendix 1:
Auto code generation patterns
• Java Annotated Source Codes
• Using APT.
• ex) Dagger2, ButterKinfe, JsonPullParser, etc…
• Externals
• Gradle Task (depends on compileJava task)
• ex ) R.java, genum (← I m developing now!!!!!!!!!!!)
Source of Source Codes
Generated Class Depends on…
• Only Interface
• MyOwnInterface instance = new GeneratedClass();
• ex) Dagger2, (Retrofit)
• Library Classes
• LibrarySuppliedBase instance = new GeneratedClass();
• ex) Shillelagh, etc…
• Nope ¦¦ Unknown
• (Generated classes are hidden.)
• ex) ButterKnife, IntentBuilder, DeepLinkDispatch
Appendix 2:
Episode
POJO
↓
Map<String, String>
Designing Auto Generated Codes
https://www.flickr.com/photos/yoshimov/10256644/
public class UserSearchRequest {
public EnumSet<UserKind> kind;
public String freeWord;
public int ageMax;
…
}
@ToQueryMap
public class UserSearchRequest {
@QueryParam(name = “kind”,
adapter = UserKindAdapter.class)
public EnumSet<UserKind> kind;
@QueryParam(name = “free_word”,
adapter = StringAdapter.class)
public String freeWord;
@QueryParam(name = “age_max”,
adapter = IntAdapter.class)
public int ageMax;
…
public final class UserSearchRequestSerializer {
public Map<String, String>
serialize(UserSearchRequest request) {
Map<String, String> map = new Map<>();
map.put(“kind”,
userKindAdapter.adapt(request.kind));
map.put(“free_word”,
stringAdapter.adapt(request.freeWord));
map.put(“age_max”,
intAdapter.adapt(request.ageMax));
…
return map;
}
GENERATED
Yheaaaaaaaa
\\٩( 'ω' )‫و‬ ////
Thank you for listening!
Question?
@kikuchy

More Related Content

PDF
Android development at mercari 2015
PDF
Debot android debugging library
PDF
プレゼンビフォアアフタ
PDF
Developing better debug_components
PDF
Continous UI testing with Espresso and Jenkins
PPTX
Exploring App Compat
PPTX
Exploring Android Studio
PPTX
Android Studio vs Eclipse: What are the main differences?
Android development at mercari 2015
Debot android debugging library
プレゼンビフォアアフタ
Developing better debug_components
Continous UI testing with Espresso and Jenkins
Exploring App Compat
Exploring Android Studio
Android Studio vs Eclipse: What are the main differences?

What's hot (20)

PDF
I Love APIs - Oct 2015
PPTX
SONY BBS - React Native
PPTX
What is Swagger?
PPTX
Comparison between Eclipse and Android Studio for Android Development
PDF
"I have a framework idea" - Repeat less, share more.
PPTX
Automation is Easy! (python version)
PDF
Head first android apps dev tools
PDF
Get started with AAR
PDF
Introduction to Flutter - truly crossplatform, amazingly fast
PPTX
Swagger - make your API accessible
PPTX
Creating iOS and Android Apps with Visual Studio and C#
PPTX
Angular TS(typescript)
PDF
Quick run in with Swagger
PPTX
Building your Own Mobile Enterprise Application: It’s Not as Hard as You Migh...
PDF
Going Native With React
PDF
Get Your Node.js API Swaggering with OpenAPI Spec
PDF
Android Dev Conference 2017 - Produtividade Ninja no Android Studio
PDF
Efficient Automated Test Creation With Selenium IDE Plugins
PDF
React Native - Getting Started
ZIP
From IDE to Selenium 2
I Love APIs - Oct 2015
SONY BBS - React Native
What is Swagger?
Comparison between Eclipse and Android Studio for Android Development
"I have a framework idea" - Repeat less, share more.
Automation is Easy! (python version)
Head first android apps dev tools
Get started with AAR
Introduction to Flutter - truly crossplatform, amazingly fast
Swagger - make your API accessible
Creating iOS and Android Apps with Visual Studio and C#
Angular TS(typescript)
Quick run in with Swagger
Building your Own Mobile Enterprise Application: It’s Not as Hard as You Migh...
Going Native With React
Get Your Node.js API Swaggering with OpenAPI Spec
Android Dev Conference 2017 - Produtividade Ninja no Android Studio
Efficient Automated Test Creation With Selenium IDE Plugins
React Native - Getting Started
From IDE to Selenium 2
Ad

Viewers also liked (11)

PDF
Upload a screenshot to Slack
DOCX
Administrasi kurikulum
PDF
Android Clean Architecture for Dummies
PPT
Administrasi ppt
PPTX
Python勉強会in 長野 オープニング
PPTX
Uso di Slideshare
PPTX
DjangoでさくっとWeb アプリケーション開発をする話
PDF
ディープラーニングハンズオンを準備して学んだこと
PDF
「長野で語るStapyのビジョン」
PDF
Slide Wars- The Force Sleeps
PDF
Dear NSA, let me take care of your slides.
Upload a screenshot to Slack
Administrasi kurikulum
Android Clean Architecture for Dummies
Administrasi ppt
Python勉強会in 長野 オープニング
Uso di Slideshare
DjangoでさくっとWeb アプリケーション開発をする話
ディープラーニングハンズオンを準備して学んだこと
「長野で語るStapyのビジョン」
Slide Wars- The Force Sleeps
Dear NSA, let me take care of your slides.
Ad

Similar to Designing Auto Generated Codes (14)

PDF
Code Generation idioms with Xtend
PDF
Jvm internals
PPTX
Java byte code in practice
PPTX
How to build Sdk? Best practices
KEY
Codegeneration Goodies
PDF
Idiomatic Gradle Plugin Writing
ODP
Iterative and-agile-codegen
PDF
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
PPTX
2010 06-24 karlsruher entwicklertag
PDF
Using the Groovy Ecosystem for Rapid JVM Development
PDF
Developing Useful APIs
PDF
Recipes to build Code Generators for Non-Xtext Models with Xtend
PDF
Xtext Webinar
PPT
Ui Modeling In Action With PMF, e4(XWT) And EGF
Code Generation idioms with Xtend
Jvm internals
Java byte code in practice
How to build Sdk? Best practices
Codegeneration Goodies
Idiomatic Gradle Plugin Writing
Iterative and-agile-codegen
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
2010 06-24 karlsruher entwicklertag
Using the Groovy Ecosystem for Rapid JVM Development
Developing Useful APIs
Recipes to build Code Generators for Non-Xtext Models with Xtend
Xtext Webinar
Ui Modeling In Action With PMF, e4(XWT) And EGF

More from Hiroshi Kikuchi (16)

PDF
Android Developer Toolsのバグを見つけて直してもらった話
PDF
今更聞けない? Androidのテストのいろは
PDF
新規Androidアプリ開発において何より大切なこと
PDF
モバイルアプリ開発をグッと楽にするKotlinの便利なところ3選
PDF
JUnit5とAndroidのテスト
PDF
KotlinJSって正直どうなん
PDF
画面状態を抽象化してテスタブル設計ライフを送ろう
PDF
テストコードをアプリケーションコードと同じ階層に置きたい
PDF
Android thingsやってみた
PDF
どうしてコードはレガシーになるのか
PDF
Androidの世界を離れて異文化留学してみた
PDF
なるべくコードを書かないAndroid開発
PPTX
開発チームにKotlinを導入した話
PDF
3分で作る Kotlin Friendly な API
PPTX
C#でiPhone & Androidアプリ!
PPTX
Ideatter : Tech-on2011決勝でのプレゼン資料
Android Developer Toolsのバグを見つけて直してもらった話
今更聞けない? Androidのテストのいろは
新規Androidアプリ開発において何より大切なこと
モバイルアプリ開発をグッと楽にするKotlinの便利なところ3選
JUnit5とAndroidのテスト
KotlinJSって正直どうなん
画面状態を抽象化してテスタブル設計ライフを送ろう
テストコードをアプリケーションコードと同じ階層に置きたい
Android thingsやってみた
どうしてコードはレガシーになるのか
Androidの世界を離れて異文化留学してみた
なるべくコードを書かないAndroid開発
開発チームにKotlinを導入した話
3分で作る Kotlin Friendly な API
C#でiPhone & Androidアプリ!
Ideatter : Tech-on2011決勝でのプレゼン資料

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The AUB Centre for AI in Media Proposal.docx
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Designing Auto Generated Codes

  • 1. Designing Auto Generated Codes 17 Nov 2015 Roppongi.aar #2 @kikuchy
  • 2. • Hiroshi Kikuchi (@kikuchy) • Belonging to , inc , Working on , inc (mixi group) • Making Dating App for Android • Strict review OJISAN Who am I
  • 3. APT made our work reduced!! So, you use APT, and be happy!! \\٩( 'ω' )‫و‬ ////
  • 4. … I was going to talk about like that, but
  • 7. Oh, you are already using APT.
  • 10. So, I ll talk about
  • 12. What is the best way to use Generated Code in our project? Please consider and discuss.
  • 15. If you make an awesome library hiding generated codes… // Fields @ExecuteSomething String foo; // Executor class “ThisClass$$Executor” is generated. // My library loads executor class automatically! AwesomeLibrary.execute(this);
  • 16. Alice changes Naming Rule of Generated Class. ex) (ClassName)$$Executor -> (ClassName)$$Doer
  • 18. < Hey, I obfuscated your code! Proguard @ Production Build
  • 23. If you make awesome proguard-safe library… // Fields @ExecuteSomething String foo; // Executor class “ThisClassExecutor” is generated. // There are no reflection, no ClassNotFoundException!! new ThisClassExecutor().execute(this);
  • 24. Bob often asks you What s the name of Generated Classes and methods and constructor arguments and interfaces will use in Generated Code blablabla…
  • 25. Why ask me repeatedly ? Why I have to remember invisible codes? Bob < https://www.flickr.com/photos/greeblie/2190709020/
  • 26.  / / / /    / |  /    `、 i  !  |i   i  ,  l   / / //   /   | /       | |  |  l !  i  |  | `/ー- 、 / /    | /       | l   |  l l  !  !  i / ,,,,- ニ=x- 、_   !/       |i  _, +十'イ  i  !  ! ''" / :;;r jヽ ` ̄  リ      ,, -=、 レ | / /  :|  /:::::;;;;;;;:`::::::l          / :;;r ヽヽ   |/| /   :!  |::::::::;;;;;;;;:::::::l             l:::;;;;;` ::| l  //    :!   '、:_ ''''  ノ          l  '''' ノ |  /    :| ::::::::..  ̄               ` ー '   ,'      :| ::::::::::::            ,    ..::::::::::::..l  .:|   :| ::::::::::                :::::::::::::::::::|  :|   :| Mmmm…                     ::::::::::::::: l .:|  l  :|                          /  :| :l  :|                       , '   :::| :|  :| ` 、     ⊂ニ==ー‐-     , イ    ::::| :|  :|
  • 27. hiding generated codes no reflection vs
  • 29. Compare patterns Butter Knife pattern (hiding generated codes) Dagger2 pattern
 (no reflection) How to load generated codes Library dose everything Developers have to import Proguard configuration is needed not needed Developers have to learn only usage of library + generated class naming rules Type-Safe No Yes
  • 30. Which we should adopt?
  • 33. Don’t forget proguard conf? Start ↓ Like beautiful API? Is not solidity app necessary? → → Yes No↓ “Dagger2” pattern → No Yes ↓ No↓ “Dagger2” pattern “Dagger2” pattern “Butter Knife” pattern Yes
  • 36. Appendix 1: Auto code generation patterns
  • 37. • Java Annotated Source Codes • Using APT. • ex) Dagger2, ButterKinfe, JsonPullParser, etc… • Externals • Gradle Task (depends on compileJava task) • ex ) R.java, genum (← I m developing now!!!!!!!!!!!) Source of Source Codes
  • 38. Generated Class Depends on… • Only Interface • MyOwnInterface instance = new GeneratedClass(); • ex) Dagger2, (Retrofit) • Library Classes • LibrarySuppliedBase instance = new GeneratedClass(); • ex) Shillelagh, etc… • Nope ¦¦ Unknown • (Generated classes are hidden.) • ex) ButterKnife, IntentBuilder, DeepLinkDispatch
  • 43. public class UserSearchRequest { public EnumSet<UserKind> kind; public String freeWord; public int ageMax; … }
  • 44. @ToQueryMap public class UserSearchRequest { @QueryParam(name = “kind”, adapter = UserKindAdapter.class) public EnumSet<UserKind> kind; @QueryParam(name = “free_word”, adapter = StringAdapter.class) public String freeWord; @QueryParam(name = “age_max”, adapter = IntAdapter.class) public int ageMax; …
  • 45. public final class UserSearchRequestSerializer { public Map<String, String> serialize(UserSearchRequest request) { Map<String, String> map = new Map<>(); map.put(“kind”, userKindAdapter.adapt(request.kind)); map.put(“free_word”, stringAdapter.adapt(request.freeWord)); map.put(“age_max”, intAdapter.adapt(request.ageMax)); … return map; } GENERATED
  • 47. Thank you for listening!