top | item 2584752

C'mon, stop writing Java for Android

133 points| ubuwaits | 15 years ago |robots.thoughtbot.com | reply

64 comments

order
[+] jamesbritt|15 years ago|reply
So what’s stopping you from using Scala for your Android app?

Mirah.

While Mirah is still beta-ish I prefer it to Scala. Maybe it's because I'm already familiar with Ruby, but the "multi paradigm" (i.e. no paradigm) nature of Scala leaves me cold. It's kinda-sorta OO, kinda-sorta functional. But the functional part gives no guarantees of referential transparency or immutable state, so the killer value of FP is lost.

But, language rant aside, even if Scala were the cat's meow, you still have to include the Scala base libraries with every app. Proguard may help, but it seems wasteful.

Mirah, OTOH, compiles down to straight-up JVM byte code. No supporting runtime libs are needed. Very slick.

[+] Dn_Ab|15 years ago|reply
>But, language rant aside, even if Scala were the cat's meow, >you still have to include the Scala base libraries with every >app. Proguard may help, but it seems wasteful.

As someone who is using scala for 2 android apps one small and another smaller, Proguard does more than maybe help, it shrinks it to a small size. From the Scala for Android page:

AndroidForScala includes a treeshaker (proguard) that removes all the parts of the android-scala library that you don't use. For a simple "hello world" the scala library takes up about 10kb, and for a larger real world app (500kb), the library takes up more like 25kb.

[+] sreque|15 years ago|reply
I don't understand all of the Scala hate on Hacker news. First of all, the ONLY language I am aware of that provides guarantees on immutability is Haskell, as it is the only language I am know of that has any kind of serious effects system. I'm sure there are others (Clean might be one of them), but they certainly aren't in common use. That means that you must also not like Scheme/Racket, Clojure, CL, or the ML's, and you must not consider them to have killer FP value either.

Second of all, Scala isn't kinda OO kinda-sorta functional. Scala is actually more OO than Java, C#, C++, and any other statically typed language that I can think of off the top of my head. At the same time, Scala integrates functional concepts and techniques like higher order functions, immutability, and pattern matching into this object system in a very clean and effective way. In short, Scala has accomplished the most beautiful fusion of OO and functional that I have ever seen.

As someone who has used several functional and OO languages, I can witness that Scala is doing something very special and is not worthy of the criticisms you give it, whether or not you like Mirah more, and I am certainly a fan of Charles Nutter's work.

[+] crux_|15 years ago|reply
> But the functional part gives no guarantees of referential transparency or immutable state, so the killer value of FP is lost.

I don't think I agree here. First, the language's type system can give you those guarantees where you need them. (Even Haskell has unsafePerformIO...)

Second, a lot of the "killer value" comes from first-class functions (and in statically typed functional languages, type inference). Coming from Ruby you may not see the huge benefits these would give over Java... ;)

Finally I disagree with the "kinda-sorta" label: The entire Haskell standard library could be rewritten, more or less, in Scala. How is that "kinda" functional? Likewise, obviously any Java code has a direct scala analogue... and with the Dynamic trait, you may even be able to write direct translations of ruby/smalltalk/python-style code too, after a bit of plumbing.

Most (any?) "kinda-sorta" lies with the programmer, not Scala. ;)

[+] FlemishBeeCycle|15 years ago|reply
Mirah is what finally got me started with Android development. Coming from a Ruby background there's practically zero learning curve, plus you can install it from RubyGems (which when using RVM makes it dead-simple).

That being said, for my first application I decided to do it in plain old Java - since I had never worked with Java, I imagined that a rudimentary understanding of its workings would help me down the road in debugging issues that might arise when working with Mirah (somewhat like knowing JavaScript before working with CoffeeScript).

There's even a tool for writing Mirah for Android called Pindah https://github.com/mirah/pindah/ .

All in all, it's quite a nice package.

[+] swdunlop|15 years ago|reply
"you still have to include the Scala base libraries with every app. Proguard may help, but it seems wasteful."

I have started to see Scala coming into Android market apps, and haven't felt they were worse for resource utilization. Bump is the most widely deployed example that comes to mind.

[+] thejbf|15 years ago|reply
>> But the functional part gives no guarantees of referential transparency or immutable state, so the killer value of FP is lost.

Well, forcing objects to immutable on Dalvik VM will be a performance crime. Scala has no practical sense on Android since Dalvik is not made for it.

[+] wccrawford|15 years ago|reply
I'm underwhelmed. At that level, I find the Java version more readable. (I know, I know, the horror.)

But to answer the question posed: Community. I started messing with Mirah, but there's just not much community yet. Any questions you have is a new one. And nobody knows the answer yet. That's fine if you like figuring things out and have time... But drop either of those and it's just a headache.

[+] jamesbritt|15 years ago|reply
I started messing with Mirah, but there's just not much community yet.

True, but as that community includes Charlie Nutter it has a serious leg up. :)

Still, I expect things to move fairly quickly, so the number first-time-asked questions will diminish and getting solid work done will increase.

