Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laziness-Driven Development in iOS - Mobile Makers Chicago, April 2016

Laziness-Driven Development in iOS - Mobile Makers Chicago, April 2016

Spring 2016 edition of my talk on how Laziness is secretly the best way to code.

Links galore at the end!

Ellen Shapiro
PRO

April 14, 2016
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. Laziness-Driven
    Development in iOS
    Mobile Makers Chicago | April 2016 | by Ellen Shapiro
    spothero.com | justhum.com | designatednerd.com | @designatednerd

    View Slide

  2. What is Laziness-
    Driven Development?

    View Slide

  3. The laziness long game.

    View Slide

  4. What is lazy, but is NOT
    Laziness-Driven Development?

    View Slide

  5. Copy Pasta

    View Slide

  6. Code without tests

    View Slide

  7. Code which is fast to write,
    but impossible to read

    View Slide

  8. Using libraries for
    every possible task

    View Slide

  9. What is Laziness-Driven
    Development?
    » Smart reuse of code
    » Clear, Readable code
    » Removal of Stringly-typed code
    » Making smart decisions today to save yourself time
    and heartache tomorrow

    View Slide

  10. The primary philosophy of
    Laziness-Driven
    Development:

    View Slide

  11. Eventually, You're going to
    screw something up

    View Slide

  12. only screw it up once.
    Then, you only have to
    fix it once.

    View Slide

  13. Introductory
    Laziness-Driven development:
    Inheritance & MV*

    View Slide

  14. Keep code separated
    by its purpose

    View Slide

  15. Keep code with the
    same purpose
    centralized

    View Slide

  16. Aren't those just
    Best Practices?

    View Slide

  17. YES

    View Slide

  18. YEs, but they are
    only the beginning

    View Slide

  19. Beginning
    Laziness-Driven development:
    Constants,
    Structs
    and Enums

    View Slide

  20. Stringly-typed code
    Sucks

    View Slide

  21. View Slide

  22. espeshuly if u cant spel...
    (this is from just one repo)

    View Slide

  23. It's the worst

    View Slide

  24. String Constants:
    The Cure For
    Speling Problums

    View Slide

  25. Before:

    View Slide

  26. After:

    View Slide

  27. Lazy Swift Ninja:

    View Slide

  28. constants: Not just for strings
    self.viewWidth = 74;
    vs.
    self.viewWidth = kProfileViewWidth;

    View Slide

  29. Enums: Even
    lazier constants

    View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. Beginning
    Laziness-Driven development:
    Comment And Name
    Clearly

    View Slide

  37. readability

    View Slide

  38. "programs must be written for
    people to read,
    and only incidentally for
    machines to execute."

    View Slide

  39. Variable naming
    BAD:
    UIView *v var v = UIView()
    CGPoint pt var pt = CGPoint(1, 1)
    BETTER:
    UIView *profileView var profileView = UIView()
    CGPoint profileOrigin var profileOrigin = CGPoint(1, 1)

    View Slide

  40. Method Naming
    Objective-C:
    extremelyLongAndDescriptiveMethodOnLabel:label
    withParameter:parameter
    andCompletionBlock:completion
    Swift:
    shortButClearMethodOnLabel(label, param, completion)

    View Slide

  41. View Slide

  42. Benefits
    of clear naming

    View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. Some people say:
    "Comments Lie, Code Doesn't"

    View Slide

  47. If you update code without
    updating comments,
    you're doing it
    wrong

    View Slide

  48. //TODO:
    Write better comments

    View Slide

  49. What < Why

    View Slide

  50. Leave The Campsite Code
    cleaner
    than you found it

    View Slide

  51. the goal of good comments
    and clear naming is the same:
    Future laziness for you

    View Slide

  52. Beginning
    Laziness-Driven development:
    Unit Testing

    View Slide

  53. Testing stuff manually
    is a pain.
    (Repeat ad nauseam
    until it's fixed)

    View Slide

  54. Remember:
    Your computer is an
    awesome robot
    you can use to do your
    evil bidding

    View Slide

  55. View Slide

  56. View Slide

  57. View Slide

  58. Intermediate
    Laziness-Driven development:
    Categories &
    Extensions

    View Slide

  59. Adding functionality
    to existing objects
    (and also to structs in Swift)

    View Slide

  60. Objective-C:
    Categories
    UIView+XYZApp:
    - (void)xyz_circleify
    {
    self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2;
    self.clipsToBounds = YES;
    }

    View Slide

  61. Watch for method
    name collsions

    View Slide

  62. Swift: Extensions
    MyViewExtension:
    extension UIView {
    public func xyz_circleify() {
    layer.cornerRadius = CGRectGetWidth(frame) / 2
    clipsToBounds = true
    }
    }

    View Slide

  63. Watch for method name collsions
    even in Swift

    View Slide

  64. Intermediate
    Laziness-Driven development:
    Laziness-Enhancing
    Tools

    View Slide

  65. Alcatraz: Xcode
    plugins for all!

    View Slide

  66. Plugins Before Alcatraz
    » Download project
    » Build, run, install,
    » Restart Xcode,
    » Do the hokey pokey and turn yourself about.
    » Uninstall by hunting down obscure folder and then
    forgetting what the hell you were doing in there.

    View Slide

  67. Plugins AFTER Alcatraz
    » Push button, install plugin.
    » Push other button to see plugin page.
    » Search plugins easily.
    » Push button, uninstall plugin.
    !

    View Slide

  68. Laziness-Enhancing
    Plugins

    View Slide

  69. VVDocumenter

    View Slide

  70. xTODO

    View Slide

  71. BBFullIssue
    Navigator

    View Slide

  72. SCXcodeMiniMap

    View Slide

  73. View Slide

  74. A place for ideas

    View Slide

  75. Get a better idea
    of what is simple
    and what is not

    View Slide

  76. MOGenerator - Make Core Data
    less painful

    View Slide

  77. MOGenerator Kills
    Stringly-Typed Code
    just to watch it die

    View Slide

  78. Lazier Code with MOGenerator

    View Slide

  79. Advanced
    Laziness-Driven development:
    UI Testing

    View Slide

  80. KIF

    View Slide

  81. KIF

    View Slide

  82. Xcode 7 UI TESTING

    View Slide

  83. All UI testing

    View Slide

  84. UI Testing Gotchas

    View Slide

  85. Advanced
    Laziness-Driven development:
    Adopting laziness techniques
    from other languges

    View Slide

  86. Android

    View Slide

  87. View Slide

  88. View Slide

  89. Figure out how to take the theory
    and use it in an iOS-friendly way

    View Slide

  90. Caution:
    Take care that you're bringing
    things over as supplements.

    View Slide

  91. Don't try to force a new
    language or platform to
    fit
    what you already know

    View Slide

  92. Advanced
    Laziness-Driven development:
    Writing Your own
    Laziness-Enhancing Tools

    View Slide

  93. When Should You
    write Your own tools?

    View Slide

  94. View Slide

  95. (Achtung! shameless
    self-promotion)

    View Slide

  96. My Experience
    Writing Tools

    View Slide

  97. Cat2Cat
    Asset Catalog To Category
    Instead of writing:
    [UIImage imageNamed:@"My Image Name"];
    you can write:
    [UIImage ac_My_Image_Name];

    View Slide

  98. How is this lazier?

    View Slide

  99. View Slide

  100. XcodeautoBasher

    View Slide

  101. View Slide

  102. in conclusion
    » Centralize your code, make it easy to read, and
    keep it separated by purpose, so it's easy to fix.
    » Get rid of stringly-typed code so it's harder to
    break in the first place.
    » Use the tools other people have built to enhance
    your laziness, or build new tools yourself.
    » Best practices are secretly the lazy way to code.

    View Slide

  103. Questions?

    View Slide

  104. Thank you!

    View Slide

  105. Links
    » Alcatraz: http://alcatraz.io/
    » Cocoa Controls: https://www.cocoacontrols.com/
    » Swift In Practice: https://developer.apple.com/
    videos/play/wwdc2015-411/
    » CountableIntEnum: https://gist.github.com/
    LoganWright/c8a26b1faf538e40f747
    » Swift API Design Guidelines: https://swift.org/
    documentation/api-design-guidelines

    View Slide

  106. Code Generation Tools
    » MOGenerator: https://github.com/rentzsch/
    mogenerator
    » Cat2Cat: https://github.com/vokal/Cat2Cat
    » objc codegenutils: https://github.com/square/objc-
    codegenutils/

    View Slide

  107. Alcatraz Plugins
    » https://github.com/vokal/XcodeAutoBasher
    » https://github.com/onevcat/VVDocumenter-Xcode
    » https://github.com/trawor/XToDo
    » https://github.com/neonichu/BBUFullIssueNavigator
    » https://github.com/stefanceriu/SCXcodeMiniMap

    View Slide

  108. image credits
    » Luca Nebuloni, Pasta with finocciona: https://
    www.flickr.com/photos/nebulux/10708289086
    » Tom Bech, Eurasian Wolf: https://www.flickr.com/
    photos/viatorius/9358589025
    » Michael D Beckwith, The Leeds Library: https://
    www.flickr.com/photos/118118485@N05/16438065636/

    View Slide