SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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?

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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...
 

Similar a 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
 

Similar a 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
 

Último

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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