SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Scala on Android
Android Development
●   Write lots of Java code
●   Write UI and other resources in XML
●   Generate Java code from resources
●   Compile Java code into “.class” files
●   Run proguard
●   Compile class files to Dalvik Executable (DEX)
●   Deploy on device
Dalvik VM
●   Does not support “.class” bytecode format
●   Can not use libraries which generate bytecode
●   Devices have limited CPU and Memory
●   Can not easily share libraries between
    applications
Eclipse
●   Has nice UI editors
●   IDE is a build tool
Alternative Languages for Android
Jython
●   Does not have enough community support
●   Slow
●   Dynamic
JRuby
●   Ruboto framework
●   Dynamic
●   Need to use java code generation
Clojure
●   Very cool :)
●   Very slow start-up time
●   Sometimes need to generate bytecode
PHP




Who cares?
Rhino
●   Nice language
●   Can run with optimization turned off
●   Completely interpreted
●   Dynamic
Groovy




 ???
Scala
●   Statically typed
●   Compiled to Java bytecode
●   Has access to all classes in Android
●   Fast
    ●   but sometimes slow :)
●   Has SBT
    ●   Android
    ●   Maven artifacts
How to build Scala apps for Android
●   ANT
●   Maven
●   SBT + Android Plugin
Little nice things about Scala
Type Inference
●   Improve readability
●   Reduce number of imports
●   Less typing
val stream = getAssets().open("areas.json")



        val stream: InputStream =
      getAssets().open("areas.json")
Import statement
import android.view.{
  Window, Menu, MenuItem, KeyEvent, View
}

import android.util.Log.{e => error}
Lazy vals
lazy val searchBox =
  findViewById(R.id.searchBox)
  .asInstanceOf[AutoCompleteTextView]
Mixin Inheritance
class MainActivity extends MapActivity
 with Logging
 with DatabaseHelpers
 with MapHelpers
Collections
●   Best collection library I ever used
    ●   Sorry google-collections...
●   Using arrays is easy
●   @specialized
Collection examples
val suggestions = areas map { _.name }
val index = areas.indexWhere(
  _.name == searchString
)

val index =
  areas.indexWhere(_.contains(coordinate))

pointList.minBy(_.lat)
First class functions
class AreaOverlay(
  areas: Array[Area],
  selectListener: Int => Unit
)

new AreaOverlay(
  areas, this.onAreaSelected
)
Convert listeners into functions
implicit def fn2ClickListener(
  f: View => Unit
): View.OnClickListener =
  new View.OnClickListener() {
     override def onClick(v: View) = f(view)
  }

exitButton.setOnClickListener(
 this.onExitClick
)
Files
●   Directory structure is not forced to mirror
    packages
●   Files can contain any amount of classes
Pattern matching
●   No NPEs when using Option[T]
●   Easy to work with data objects
Pattern matching
lastLocation match {
  case Some(c@Coordinate(lat, lon)) =>
    ...
  case None =>
    ...
}
Implicits
implicit def coordinate2geopoint(
  c: Coordinate
): GeoPoint = new GeoPoint(
  c.lat * 1.0e6 toInt, c.lon * 1.0e6 toInt
)
XML
for (s <- xml  "Document"  "Style")

placemarkElem  "Polygon" 
   "outerBoundaryIs"  "LinearRing" 
      "coordinates"
Bad stuff
●   Performance sensitive parts
    ●   Learn to use “javap”
    ●   Remove for-comprehensions and lambda functions
    ●   Do not use boxed types “by accident”
●   Tools
    ●   UI Editor
    ●   Debugger
    ●   Build time (dex'ing of scala library)
What I missed from Java
●   Google Guice
●   Maven
●   Good Eclipse integration
●   Feeling important...
Thank you!
Questions?

Contenu connexe

Tendances

Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Peter Arato
 
F# type providers
F# type providersF# type providers
F# type providersAntya Dev
 
Lightning talk: Kotlin
Lightning talk: KotlinLightning talk: Kotlin
Lightning talk: KotlinEvolve
 
Moving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xMoving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xSergey Rubanov
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Divedavanum
 
Why I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CWhy I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CSeniorDevOnly
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at CodacyJohann Oikonomou
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scalaAlessandro Marrella
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...Paris Open Source Summit
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features Florian Hopf
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with javaLiviu Tudor
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
 

Tendances (20)

Turbo charging v8 engine
Turbo charging v8 engineTurbo charging v8 engine
Turbo charging v8 engine
 
Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)
 
C#
C#C#
C#
 
C#
C#C#
C#
 
C#
C#C#
C#
 
F# type providers
F# type providersF# type providers
F# type providers
 
Lightning talk: Kotlin
Lightning talk: KotlinLightning talk: Kotlin
Lightning talk: Kotlin
 
