Be a Good Citizen:
!
Develop Maintainable Apps
“…a high probability of determining the cause of
a problem in a timely manner… and a high
probability of being able to mod...
Why Care?
What’s involved…
@brwngrldev
What’s involved…
Libraries
1
@brwngrldev
What’s involved…
Libraries
1
Domain
Design
2
@brwngrldev
What’s involved…
Libraries
1
Domain
Design
2
Code
Quality
3
@brwngrldev
What’s involved…
Libraries
1
Domain
Design
2
Code
Quality
3
Testing
4
@brwngrldev
Choosing the Right Library
So many options
So many options
What to consider
@brwngrldev
What to consider
Documentation
@brwngrldev
What to consider
Documentation
Project Stability
@brwngrldev
What to consider
Documentation
Project Stability
Fulfills a Need
@brwngrldev
What to consider
Amazing App
!
Documentation
Project Stability
Fulfills a Need
@brwngrldev
Example
So you need images…
So you need images…
Volley
!
Fresco
!
Glide
!
Picasso
!
Volley
!
Documentation	

s
Volley
!
Documentation	

s
Volley
!
Documentation	

s
W Project Stability
Volley
!
Documentation	

s
W Project Stability
Volley
!
Documentation	

s
W Project Stability
p Fulfills a need
Volley
!
@brwngrldev
Rinse & Repeat
Volley
!
Fresco
!
Glide
!
Picasso
!
Review…
• Documentation
• Repository Check-ins
• Fulfills a Need
Libraries
1
@brwngrldev
Domain Design
Doing too much
Doing too much
Seen this?
Seen this?
Seen this?
Seen this?
How to fix this
Clean
It Up!
How to fix this
Clean
It Up!
How to fix this
MVP
MVVM
OO
Foo
What’s involved…
What’s involved…
Foo Bar
Baz Lol
Omg
Example
Remember this?
We need tests
We need tests
We need tests
Extract a Presenter
Create an Interface
Reference the Interface
Implement the Interface
Foo Bar
Baz Lol
Omg
@brwngrldev
Review…
• Keep Code Simple
• Use MV* Pattern
• Functional Tests
• Use the Tools
@brwngrldev
Domain
Design
2
Code Quality
Poor Readability
Poor Readability
Increase Readability?
Increase Readability?
“Checkstyle is a development tool to
help programmers write Java code
that adheres to a coding stand...
Source
Files
config.xml
Checkstyle Tool
!
Modules
Design
Formatting
Code Complexity
apply plugin: ‘checkstyle’
!
task checkstyle(type: Checkstyle) {

description 'Checks if the code passes quality standards...
apply plugin: ‘checkstyle’
!
task checkstyle(type: Checkstyle) {

description 'Checks if the code passes quality standards...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...
<module name=“MethodLength">
<property name="max" value=“60"/>
</module>


<module name=“LineLength">
<property name="max"...


<module name=“CyclomaticComplexity">
<property name="max" value=“8"/>
</module>
!
M = E − N + 2P
@brwngrldev
M = E − N + 2P
@brwngrldev
Example
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
switch (video.getCateg...
case "CAT1" :
playVideo(video);
if (video.getLargeImageUrl() == null) {
video.setLargeImageUrl("http://www.largeImage.png"...
… warning: Cyclomatic Complexity is 9
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
updateVideoBasedOnCate...
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
updateVideoBasedOnCate...
public void overlyComplexMethod(Video video) {
if (video != null && video.getStreamUrl() != null) {
updateVideoBasedOnCate...
!
switch (video.getCategory()) {
case "CAT1" :
playVideo(video);
updateMetaDataAndUrl(video, "http://www.largeImage.png");...
!
switch (video.getCategory()) {
case "CAT1" :
playVideo(video);
updateMetaDataAndUrl(video, "http://www.largeImage.png");...
Review…
• Readability Matters
• Use Checkstyle
• Refactor Gradually
@brwngrldev
Code
Quality
3
Unit Testing
Untested Code
Untested Code
“Every single line of code that you
write should be tested. Period.”
— Robert Martin
0
9,000
18,000
27,000
36,000
Lines of Code
Production Tests
FitNesse
0
9,000
18,000
27,000
36,000
Lines of Code
Production Tests 90%
FitNesse
0
9,000
18,000
27,000
36,000
Lines of Code
Production Tests 90%
2,200
FitNesse
0
9,000
18,000
27,000
36,000
Lines of Code
Production Tests 90%
2,200
90s
FitNesse
Example
Test Setup
@brwngrldev
Sample Test
@brwngrldev
Test Report
Continuous Integration
@brwngrldev
Code Coverage
@brwngrldev
Makes You Powerful
Review
• Listen to Robert Martin!
• JUnit + Mockito
• Continuous Integration
• Code Coverage
Testing
4
@brwngrldev
Summary
Summary
Choose the right library
Summary
Choose the right library
Don’t do too much
Summary
Ensure code quality
Choose the right library
Don’t do too much
Summary
Ensure code quality
Choose the right library
Don’t do too much
Write unit tests
Resources
• Clean Code - http://amzn.to/1DJybxH
• Effective Java - http://amzn.to/1Ku8Xel
• Working Effectively with Legacy ...
Photo Credits
• Slide 4 - https://www.flickr.com/photos/nikigunn/8379494330
• Slide 6 - https://www.flickr.com/photos/tracy_...
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Develop Maintainable Apps
Upcoming SlideShare
Loading in …5
×

Develop Maintainable Apps

8,587 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. Learn four tips to delivering high quality Android applications.

Published in: Mobile

Develop Maintainable Apps

  1. 1. Be a Good Citizen: ! Develop Maintainable Apps
  2. 2. “…a high probability of determining the cause of a problem in a timely manner… and a high probability of being able to modify the program without causing an error in some other part…” — IEEE
  3. 3. Why Care?
  4. 4. What’s involved… @brwngrldev
  5. 5. What’s involved… Libraries 1 @brwngrldev
  6. 6. What’s involved… Libraries 1 Domain Design 2 @brwngrldev
  7. 7. What’s involved… Libraries 1 Domain Design 2 Code Quality 3 @brwngrldev
  8. 8. What’s involved… Libraries 1 Domain Design 2 Code Quality 3 Testing 4 @brwngrldev
  9. 9. Choosing the Right Library
  10. 10. So many options
  11. 11. So many options
  12. 12. What to consider @brwngrldev
  13. 13. What to consider Documentation @brwngrldev
  14. 14. What to consider Documentation Project Stability @brwngrldev
  15. 15. What to consider Documentation Project Stability Fulfills a Need @brwngrldev
  16. 16. What to consider Amazing App ! Documentation Project Stability Fulfills a Need @brwngrldev
  17. 17. Example
  18. 18. So you need images…
  19. 19. So you need images… Volley ! Fresco ! Glide ! Picasso !
  20. 20. Volley !
  21. 21. Documentation s Volley !
  22. 22. Documentation s Volley !
  23. 23. Documentation s W Project Stability Volley !
  24. 24. Documentation s W Project Stability Volley !
  25. 25. Documentation s W Project Stability p Fulfills a need Volley !
  26. 26. @brwngrldev
  27. 27. Rinse & Repeat Volley ! Fresco ! Glide ! Picasso !
  28. 28. Review… • Documentation • Repository Check-ins • Fulfills a Need Libraries 1 @brwngrldev
  29. 29. Domain Design
  30. 30. Doing too much
  31. 31. Doing too much
  32. 32. Seen this?
  33. 33. Seen this?
  34. 34. Seen this?
  35. 35. Seen this?
  36. 36. How to fix this
  37. 37. Clean It Up! How to fix this
  38. 38. Clean It Up! How to fix this MVP MVVM OO
  39. 39. Foo What’s involved…
  40. 40. What’s involved… Foo Bar Baz Lol Omg
  41. 41. Example
  42. 42. Remember this?
  43. 43. We need tests
  44. 44. We need tests
  45. 45. We need tests
  46. 46. Extract a Presenter
  47. 47. Create an Interface
  48. 48. Reference the Interface
  49. 49. Implement the Interface
  50. 50. Foo Bar Baz Lol Omg @brwngrldev
  51. 51. Review… • Keep Code Simple • Use MV* Pattern • Functional Tests • Use the Tools @brwngrldev Domain Design 2
  52. 52. Code Quality
  53. 53. Poor Readability
  54. 54. Poor Readability
  55. 55. Increase Readability?
  56. 56. Increase Readability? “Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.”
  57. 57. Source Files config.xml Checkstyle Tool ! Modules Design Formatting Code Complexity
  58. 58. apply plugin: ‘checkstyle’ ! task checkstyle(type: Checkstyle) {
 description 'Checks if the code passes quality standards'
 group 'verification'
 
 configFile file(‘checkstyle.xml') …
 }
  59. 59. apply plugin: ‘checkstyle’ ! task checkstyle(type: Checkstyle) {
 description 'Checks if the code passes quality standards'
 group 'verification'
 
 configFile file(‘checkstyle.xml') …
 }
  60. 60. <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> …
  61. 61. <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> …
  62. 62. <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 !
  63. 63. <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> … leable.WapoVideoView_showClosedCaptionsButton, false));
  64. 64. <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> …
  65. 65. <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> …
  66. 66. 
 <module name=“CyclomaticComplexity"> <property name="max" value=“8"/> </module> !
  67. 67. M = E − N + 2P @brwngrldev
  68. 68. M = E − N + 2P @brwngrldev
  69. 69. Example
  70. 70. 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");
  71. 71. 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"); } updateMetadata(video); break; …
  72. 72. … warning: Cyclomatic Complexity is 9
  73. 73. 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;
  74. 74. 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;
  75. 75. 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
  76. 76. ! switch (video.getCategory()) { case "CAT1" : playVideo(video); updateMetaDataAndUrl(video, "http://www.largeImage.png"); break; … @brwngrldev
  77. 77. ! switch (video.getCategory()) { case "CAT1" : playVideo(video); updateMetaDataAndUrl(video, "http://www.largeImage.png"); break; … 4 @brwngrldev
  78. 78. Review… • Readability Matters • Use Checkstyle • Refactor Gradually @brwngrldev Code Quality 3
  79. 79. Unit Testing
  80. 80. Untested Code
  81. 81. Untested Code
  82. 82. “Every single line of code that you write should be tested. Period.” — Robert Martin
  83. 83. 0 9,000 18,000 27,000 36,000 Lines of Code Production Tests FitNesse
  84. 84. 0 9,000 18,000 27,000 36,000 Lines of Code Production Tests 90% FitNesse
  85. 85. 0 9,000 18,000 27,000 36,000 Lines of Code Production Tests 90% 2,200 FitNesse
  86. 86. 0 9,000 18,000 27,000 36,000 Lines of Code Production Tests 90% 2,200 90s FitNesse
  87. 87. Example
  88. 88. Test Setup @brwngrldev
  89. 89. Sample Test @brwngrldev
  90. 90. Test Report
  91. 91. Continuous Integration @brwngrldev
  92. 92. Code Coverage @brwngrldev
  93. 93. Makes You Powerful
  94. 94. Review • Listen to Robert Martin! • JUnit + Mockito • Continuous Integration • Code Coverage Testing 4 @brwngrldev
  95. 95. Summary
  96. 96. Summary Choose the right library
  97. 97. Summary Choose the right library Don’t do too much
  98. 98. Summary Ensure code quality Choose the right library Don’t do too much
  99. 99. Summary Ensure code quality Choose the right library Don’t do too much Write unit tests
  100. 100. 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 • PostTV App - https://goo.gl/0TRsXU @brwngrldev
  101. 101. Photo Credits • Slide 4 - https://www.flickr.com/photos/nikigunn/8379494330 • Slide 6 - https://www.flickr.com/photos/tracy_olson/61056391 • Slide 7 - https://en.wikipedia.org/wiki/Dominoes • Slide 10 - https://www.flickr.com/photos/tshirbert/118250140 • Slide 24 - http://uncompromisedmen.com/2015/02/17/top-10-crazy-beards- wish-youd-seen-person/ • Slide 38 - https://www.flickr.com/photos/cast_fish/2888442781 • Slide 52 - https://www.flickr.com/photos/desertbusforhope/8207412726/ • Slide 54 - https://www.flickr.com/photos/sokabs/2668975758 • Slide 63 - https://www.flickr.com/photos/pasukaru76/5268559005 @brwngrldev

×