Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Scala for android
1. Do More with Less:
Building Android Apps with Scala
Tony Hillerson • Tack Mobile
AnDevCon III
@thillerson @tackmobile
PRESENTATION ANDEVCON • MAY 14, 2012
2. ABOUT ME
Tony Hillerson
Software Architect & Partner Mobile design and development
company based in Denver, CO.
• O’Reilly Screencasts
• Computer Nerd @tackmobile
• Co-creator of FieldTest tackmobile.com
@thillerson
tony@tackmobile.com
PRESENTATION tackmobile.com
3. Why Would I Consider Scala?
• Write less boilerplate code
• More powerful features than Java
• Move towards Functional paradigms
PRESENTATION tackmobile.com
4. N.B. I Am Not a Scala Expert
• You can probably stump me
• This talk is about how you can explore what
Scala might do for you
PRESENTATION tackmobile.com
5. My Goals
• Introduce you to Scala
• Introduce you to Scala with Android
• Give you a few good reasons to use Scala
• Encourage you to become a Polyglot
PRESENTATION tackmobile.com
10. What is Scala?
• JVM Language
• Take advantage of any Java library
• Bridges the divide between OO and
Functional spaces
PRESENTATION tackmobile.com
13. Strongly, Statically Typed
• Compile time type checking
• Restrictions on how types can be used
together
• For comparison:
• Javascript - Weakly typed, Dynamic
• Ruby - Strongly typed, Dynamic
PRESENTATION tackmobile.com
14. ≠ Boilerplate
• Perens are (sometimes) optional
• Semicolons are (mostly) optional
• Types are inferred, thus:
ArrayList<GameTileMotionDescriptor> descriptors = new
ArrayList<GameTileMotionDescriptor>();
VS.
val descriptors = new ArrayBuffer[GameTileMotionDescriptor]
PRESENTATION tackmobile.com
15. More OO than Java
• Everything is an object
• Operators are actually methods
• For instance, override the “+” method
PRESENTATION tackmobile.com
16. Functional Language
• Functions are first class citizens
• High order functions: Functions that
operate on functions
• Avoids mutable state
• Could get pretty academic
• Scala bridges the gap between OO and
Functional
PRESENTATION tackmobile.com
17. A Javascript Function
var doSomething = function(data) {
doSomethingElseWithData(data);
}
PRESENTATION tackmobile.com
18. A Scala Function
def doSomething(data:A):B = {
doSomethingElseWithData(data)
}
PRESENTATION tackmobile.com
19. Concurrent
• Optional immutable state
• Actors - Higher concept than Threads/
Thread Pools
PRESENTATION tackmobile.com
22. Experiment: Convert from Java to Scala
• Android
• https://github.com/thillerson/Android-Slider-Puzzle
• Scala
• https://github.com/thillerson/scala-android-slider-puzzle
• Mixed results.
• I have a lot to learn about Scala
PRESENTATION tackmobile.com
23. Mike Burns
• Thoughtbot
• Android and Scala at Android Open
• http://robots.thoughtbot.com/post/
5836463058/scala-a-better-java-for-android
• Ohlaunch - https://github.com/mike-burns/
ohlaunch
PRESENTATION tackmobile.com
27. But I Need My Eclipse!
• http://www.assembla.com/wiki/show/scala-
ide/Developing_for_Android
PRESENTATION tackmobile.com
28. Scala’s Features
and Idioms
PRESENTATION ANDEVCON • MAY 14, 2012
29. vals and vars
• var - A variable definition. Required to be
initialized when in a function
• val - A value definition. Once set, cannot be
changed
• Basically a “final”
• Important consideration for concurrent
programming
PRESENTATION tackmobile.com