SlideShare a Scribd company logo
Android
antipatterns
mobile guild
#cododajnia
Bartosz Kosarzycki
@bkosarzycki
Anti-pattern
a common response to a recurring problem that is usually
ineffective [and] usually counter-productive.
Android antipatterns
Premature optimisation
Donald Knuth
Author of “The Art of Computer Programming”
Sir Tony Hoare
Quick Sort, Null-reference,
Hoare logic
Donald Knuth:
For those who don't work to strict memory or CPU cycle limits,
PrematureOptimization is an AntiPattern, since there is only cost and no
benefit. For those who do, it is often confused with poor coding, or with
misguided attempts at writing optimal code.
Quotes original author is still questioned.
“We should forget about small efficiencies, say about
97% of the time”
LET’S REMOVE ALL ENUMS!
WHY?
Enums have obvious benefits:
- make the code more self-documenting
- the compiler can assign default values to
enumerator automatically
- prevents the programmer from writing illogical
code - e.g. multiplying enums?
- IDEs, type checking, correctness etc.
Change it to
integers?
public class View {
public static final int VISIBLE = 0x00000000;
public static final int INVISIBLE = 0x00000004;
public static final int GONE = 0x00000008;
}
https://developer.android.com/reference/android/support/annotation/IntDef.html
@IntDef would be
a better idea...
@IntDef({NAVIGATION_MODE_STANDARD,
NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
Which leaves us
with...
public class View {
public static final int VISIBLE = 0x00000000;
public static final int INVISIBLE = 0x00000004;
public static final int GONE = 0x00000008;
@IntDef({VISIBLE, INVISIBLE, GONE})
@Retention(RetentionPolicy.SOURCE)
public @interface Visibility {}
}
PROGUARD
DOES IT
FOR US!
-keep public enum
android-how-to-keep-enum-from-proguard [link]
proguard-wont-keep-a-class-members-enums [link]
Proguard config
#keep enum classes
-keep public enum com.intive.nearbyplaces.model.ApiProviderType** {
**[] $VALUES;
public *;
}
You can also keep the enums...
Android antipatterns
Android antipatterns
Silver-bullet
LET’S DO EVERYTHING REACTIVE
If you don’t need it - don’t use it!
Library Method count
Butterknife 119
Retrofit2 402
Realm 2343
com.google.android 9651
Glide 2364
Kotlin 5090
RxJava + RxBinding + RxPref + RxLoc +
RxTuples
5319 + 758 + 90 + 176 + 137 = 6480
Hawk 121
RxJava is heavy on android
*without proguard
Use reactive:
- Constant flow of data
- “Instant” search cases
Debounce(), throttleFirst()
- Reflecting settings in UI ?
It’s NOT only RxJava
Maybe Android bindings are enough?
Don’t use reactive:
- button clicks
@Click is probably more concise
- Simple “lookups” from db
Category category = Category.forId(263);
- Large, expensive, cached objects
Android antipatterns
Duplication
RxJava
Duplication of reactive approaches
EventBus
EventBus
Don’t use a separate
library - both approaches
are reactive!
/**
* Rx-style Event bus. Each event type implements its own subscription methods.
*/
public class RxEventBus {
private static RxEventBus instance;
private PublishSubject<Location> mGpsLocationEvents = PublishSubject.create();
public static RxEventBus instanceOf() {
if (instance == null) {
instance = new RxEventBus();
}
return instance;
}
/**
* Pass events of LOCATION type down to event listeners.
*/
public void newLocationEvent(Location location) {
mGpsLocationEvents.onNext(location);
}
/**
* Subscribe to this LOCATION type Observable. On event Action will be called.
*/
public Observable<Location> getLocationEvents() {
return mGpsLocationEvents;
}
}
Android antipatterns
Nullpointer hell
@NonNull
Java is not null-safe
@NonNull
How can we overcome
this?
@NonNull
- We could use a higher order language like
Kotlin/Scala/Dart
- Optional<Type>
- Annotations @NonNull @Nullable
@NonNull
funtion add(@NonNull Square s1, @NonNull Square s2) {
}
@NonNull
funtion add(@NonNull Square s1, @NonNull Square s2) {
}
TEDIOUS!
@NonNull
Let’s assume parameters
and return values are
NonNull by default
@NonNull
file: package-info.java
@ParametersAreNonnullByDefault
@ReturnValuesAreNonnullByDefault
package com.intive.nearbyplaces;
Gradle tasks for generating these files:
download, download
Antipatterns summary
- Premature optimization
- Silver bullet
- Duplication
- Nullpointer hell
Other Antipatterns
Superstitious coding
Coding to handle error conditions which are already known to be impossible.
Reinventing the square wheel/ Not Invented Here (NIH)
Failing to adopt an existing solution and instead adopting a custom solution which performs much
worse than the existing one
Tester Driven Development
Removing the determination of requirements and letting the testers (or the QA team) drive what they think the software should be
through the testing (or QA) process.
Lava flow
Retaining undesirable (redundant or low-quality) code because removing it is too expensive
Links
- Premature optimization is the root of all evil - Donald Knuth link
- The antipattern catalogue Donald Knuth - link
- The price of enums Android Developers - link
- AntiPatterns: Refactoring Software, Architectures, and Projects in
Crisis link
- When not to use reactive - link
- NonNull gradle task generator - link, link
Thank you!
QUESTIONS
Bartosz Kosarzycki
@bkosarzycki

More Related Content

PDF
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
PDF
re-frame à la spec
Kent Ohashi
 
PDF
Introduction to Dart
RameshNair6
 
PDF
GraphQL API in Clojure
Kent Ohashi
 
PDF
Java objects on steroids
Romain Rochegude
 
PDF
Kotlin: Challenges in JVM language design
Andrey Breslav
 
PDF
Java Full Throttle
José Paumard
 
PDF
Kotlin - Better Java
Dariusz Lorenc
 
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
re-frame à la spec
Kent Ohashi
 
Introduction to Dart
RameshNair6
 
GraphQL API in Clojure
Kent Ohashi
 
Java objects on steroids
Romain Rochegude
 
Kotlin: Challenges in JVM language design
Andrey Breslav
 
Java Full Throttle
José Paumard
 
Kotlin - Better Java
Dariusz Lorenc
 

What's hot (20)

PDF
Gradle in a Polyglot World
Schalk Cronjé
 
PDF
Frege Tutorial at JavaOne 2015
Dierk König
 
PPT
What's New in Groovy 1.6?
Guillaume Laforge
 
PDF
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
PDF
Frege - consequently functional programming for the JVM
Dierk König
 
PDF
R ext world/ useR! Kiev
Ruslan Shevchenko
 
KEY
Mirah Talk for Boulder Ruby Group
baroquebobcat
 
PDF
Handling inline assembly in Clang and LLVM
Min-Yih Hsu
 
PDF
Inside the JVM - Follow the white rabbit!
Sylvain Wallez
 
PDF
Continuations in scala (incomplete version)
Fuqiang Wang
 
PPTX
Kotlin
Rory Preddy
 
ODP
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
PDF
Dart Workshop
Dmitry Buzdin
 
PDF
FregeFX - JavaFX with Frege, a Haskell for the JVM
Dierk König
 
PPTX
Fall in love with Kotlin
Hari Vignesh Jayapalan
 
PDF
Core Java - Quiz Questions - Bug Hunt
CodeOps Technologies LLP
 
PDF
Seeking Clojure
chrisriceuk
 
ODP
Groovy Ast Transformations (greach)
HamletDRC
 
PDF
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko
 
PDF
C++ for Java Developers (SwedenCpp Meetup 2017)
Patricia Aas
 
Gradle in a Polyglot World
Schalk Cronjé
 
Frege Tutorial at JavaOne 2015
Dierk König
 
What's New in Groovy 1.6?
Guillaume Laforge
 
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Frege - consequently functional programming for the JVM
Dierk König
 
R ext world/ useR! Kiev
Ruslan Shevchenko
 
Mirah Talk for Boulder Ruby Group
baroquebobcat
 
Handling inline assembly in Clang and LLVM
Min-Yih Hsu
 
Inside the JVM - Follow the white rabbit!
Sylvain Wallez
 
Continuations in scala (incomplete version)
Fuqiang Wang
 
Kotlin
Rory Preddy
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
Dart Workshop
Dmitry Buzdin
 
FregeFX - JavaFX with Frege, a Haskell for the JVM
Dierk König
 
Fall in love with Kotlin
Hari Vignesh Jayapalan
 
Core Java - Quiz Questions - Bug Hunt
CodeOps Technologies LLP
 
Seeking Clojure
chrisriceuk
 
Groovy Ast Transformations (greach)
HamletDRC
 
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko
 
C++ for Java Developers (SwedenCpp Meetup 2017)
Patricia Aas
 
Ad

Viewers also liked (20)

PDF
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
PDF
Daggerate your code - Write your own annotation processor
Bartosz Kosarzycki
 
PDF
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
PDF
Introduction to Flutter - truly crossplatform, amazingly fast
Bartosz Kosarzycki
 
PPTX
Rx java in action
Pratama Nur Wijaya
 
PDF
RxJava in practice
Javier Gamarra
 
PDF
Reactive programming on Android
Tomáš Kypta
 
PDF
RxBinding-kotlin
Satoru Fujiwara
 
PDF
Git into the Flow, with the Ultimate Continuous Delivery Workflow on Heroku
Salesforce Developers
 
PDF
Practical RxJava for Android
Tomáš Kypta
 
PPTX
Introduction to rx java for android
Esa Firman
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Gitlab flow
viniciusban
 
PDF
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
PDF
Kotlinにお触り
Shinobu Okano
 
PDF
Git workshop
Al Sayed Gamal
 
PDF
Practical RxJava for Android
Tomáš Kypta
 
PDF
Gitlab flow solo
viniciusban
 
PDF
RxJava+RxAndroid (Lecture 20 – rx java)
Noveo
 
PPTX
Ultimate Git Workflow - Seoul 2015
Atlassian 대한민국
 
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Daggerate your code - Write your own annotation processor
Bartosz Kosarzycki
 
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Introduction to Flutter - truly crossplatform, amazingly fast
Bartosz Kosarzycki
 
Rx java in action
Pratama Nur Wijaya
 
RxJava in practice
Javier Gamarra
 
Reactive programming on Android
Tomáš Kypta
 
RxBinding-kotlin
Satoru Fujiwara
 
Git into the Flow, with the Ultimate Continuous Delivery Workflow on Heroku
Salesforce Developers
 
Practical RxJava for Android
Tomáš Kypta
 
Introduction to rx java for android
Esa Firman
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Gitlab flow
viniciusban
 
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Kotlinにお触り
Shinobu Okano
 
Git workshop
Al Sayed Gamal
 
Practical RxJava for Android
Tomáš Kypta
 
Gitlab flow solo
viniciusban
 
RxJava+RxAndroid (Lecture 20 – rx java)
Noveo
 
Ultimate Git Workflow - Seoul 2015
Atlassian 대한민국
 
Ad

Similar to Android antipatterns (20)

PDF
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
PDF
Where All Libraries & Data Required For Android App Development Are Present
Techugo
 
PPTX
Performance #5 cpu and battery
Vitali Pekelis
 
PDF
Eric Lafortune - ProGuard and DexGuard for optimization and protection
GuardSquare
 
PDF
Android App Performance
Altaf ur Rehman
 
PDF
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 
PPTX
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
PPTX
It's always your fault. Poznań ADG 2016
Przemek Jakubczyk
 
PPTX
Introduction to kotlin
Shaul Rosenzwieg
 
PPTX
It's always your fault
Przemek Jakubczyk
 
PPTX
Kotlin presentation
MobileAcademy
 
PPTX
Introduction to Android- A session by Sagar Das
dscfetju
 
PDF
Android Made Simple
Gabriel Dogaru
 
PDF
Priming Java for Speed at Market Open
Azul Systems Inc.
 
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
PDF
Functional Reactive Programming (RxJava) on Android
Richard Radics
 
PDF
Exploring Koltin on Android
Deepanshu Madan
 
PPTX
Design patterns with kotlin
Alexey Soshin
 
PDF
Java Performance Tuning
Atthakorn Chanthong
 
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
Where All Libraries & Data Required For Android App Development Are Present
Techugo
 
Performance #5 cpu and battery
Vitali Pekelis
 
Eric Lafortune - ProGuard and DexGuard for optimization and protection
GuardSquare
 
Android App Performance
Altaf ur Rehman
 
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
It's always your fault. Poznań ADG 2016
Przemek Jakubczyk
 
Introduction to kotlin
Shaul Rosenzwieg
 
It's always your fault
Przemek Jakubczyk
 
Kotlin presentation
MobileAcademy
 
Introduction to Android- A session by Sagar Das
dscfetju
 
Android Made Simple
Gabriel Dogaru
 
Priming Java for Speed at Market Open
Azul Systems Inc.
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Functional Reactive Programming (RxJava) on Android
Richard Radics
 
Exploring Koltin on Android
Deepanshu Madan
 
Design patterns with kotlin
Alexey Soshin
 
Java Performance Tuning
Atthakorn Chanthong
 

More from Bartosz Kosarzycki (12)

PDF
Droidcon Summary 2021
Bartosz Kosarzycki
 
PDF
Droidcon Online 2020 quick summary
Bartosz Kosarzycki
 
PDF
Provider vs BLoC vs Redux
Bartosz Kosarzycki
 
PDF
Animations in Flutter
Bartosz Kosarzycki
 
PDF
Flutter overview - advantages & disadvantages for business
Bartosz Kosarzycki
 
PDF
Flutter CI & Device Farms for Flutter
Bartosz Kosarzycki
 
PDF
Drone racing - beginner's guide
Bartosz Kosarzycki
 
PDF
Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Bartosz Kosarzycki
 
PDF
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Bartosz Kosarzycki
 
PDF
DroidCon Berlin 2018 summary
Bartosz Kosarzycki
 
PDF
SCALA - Functional domain
Bartosz Kosarzycki
 
PDF
Android things introduction - Development for IoT
Bartosz Kosarzycki
 
Droidcon Summary 2021
Bartosz Kosarzycki
 
Droidcon Online 2020 quick summary
Bartosz Kosarzycki
 
Provider vs BLoC vs Redux
Bartosz Kosarzycki
 
Animations in Flutter
Bartosz Kosarzycki
 
Flutter overview - advantages & disadvantages for business
Bartosz Kosarzycki
 
Flutter CI & Device Farms for Flutter
Bartosz Kosarzycki
 
Drone racing - beginner's guide
Bartosz Kosarzycki
 
Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Bartosz Kosarzycki
 
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Bartosz Kosarzycki
 
DroidCon Berlin 2018 summary
Bartosz Kosarzycki
 
SCALA - Functional domain
Bartosz Kosarzycki
 
Android things introduction - Development for IoT
Bartosz Kosarzycki
 

Recently uploaded (20)

PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Presentation about variables and constant.pptx
safalsingh810
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Exploring AI Agents in Process Industries
amoreira6
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 

Android antipatterns