Moving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xMoving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201x
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
 
Why I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CWhy I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective C
 
Realm database
Realm databaseRealm database
Realm database
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at Codacy
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scala
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Metaprogramming with javascript
Metaprogramming with javascriptMetaprogramming with javascript
Metaprogramming with javascript
 
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features
 
React native
React nativeReact native
React native
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 

Similaire à Scala on Android Development

Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioAhasan Habib
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Introducing Android Programming
Introducing Android ProgrammingIntroducing Android Programming
Introducing Android ProgrammingArif Huda
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015Jorg Janke
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007lucclaes
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"Gal Marder
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Kenneth Geisshirt
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeWaqqas Jabbar
 
React Native - performance optimization
React Native - performance optimizationReact Native - performance optimization
React Native - performance optimizationStas Doskalenko
 

Similaire à Scala on Android Development (20)

Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual Studio
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Introducing Android Programming
Introducing Android ProgrammingIntroducing Android Programming
Introducing Android Programming
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React Native - performance optimization
React Native - performance optimizationReact Native - performance optimization
React Native - performance optimization
 

Dernier

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Dernier (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

Scala on Android Development

  • 2. Android Development ● Write lots of Java code ● Write UI and other resources in XML ● Generate Java code from resources ● Compile Java code into “.class” files ● Run proguard ● Compile class files to Dalvik Executable (DEX) ● Deploy on device
  • 3. Dalvik VM ● Does not support “.class” bytecode format ● Can not use libraries which generate bytecode ● Devices have limited CPU and Memory ● Can not easily share libraries between applications
  • 4. Eclipse ● Has nice UI editors ● IDE is a build tool
  • 6. Jython ● Does not have enough community support ● Slow ● Dynamic
  • 7. JRuby ● Ruboto framework ● Dynamic ● Need to use java code generation
  • 8. Clojure ● Very cool :) ● Very slow start-up time ● Sometimes need to generate bytecode
  • 10. Rhino ● Nice language ● Can run with optimization turned off ● Completely interpreted ● Dynamic
  • 12. Scala ● Statically typed ● Compiled to Java bytecode ● Has access to all classes in Android ● Fast ● but sometimes slow :) ● Has SBT ● Android ● Maven artifacts
  • 13. How to build Scala apps for Android ● ANT ● Maven ● SBT + Android Plugin
  • 14. Little nice things about Scala
  • 15. Type Inference ● Improve readability ● Reduce number of imports ● Less typing
  • 16. val stream = getAssets().open("areas.json") val stream: InputStream = getAssets().open("areas.json")
  • 17. Import statement import android.view.{ Window, Menu, MenuItem, KeyEvent, View } import android.util.Log.{e => error}
  • 18. Lazy vals lazy val searchBox = findViewById(R.id.searchBox) .asInstanceOf[AutoCompleteTextView]
  • 19. Mixin Inheritance class MainActivity extends MapActivity with Logging with DatabaseHelpers with MapHelpers
  • 20. Collections ● Best collection library I ever used ● Sorry google-collections... ● Using arrays is easy ● @specialized
  • 21. Collection examples val suggestions = areas map { _.name } val index = areas.indexWhere( _.name == searchString ) val index = areas.indexWhere(_.contains(coordinate)) pointList.minBy(_.lat)
  • 22. First class functions class AreaOverlay( areas: Array[Area], selectListener: Int => Unit ) new AreaOverlay( areas, this.onAreaSelected )
  • 23. Convert listeners into functions implicit def fn2ClickListener( f: View => Unit ): View.OnClickListener = new View.OnClickListener() { override def onClick(v: View) = f(view) } exitButton.setOnClickListener( this.onExitClick )
  • 24. Files ● Directory structure is not forced to mirror packages ● Files can contain any amount of classes
  • 25. Pattern matching ● No NPEs when using Option[T] ● Easy to work with data objects
  • 26. Pattern matching lastLocation match { case Some(c@Coordinate(lat, lon)) => ... case None => ... }
  • 27. Implicits implicit def coordinate2geopoint( c: Coordinate ): GeoPoint = new GeoPoint( c.lat * 1.0e6 toInt, c.lon * 1.0e6 toInt )
  • 28. XML for (s <- xml "Document" "Style") placemarkElem "Polygon" "outerBoundaryIs" "LinearRing" "coordinates"
  • 29. Bad stuff ● Performance sensitive parts ● Learn to use “javap” ● Remove for-comprehensions and lambda functions ● Do not use boxed types “by accident” ● Tools ● UI Editor ● Debugger ● Build time (dex'ing of scala library)
  • 30. What I missed from Java ● Google Guice ● Maven ● Good Eclipse integration ● Feeling important...