Giter Club home page Giter Club logo

androiddemoin4languages's Introduction

中文版 日本版

AndroidDemoIn4Languages

A simple Android application written in Java, Groovy, Scala and Kotlin in order to find out what is the better language for Android development.

How to Compare?

Only import the minimal dependencies.

Dependence Report

  • In Java
    • Import com.android.support:appcompat-v7:23.1.1
  • In Groovy
    • Import com.android.support:appcompat-v7:23.1.1
    • Import org.codehaus.groovy:groovy:2.4.5:grooid
    • Import org.codehaus.groovy:groovy-json:2.4.5
  • In Scala
    • Import com.android.support:appcompat-v7:23.1.1
    • Import org.scala-lang:scala-library:2.11.7
    • Import org.scaloid:scaloid_2.11:4.0
  • In Kotlin
    • Import com.android.support:appcompat-v7:23.1.1
    • Import org.jetbrains.kotlin:kotlin-stdlib:1.0.0-beta-4584

Analysis Report

Line Counter

Language Files Blank Lines Comment Lines Code Lines
Java 3 22 0 165
Groovy 3 23 9 140
Scala 3 25 9 110
Kotlin 3 23 9 133

Size Counter

Language Disable Proguard (bytes) Enable Proguard (bytes)
Java 1,220,887 654,906
Groovy 2,934,236 1,674,177
Scala over 65536 methods 1,190,188
Kotlin 1,602,041 697,290

Build Speed

Language Gradle Plugin Spend (secs)
Java 2.0.0-alpha7 ≈ 35
Groovy 2.0.0-alpha7 > 120
Scala 1.3.1 > 160
Kotlin 1.3.1 ≈ 45

Method Counter

Language Disable Proguard Enable Proguard
Java 164,60 6,421
Groovy 46,055 23,112
Scala over 65536 methods 19,388
Kotlin 24,061 6,559

Coding Comparison

Find View

Java

TextView title = (TextView)view.findViewById(android.R.id.text1);

Groovy

def title = view.findViewById(android.R.id.text1) as TextView

Scala

val title = view.findViewById(android.R.id.text1).asInstanceOf[TextView]

Kotlin

val title = view.findViewById(android.R.id.text1) as TextView

OnClickListener

Java

button.setOnClickListener(new View.OnClickListener() {
    @Override
    void onClick(final View v) {
      //  do something
    }
})

Groovy

button.onClickListener = {
    //  do something
}

Scala

button.onClick((v: View) =>
    //  do something
)

Kotlin

button.setOnClickListener {
    //  do something
}

Callback

Java

public interface FindCallback {
    void onFinish(List<String> results, Exception e);
}
private void findCountries(FindCallback doneCallback) {
    try {
        //  a long time mission
        doneCallback.onFinish(results, null);
    } catch (Exception e) {
        doneCallback.onFinish(null, e);
    }
}
findCountries(new FindCallback(){
    void onFinish(List<String> results, Exception e){
      //  handle result
    }
});

Groovy

def findCountries(Closure doneCallback) {
    try {
        //  a long time mission
        doneCallback(results, null)
    } catch (e) {
        doneCallback(null, e)
    }
}
findCountries{ List<String> results, Exception e ->
  //  handle result
});

Scala

def findCountries(doneCallback: (ArrayBuffer[String], Exception) => Unit):Unit = {
    try {
        //  a long time mission
        doneCallback(results, null)
    } catch {
        case e: Exception => doneCallback(null, e)
    }
}
findCountries((names: ArrayBuffer[String], e: Exception) =>
  //  handle result
)

Kotlin

fun findCountries(doneCallback: (List<String>?, Exception?) -> Unit) {
    try {
        //  a long time mission
        doneCallback(results, null)
    } catch (e: Exception) {
        doneCallback(null, e)
    }
}
findCountries{ list, e ->
  //  handle result
}

Community Support

  • Java Native Support
  • Groovy Official Support
  • Scala No Support
  • Kotlin Official Support

Conclusion

The futher comparasion to be continue...

androiddemoin4languages's People

Contributors

pfn avatar sidneyxu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.