Building SDKs - The Kotlin Way

Building SDKs - The Kotlin Way

by Jossi Wolf
presented on August 30, 2019 @Kotlin/Everywhere Hamburg

C67d4b2a0b74214c56b23969177e743c?s=128

Kotlin User Group Hamburg

August 30, 2019
Tweet

Transcript

  1. None
  2. None
  3. None
  4. None
  5. Project Manager Developer Hey could you ship the new SDK

    version?
  6. Project Manager Developer Hey could you ship the new SDK

    version? S-s-sure…
  7. $ gradlew sdk:assembleRelease $ building… $ … $ # 10

    hours later
  8. 3. Blah blah bla 2. Bla blah bla 1. Blah

    blah blah RELEASE NOTES
  9. 4. EXPERIMENTAL APIs. They are subject to change and not

    final!!! 3. Blah blah bla 2. Bla blah bla 1. Blah blah blah RELEASE NOTES
  10. Project Manager Developer Cool, thanks Here’s the new Version! SDK

  11. 4. APIs have been removed. 3. Blah blah bla 2.

    Bla blah bla 1. Blah blah blah RELEASE NOTES
  12. Project Manager Developer Cool, thanks Here’s the new Version! SDK

  13. Slack Message PROJECT MANAGER $CUSTOMER JUST CALLED THEY HAVE A

    BUILD ERROR WITH THE NEW SDK VERSION CAN YOU FIX THAT NOW PLS Friday, 9PM
  14. You: Have they read the release notes? PM: I’ll ask

    ... PM: No
  15. @Experimental @Deprecated

  16. @Target(ANNOTATION_CLASS) public annotation class Experimental(val level: Level = Level.ERROR) {

    public enum class Level { WARNING, ERROR, } }
  17. @Target(ANNOTATION_CLASS) public annotation class Experimental(val level: Level = Level.ERROR) {

    public enum class Level { WARNING, ERROR, } }
  18. @Target(ANNOTATION_CLASS) public annotation class Experimental(val level: Level = Level.ERROR) {

    public enum class Level { WARNING, ERROR, } }
  19. @Experimental annotation class ExperimentalCatPicturesAPI

  20. class CatPicturesAPI { /** * Experimental in case cats overtake

    the planet and * demand pets and treats in exchange for cat pictures */ @ExperimentalCatPicturesAPI fun getCatPicture(): CatPicture = CatPicture() }
  21. fun doCatPictureAPIStuff() { val catPicturesAPI = CatPicturesAPI() catPicturesAPI.getCatPicture() } This

    API is experimental and its usage must be marked with @UseExperimental.
  22. @ExperimentalCatPicturesAPI fun doCatPictureAPIStuff() { val catPicturesAPI = CatPicturesAPI() catPicturesAPI.getCatPicture() }

  23. @UseExperimental(ExperimentalCatPicturesAPI::class) fun doCatPictureAPIStuff() { val catPicturesAPI = CatPicturesAPI() catPicturesAPI.getCatPicture() }

  24. Productive Developer

  25. Project Man Developer

  26. Project Manager Developer

  27. Project Manager Developer

  28. Project Manager Developer

  29. Project Manager Developer Hey could you ship the new SDK

    version?
  30. Project Manager Developer Hey could you ship the new SDK

    version? S-s-sure…
  31. 4. APIs have been deprecated. 3. Blah blah bla 2.

    Bla blah bla 1. Blah blah blah RELEASE NOTES
  32. Project Manager Developer Cool, thanks Here’s the new Version! SDK

    Contains deprecated APIs
  33. Project Manager Cool, thanks SDK User Here’s the new Version!

    SDK Contains deprecated APIs
  34. BUILD ERROR SDK User SDK *updates SDK version* *runs Gradle

    build*
  35. /** * Marks the annotated declaration as deprecated. */ TYPEALIAS)

    annotation class Deprecated( val message: String, val replaceWith: ReplaceWith = ReplaceWith(""), val level: DeprecationLevel = DeprecationLevel.WARNING )
  36. @Deprecated(“This is a legacy API. Please use the new CatPicturesAPI

    instead.") class LegacyCatPictureAPI { fun getCatPicture(): CatPicture = CatPicture() }
  37. val api = LegacyCatPictureAPI()

  38. /** * Marks the annotated declaration as deprecated. */ TYPEALIAS)

    annotation class Deprecated( val message: String, val replaceWith: ReplaceWith = ReplaceWith(""), val level: DeprecationLevel = DeprecationLevel.WARNING )
  39. annotation class ReplaceWith( val expression: String, vararg val imports: String

    )
  40. @Deprecated( "This is a legacy API. Please use the new

    CatPicturesAPI instead.", ReplaceWith("CatPicturesAPI") ) class LegacyCatPictureAPI { fun getCatPicture(): CatPicture = CatPicture() }
  41. @Deprecated( "This is a legacy API. Please use the new

    CatPicturesAPI instead.", ReplaceWith("CatPicturesAPI") ) class LegacyCatPictureAPI { fun getCatPicture(): CatPicture = CatPicture() }
  42. val api = LegacyCatPictureAPI() Replace with ‘CatPicturesAPI’

  43. val api = LegacyCatPictureAPI() Replace with ‘CatPicturesAPI’ Alt + Enter

  44. val api = CatPicturesAPI() ✔Occurrence Replaced!

  45. class Laboratory { fun getRandommChemical(): Chemical = randomExperiment + randomExperiment

    + explosive }
  46. class Laboratory { @Deprecated( "Typo in here. Please use getRandomChemical

    instead.", ReplaceWith("getRandomChemical") ) fun getRandommChemical(): Chemical = randomExperiment + randomExperiment + explosive }
  47. class Laboratory { @Deprecated( "Typo in here. Please use getRandomChemical

    instead.", ReplaceWith("getRandomChemical") ) fun getRandommChemical(): Chemical = randomExperiment + randomExperiment + explosive fun getRandomChemical(): Chemical = randomExperiment + randomExperiment + explosive }
  48. class Laboratory { @Deprecated( "Typo in here. Please use getRandomChemical

    instead.", ReplaceWith("getRandomChemical") ) fun getRandommChemical(): Chemical = getRandomChemical() fun getRandomChemical(): Chemical = randomExperiment + randomExperiment + explosive }
  49. class CatPicturesAPI { /** * Experimental in case cats overtake

    the planet and * demand pets and treats in exchange for cat pictures */ @ExperimentalCatPicturesAPI fun getCatPicture(): CatPicture = CatPicture() }
  50. class CatPictureAPI { /** * Experimental in case cats overtake

    the planet and * demand pets and treats in exchange for cat pictures */ @ExperimentalCatPicturesAPI fun getCatPicture(): CatPicture = CatPicture() }
  51. @Deprecated( message = "CatPicturesAPI has been renamed to CatPictureAPI“, replaceWith

    = ReplaceWith("CatPictureAPI") ) typealias CatPicturesAPI = CatPictureAPI
  52. None
  53. SDK

  54. interface SDKCapabilities { ... } class ArtboardSDK: SDKCapabilities { //It'll

    become super bloated }
  55. interface CanvasCapabilities interface SDKCapabilities: CanvasCapabilities class ArtboardSDK: SDKCapabilities { val

    canvasManager = CanvasManager() override fun draw() = canvasManager.draw() }
  56. interface CanvasCapabilities interface SDKCapabilities: CanvasCapabilities class ArtboardSDK: SDKCapabilities { val

    canvasManager = CanvasManager() override fun draw() = canvasManager.draw() }
  57. interface CanvasCapabilities interface SDKCapabilities: CanvasCapabilities class ArtboardSDK: SDKCapabilities { val

    canvasManager = CanvasManager() override fun draw() = canvasManager.draw() }
  58. interface CanvasCapabilities interface SDKCapabilities: CanvasCapabilities class CanvasManager: CanvasCapabilities class ArtboardSDK:

    SDKCapabilities, CanvasCapabilities by CanvasManager()
  59. interface CanvasCapabilities interface SDKCapabilities: CanvasCapabilities class CanvasManager: CanvasCapabilities class ArtboardSDK:

    SDKCapabilities, CanvasCapabilities by CanvasManager()
  60. None
  61. None
  62. None