$30 off During Our Annual Pro Sale. View Details »

I'm only MVC after all. Don't put your blame on me.

I'm only MVC after all. Don't put your blame on me.

"There are two ways of getting home; and one of them is to stay there.
The other is to walk round the whole world till we come back to the same
place"
~ G. K. Chesterton, The Everlasting Man

In 10 years of iOS presence on the market we've seen many changes in the SDK.
But Cocoa MVC... Feels untouched, even forgotten!
Maybe it's perfect...
Maybe it's rotted...
Who knows?
We can see that silence around this topic has driven many developers mad, so they've started inventing new architectures, and boasting about each one being better than the other, and of course being better than MVC.
I'd like to flip the coin and show you that MVC isn't the problem.

Mateusz Zając

December 07, 2017
Tweet

More Decks by Mateusz Zając

Other Decks in Programming

Transcript

  1. I'm only human MVC after all. Don't put your blame

    on me. 1
  2. Hi, I'm Mateusz! Mobile Tech Lead @Codete @cojoj 2

  3. “There are two ways of getting home...” https://www.wordonfire.org/wof-site/media/brchesterton2.jpg 3

  4. “...and one of them is to stay there.” https://www.wordonfire.org/wof-site/media/brchesterton2.jpg 4

  5. “The other is to walk round the whole world till

    we come back to the same place.” G. K. Chesterton, The Everlasting Man https://www.wordonfire.org/wof-site/media/brchesterton2.jpg 5
  6. Agenda » Historical Overview » Pros & Cons » Problems

    & Misbeliefs » Competitors » My Personal Approach (Optional) » Summary 6
  7. History https://www.nationalgeographic.com/content/dam/archaeologyandhistory/rights-exempt/history-magazine/ 2016/07-08/05-abu-simbel.jpg 7

  8. Xerox PARC California 1970s http://www.siliconvalleyguide.info/wp-content/uploads/2015/03/PARC-2.jpg 8

  9. Smalltalk 1972 » Object-Oriented » Class-based Inheritance » Dynamically Typed

    » Reflective » Message Driven https://cdn-images-1.medium.com/max/597/1*9qr-I3aJLr0IrM256gVIvg.jpeg 9
  10. 2nd most loved language of 2017!!! (Swift's 4th, yay!) 10

  11. Graphical User Interface http://images.computerhistory.org/revonline/images/500004472-03-01.jpg?w=600 11

  12. Xerox Alto Smalltalk + GUI https://www.parc.com/content/news/media-library/altochildren9.5x7.5.jpg 12

  13. DynaBook 1972 “A portable computer that should contain all data

    of interest to its owner/user. (...) The owner/user should be able to understand and write the programs.” https://blog.codinghorror.com/content/images/uploads/2008/11/6a0120a85dcdae970b0128777053a5970c-pi.png 13
  14. Whatcha talkin bout, Willis? 14

  15. Xerox PARC Learning Research Group http://worrydream.com/EarlyHistoryOfSmalltalk/Images/kiddikomp.png 15

  16. Model-View-Controller Trygve Reenskaug 1978 - 1979 http://static.cw.newsfront.no/files/styles/cropimagemain_large/public/dcx/reenskaug-trygve-1.jpg 16

  17. Original ideal MVC 17

  18. Model “Models represent knowledge. A model could be a single

    object (rather uninteresting), or it could be some structure of objects.” T. Reenskaug 18
  19. View “A view is a (visual) representation of its model.

    It would ordinarily highlight certain attributes of the model and suppress others.” T. Reenskaug 19
  20. Controller “A controller is a link between a user and

    the system. It provides the user with input by arranging for relevant views to present themselves in appropriate places on the screen.” T. Reenskaug 20
  21. Couldn't get any simpler... 21

  22. 22

  23. 23

  24. Pros & Cons http://www.pxleyes.com/images/contests/measuring-instruments/fullsize/Old-Scale-50a8e2e07b1a5_hires.jpg 24

  25. Pros » Simultaneous development » High cohesion » Low coupling

    » Ease of modification » Multiple views for a model 25
  26. Cons » Code navigability » Multi-artifact consistency » Pronounced learning

    curve 26
  27. MVC is not a silver bullet! 27

  28. Where's Apple in this whole story? 28

  29. But, there's one more thing... 29

  30. 30

  31. » Objective-C (incorporated) » Cocoa » Cocoa MVC » NeXT's

    WebObjects » NeXTSTEP » Mac OS X 31
  32. Cocoa MVC 32

  33. MVP: Model- View-Presenter The Taligent Programming Model for C++ and

    Java 33
  34. MVP == Cocoa MVC Presenter == Supervising Controller 34

  35. Pros & Cons http://www.pxleyes.com/images/contests/measuring-instruments/fullsize/Old-Scale-50a8e2e07b1a5_hires.jpg 35

  36. Pros » Logic can be moved from the view to

    the presenter/ supervising controller » It's easier to unit test UI, because of the presenter » UI and app logic can be developed independently » It breaks MVC's circularity! 36
  37. Cons » Effort » Presenter can easily become god class

    » There are multiple axes of the application 37
  38. “If we take NeXTStep 4 as the origin date for

    Cocoa’s current Model- View-Controller pattern then it is 20 years old this year” Matt Gallagher https://www.cocoawithlove.com/blog/mvc-and-cocoa.html 38
  39. Problems & Misbeliefs http://www.kubipet.com/data/out/19/iwp779816317-blackboard-wallpapers.jpg 39

  40. #1. “Mobile apps are now more complicated than they used

    to be, and MVC is too simple to handle their scale.” 40
  41. #2. “Cocoa MVC is poorly documented and lacks proper learning

    materials. It feels like Apple actually doesn't care about it anymore (but, have they ever?).” 41
  42. #3. “It's so easy to write an app right now,

    that carrying about such nuances as app architecture is a waste of time.” #4. “There are so many developers lacking the basic CS education, and they simply don't get why app architecture is important.” 42
  43. #5. “Architectures on other platforms are so well written and

    well thought, that we should also have something like this instead of this dead-simple Cocoa MVC.” 43
  44. Competitors https://www.ultimaterb.com/wp-content/uploads/2015/03/iStock_000015985266XXLarge-web.jpg 44

  45. Groups » Kinda supersets of MVC » Reactive » Unidirectional

    Dataflow » We can do it differently 45
  46. Kinda supersets of MVC » Model-View-Presenter » Model-View-ViewModel » VIPER

    46
  47. VIPER VIPER VIPER 47

  48. “Do you strictly follow VIPER architecture?” 48

  49. https://www.reddit.com/r/iOSProgramming/comments/5pcebg/viperhowstrictlydoyouguysfollowthisor/ 49

  50. “No. VIPER is what happens when former enterprise Java programmers

    invade the iOS world.” 50
  51. https://www.reddit.com/r/iOSProgramming/comments/5pcebg/viperhowstrictlydoyouguysfollowthisor/dcqa1uj/ 51

  52. Reactive » RxSwift/RxCocoa » ReactiveSwift/ReactiveCocoa » Cocoa Bindings 52

  53. “Bindings technology provides a means of keeping model and view

    values synchronized without you having to write a lot of glue code” https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/ WhatAreBindings.html 53
  54. 54

  55. Reactive in code // RxSwift with RxCocoa (I skipped disposing)

    viewModel.title.drive(skillTitleLabel.rx.text) // ReactiveCocoa with ReactiveSwift nameLabel.reactive.text <~ person.name // Hanson bind(viewModel.isLoadingData, to: view.showsActivityIndicator) // Bond textField.reactive.text.bind(to: label) 55
  56. Unidirectional dataflow » ReSwift » ReduxSwift » Katana » VueFlux

    56
  57. Redux-like architecture 57

  58. We can do it differently » Elm Architecture » React

    Native 58
  59. Elm-like architecture 59

  60. Ain't nobody got time for that! 60

  61. My Personal Approach http://www.bestphotosite.net/photos/23193280813765.jpg 61

  62. I'm ! for Cocoa MVC... 62

  63. But, I also like the idea of ViewModels... (Mostly because

    I use RxSwift) 63
  64. So, let's call it... MVC-ish! 64

  65. “I’m also guilty of using the term MVVM, but actually

    writing MVC code. I don’t mind it, though.” @thesunshinejr 65
  66. Łukasz Is Guilty, Too! 66

  67. Great minds think alike! ! (But I want my promised

    beer anyway) 67
  68. 68

  69. But how do you navigate? 69

  70. 70

  71. Wait, what? 71

  72. Back to the navigation... 72

  73. 73

  74. Coordinators, Flow controllers 74

  75. 75

  76. What the heck with Reactive? 76

  77. Informing others » KVO » Notification Center » Delegates »

    Target-Action » Closures » ? 77
  78. Observable<T> 78

  79. “Reactive MVVM/MVC with Coordinators and Routing” 79

  80. 80

  81. Summary http://i0.wp.com/bossfight.co/wp-content/uploads/2015/03/boss-fight-stock-images-photos-free-photography-pencil- paper.jpg 81

  82. MVC introduces complexity. Though, it's supersets double and triple it.

    82
  83. Be flexible, you don't have to use one architecture! 83

  84. Naming Naming Naming x100 84

  85. Stick to Apple technologies 85

  86. Think! 86

  87. Before you blame something MVC, think about it even deeper.

    87
  88. Improvise. Adapt. Overcome 88

  89. 89

  90. 90

  91. Questions? 91