Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Designing Auto Generated Codes

1 388 vues

Publié le

Roppongi.aar #2 で発表しました「自動生成されるコードの設計」スライド
http://roppongi-aar.connpass.com/event/21907/

Publié dans : Technologie
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Designing Auto Generated Codes

  1. 1. Designing Auto Generated Codes 17 Nov 2015 Roppongi.aar #2 @kikuchy
  2. 2. • Hiroshi Kikuchi (@kikuchy) • Belonging to , inc , Working on , inc (mixi group) • Making Dating App for Android • Strict review OJISAN Who am I
  3. 3. APT made our work reduced!! So, you use APT, and be happy!! \\٩( 'ω' )‫و‬ ////
  4. 4. … I was going to talk about like that, but
  5. 5. Oh, you are already using APT.
  6. 6. fin.
  7. 7. \(^o^)/
  8. 8. So, I ll talk about
  9. 9. Designing Auto Generated Codes
  10. 10. What is the best way to use Generated Code in our project? Please consider and discuss.
  11. 11. The Problem Make Us Wakeful
  12. 12. Case 1 (/2)
  13. 13. 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);
  14. 14. Alice changes Naming Rule of Generated Class. ex) (ClassName)$$Executor -> (ClassName)$$Doer
  15. 15. proguard-rules.pro ????
  16. 16. < Hey, I obfuscated your code! Proguard @ Production Build
  17. 17. Case 2 (/2)
  18. 18. 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);
  19. 19. Bob often asks you What s the name of Generated Classes and methods and constructor arguments and interfaces will use in Generated Code blablabla…
  20. 20. Why ask me repeatedly ? Why I have to remember invisible codes? Bob < https://www.flickr.com/photos/greeblie/2190709020/
  21. 21.  / / / /    / |  /    `、 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  :|                       , '   :::| :|  :| ` 、     ⊂ニ==ー‐-     , イ    ::::| :|  :|
  22. 22. hiding generated codes no reflection vs
  23. 23. Butter Knife pattern Dagger2 pattern vs
  24. 24. 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
  25. 25. Which we should adopt?
  26. 26. case by case
  27. 27. My Recommend: Dagger2 pattern
  28. 28. 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
  29. 29. No proguard, and save the team
  30. 30. https://www.flickr.com/photos/katrinasagemuller/3751402009/
  31. 31. Appendix 1: Auto code generation patterns
  32. 32. • 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
  33. 33. 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
  34. 34. Appendix 2: Episode
  35. 35. POJO ↓ Map<String, String>
  36. 36. https://www.flickr.com/photos/yoshimov/10256644/
  37. 37. public class UserSearchRequest { public EnumSet<UserKind> kind; public String freeWord; public int ageMax; … }
  38. 38. @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; …
  39. 39. 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
  40. 40. Yheaaaaaaaa \\٩( 'ω' )‫و‬ ////
  41. 41. Thank you for listening!
  42. 42. Question?
  43. 43. @kikuchy

×