Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Develop Maintainable Apps - edUiConf

308 views

Published on

Great Android apps only include what's needed to achieve the goals of the product, not enhance the resume of the developer. What’s more, the more maintainable an application is, the more likely it will have increased user satisfaction and decreased time to market.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Develop Maintainable Apps - edUiConf

  1. 1. Develop Maintainable Apps @brwngrldev
  2. 2. What’s our job? A. Make apps B. Make apps that work C. Make great apps! @brwngrldev
  3. 3. What’s our job? Make great apps! @brwngrldev
  4. 4. The tools… Libraries 1 Domain Design 2 Code Quality 3 Testing 4 @brwngrldev
  5. 5. Choosing the Right Library
  6. 6. So many options
  7. 7. What to consider Amazing App ! Documentation Project Stability Fulfills a Need @brwngrldev
  8. 8. Example
  9. 9. So you need images… Volley ! Fresco ! Glide ! Picasso !
  10. 10. Documentations Volley !
  11. 11. Documentations W Project Stability Volley !
  12. 12. Documentations W Project Stability p Fulfills a need Volley !
  13. 13. @brwngrldev
  14. 14. Rinse & Repeat Volley ! Fresco ! Glide ! Picasso !
  15. 15. Review… • Documentation • Repository Check-ins • Fulfills a Need Libraries 1 @brwngrldev
  16. 16. Domain Design
  17. 17. Doing too much
  18. 18. Seen this?
  19. 19. Clean It Up! How to fix this MVP MVVM OO
  20. 20. Foo What’s involved… Foo Bar Baz L Om
  21. 21. Example
  22. 22. Remember this?
  23. 23. We need tests
  24. 24. Extract a Presenter
  25. 25. Create an Interface
  26. 26. Reference the Interface public void onEvent (ErrorEvent event) { mainView.showVideoUnavailableMessage(); }
  27. 27. Implement the Interface @Override public void showVideoUnavailableMessage () { Toast.makeText( this, getString(R.string.video_unavailable), Toast.LENGTH_LONG ) .show(); }
  28. 28. Foo Bar Baz Lol Omg @brwngrldev
  29. 29. Review… • Keep Code Simple • Use MV* Pattern • Functional Tests • Use the Tools @brwngrldev Domain Design 2
  30. 30. Code Quality
  31. 31. Poor Readability
  32. 32. Increase Readability? “Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.”
  33. 33. Source Files config.xml Checkstyle Tool Modules Design Formatting Code Complexity
  34. 34. apply plugin: ‘checkstyle’ task checkstyle(type: Checkstyle) {
 description 'Checks if the code passes quality standards'
 group 'verification'
 
 configFile file(‘checkstyle.xml') …
 }
  35. 35. <module name=“MethodLength"> <property name="max" value=“60"/> </module> 
 <module name=“LineLength"> <property name="max" value=“120"/> </module>
 
 <module name=“CyclomaticComplexity"> <property name="max" value=“8"/> </module> … playerControlConfig.setShowClosedCaptionsButton(a.getBo
  36. 36. 
 <module name=“CyclomaticComplexity"> <property name="max" value=“8"/> </module>
  37. 37. Example
  38. 38. public void overlyComplexMethod(Video video) { if (video != null && video.getStreamUrl() != null) { switch (video.getCategory()) { case "CAT1" : playVideo(video); if (video.getLargeImageUrl() == null) { video.setLargeImageUrl("http://www.largeImage.png"); } updateMetadata(video); break; case "CAT2" : if (video.getLargeImageUrl() == null) { video.setLargeImageUrl("http://www.smallImage.png");
  39. 39. … warning: Cyclomatic Complexity is 9
  40. 40. public void overlyComplexMethod(Video video) { if (video != null && video.getStreamUrl() != null) { updateVideoBasedOnCategory(video); } } private void updateVideoBasedOnCategory(Video video) { switch (video.getCategory()) { case "CAT1" : playVideo(video); if (video.getLargeImageUrl() == null) { video.setLargeImageUrl("http://www.largeImage.png"); } updateMetadata(video); break; 7
  41. 41. switch (video.getCategory()) { case "CAT1" : playVideo(video); updateMetaDataAndUrl(video, "http://www.largeImage.png"); break; … 4 @brwngrldev
  42. 42. Review… • Readability Matters • Use Checkstyle • Refactor Gradually @brwngrldev Code Quality 3
  43. 43. Unit Testing
  44. 44. Untested Code
  45. 45. “Every single line of code that you write should be tested. Period.” — Robert Martin
  46. 46. 0 9,000 18,000 27,000 36,000 Lines of Code Production Tests 90% 2,200 90s FitNesse
  47. 47. JUnit • Framework for writing repeatable tests • Assertions for testing expected results • Features for sharing common test data • Test suites for organizing tests
  48. 48. Mockito • Enables mock creation and verification • Mock concrete classes and interfaces • Simple annotation support
  49. 49. Example
  50. 50. Test Setup @Mock MainView mainView; @brwngrldev
  51. 51. Test Setup @Mock MainView mainView; @Before public void setUp () { } @brwngrldev
  52. 52. Test Setup @Mock MainView mainView; @Before public void setUp () { initMocks( this ); mainPresenter = new MainPresenter(); mainPresenter.setMainView( mainView ); } @brwngrldev
  53. 53. Sample Test @brwngrldev @Test public void configurationLoaded_shouldHideSplashScreen () { ConfigurationLoadedEvent event = new ConfigurationLoadedEvent(); mainPresenter.onEvent( event ); }
  54. 54. Sample Test @brwngrldev @Test public void configurationLoaded_shouldHideSplashScreen () { ConfigurationLoadedEvent event = new ConfigurationLoadedEvent(); mainPresenter.onEvent( event ); verify( mainView ).hideSplashScreen(); }
  55. 55. Test Report @brwngrldev
  56. 56. Continuous Integration @brwngrldev
  57. 57. Code Coverage @brwngrldev
  58. 58. Makes You Powerful
  59. 59. Review • Listen to Robert Martin! • JUnit + Mockito • Continuous Integration • Code Coverage Testing 4 @brwngrldev
  60. 60. Summary Ensure code quality Choose the right library Don’t do too much Write unit tests @brwngrldev
  61. 61. Thanks! @brwngrldev +AnnyceDavis www.adavis.info
  62. 62. Resources • Clean Code - http://amzn.to/1DJybxH • Effective Java - http://amzn.to/1Ku8Xel • Working Effectively with Legacy Code - http://amzn.to/1Jqe1PA • Unit Testing Idioms - http://goo.gl/Bx1WbL • Google Code Style - http://goo.gl/8Pf6J3 • Architecting Android - http://goo.gl/UKvmbq • Conquering Cyclomatic Complexity - http://goo.gl/lRoPXN @brwngrldev
  63. 63. Photo Credits • Slide 5 - https://www.flickr.com/photos/tshirbert/118250140 • Slide 19 - http://uncompromisedmen.com/2015/02/17/top-10-crazy-beards- wish-youd-seen-person/ • Slide 34 - https://www.flickr.com/photos/cast_fish/2888442781 • Slide 48 - https://www.flickr.com/photos/desertbusforhope/8207412726/ • Slide 50 - https://www.flickr.com/photos/sokabs/2668975758 • Slide 64 - https://www.flickr.com/photos/pasukaru76/5268559005 @brwngrldev

×