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

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Dernier (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

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...