[+] codesink|15 years ago|reply
I think google is working to move Android to Go as soon as possible; Rob Pike replied to a related question with "I cannot talk about it" and that sounds like a good clue :)

Go binaries already run on Android/ARM, the higher level code is the one that's missing.

That would bring great boost in performance (compilers are available for both x86 and ARM) without adding any complexity on the language side (Go is a cool language).

[+] jraines|15 years ago|reply
Just went to Google to see if I could find anything relating to this possibility, and was immediately reminded how annoying it is, with respect to search, that they named the language "Go".
[+] jdq|15 years ago|reply
Interesting. Possibly to skirt the Oracle/Java mess? If so, I think it's a great idea. iOS/Obj-C has shown that devs will use a new (to them) language if need be.
[+] jemeshsu|15 years ago|reply
With Golang on AppEngine, I can see a momentum within Google pushing for Golang for Android. Rob's comment sounds very positive. I'm guessing we will see something at Google IO next year.
[+] ggeorgovassilis|15 years ago|reply
So what’s stopping you from using Scala for your Android app?

The same that is stopping me from using it for J2EE production code: the insufficient IDE integration. It's quite ok for unit tests though.

[+] mikemaccana|15 years ago|reply
Re: mentioning Python via the ASE in the intro, it's a non-starter: the ASE can't make GUI or OpenGL apps . Other than that: yes, Scala is awesome (asides from all those curly brackets).
[+] muyyatin|15 years ago|reply
Is there a noticeable size increase from including parts of the Scala library? I know Proguard will probably strip out a lot of unused classes.
[+] joshhart|15 years ago|reply
You absolutely need proguard since the Scala library is several megs in size, and will likely grow bigger when specialization goes everywhere.
[+] th0ma5|15 years ago|reply
I haven't tried myself, but I have used GNU Kawa to great success, and your right, Proguard does strip most of it out.
[+] mickeyben|15 years ago|reply
I tried both Mirah and Scala and I'm sticking with Java for the IDE integration.
[+] squidsoup|15 years ago|reply
The IDEA Scala plugin is pretty solid now; worth revisiting if you haven't tried it in a while.
[+] nupark2|15 years ago|reply
We use Java because we don't want to foist a 'weird' language on our clients.

If it wasn't for that, we'd leap at the opportunity to use Scala.

[+] dustingetz|15 years ago|reply
I also would love to hear from someone who has put effort into and succeeded, or failed, at selling their enterprise clients on Scala.
[+] thepumpkin1979|15 years ago|reply
It's true that you can use the NDK to write "Parts" of the app but, don't get me wrong, I don't think it's intended as a replacement for Java or the Java libraries (unless you are writing a game that requires high performance requirements).

I think Java is a decent programming language and Android comes with tools nicely integrated in Eclipse IDE.

I quote: "The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications.

Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. This can provide benefits to certain classes of applications, in the form of reuse of existing code and in some cases increased speed."

See http://developer.android.com/sdk/ndk/overview.html

[+] ikhare|15 years ago|reply
At Bump we use Scala for our the service layer of the application that manages connectivity to our servers and deals with our "business logic". It's a great language when you are within it's rules, and a great way to do succinct state management.

But writing Scala in Android is chock full of gotchas as well. Just today I was dealing with the scala compiler not finding a public inner class in the Android framework, forcing me to rewrite that class in Java. I am fairly new to Scala myself but stuff like this does come up, and can eat up more time than expected.

We've promised a blog post with more details on the pains and triumphs of using Scala in Android. Also if you're going to be at the Scala Days conference next week at Stanford, we're going to be giving a talk about this subject.

[+] sehugg|15 years ago|reply
If Scala can give me a way to abstract all the wacky Activity/Intent/Service stuff, get around incompatibilities between Android 1.5/1.6/2.1/2.2/2.3/3.0, work around bugs in various hardware platforms, provide me a usable GUI layout tool, and maybe even make my simulator start a wee bit faster .. I'm yours pal. Otherwise I'll be sad because I'll just be pretending that I'm programming in the future.
[+] markokocic|15 years ago|reply
This comes too late. Mirah already took the torch for javaless android development.

It's much simpler language then Scala, and compile directly to bytecode without requiring any runtime.

The only thing where Scala is better (for Android development) is better tooling, but I hope that will be fixed soon.

[+] cmars|15 years ago|reply
I'll switch to scala or any other language if it will abstract away SQL cursors with minimal overhead.
[+] leon_|15 years ago|reply
> you don’t need as many semicolons

What is up with the hate on semicolons?

Luckily I know scala but if I didn't and someone would try to sell it starting with that argument I'd get very suspicious.

[+] bonzoesc|15 years ago|reply
They're more typing than no-semicolons and all you stand to gain is code that's harder to read for a majority of programmers. It's really as close as you get to an objectively-bad thing in a programming language.
[+] hunterp|15 years ago|reply
Don't take my System.out's away from me wierdo.