TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Scala: The Android programming language you didn't know you had

47 点作者 bleakgadfly超过 13 年前

6 条评论

unoti超过 13 年前
I do game programming for Android, and use Scala for my server infrastructure. I'd like to use Scala for the Android device as well, but haven't even tried because I'm concerned about garbage collection. You see, I can't even use Java iterators in areas that are called on every frame on the Android device, because those create little object instances that will trigger garbage collection. So I have to write for loops. There are all kinds of things I need to do in an action game in Java on Android to carefully pre-allocate my memory and not trigger garbage collection.<p>When I look at the code that Scala produces, it's spinning off little instances of auto-generated classes all over the place to work the magic that it works. You can't breathe in Scala without it generating a few anonymous classes and instantiating them. All that is fine for an app where the device is idle between UI events (a "normal" app), but how does it fly in a game? I can see and "feel" a noticeable glitch when my machine GC's, and I need to avoid that pretty much at all costs. How in the world do you avoid that with Scala in an action game? So far I've been assuming that you pretty much don't avoid it, so I haven't bothered trying to use Scala for my games on Android.
Tichy超过 13 年前
Any news on Clojure for Android? Last I checked (~1.5 years ago) it was too slow because reflection works differently on Dalvik than on a normal JVM, or something like that.<p>I would prefer getting into Clojure over Scala.
评论 #2937032 未加载
评论 #2937510 未加载
评论 #2937760 未加载
wccrawford超过 13 年前
"To start with, you don't need as many semicolons."<p>Is this a cute way of saying you will end up with fewer lines of code to do the same thing, or that you just don't need to use semicolons?<p>I think if you're trying to convince someone to use a new language, you should be a little more clear.
评论 #2937112 未加载
评论 #2937396 未加载
Dn_Ab超过 13 年前
I would like to share my experience with Scala and Android. Maybe someone can tell me what I am doing wrong.<p>Speed and start up time does not appear to be a problem, even if you are using a good part of the library. The problem with scala is it takes so darn long to build your simple app. Size of generated output is not a big deal, though it will be larger than Java for simpler stuff. But unless your app is trivial the media elements will make a much larger contribution to your final size than the code. Also the growth is non linear. Here is what I mean.<p>If you hello world and proguard your app will be the same size as a java app. But once you bring in some scala stuff - collections or language features which need the library it grows by an order of magnitude. So a 20k Java app vs 100k Scala for the same app. After that initial bump the additional baggage is gradual so that eventually the java app of similar complexity will generate similar sized output. Speed is not meaningfully impacted in my experience. If you are making a game it would be worth considering preallocating arrays and doing basic memory management to avoid stalls.<p>You will have to avoid some idiomatic scala because functional programming is too easy going in terms of allocation. So manually iterating java hashtables and arrays instead folding over maps and lists. I will note that for my simple app I fold over lists with little impact for now. Scala has the basic advantage of being a java with less boilerplate. The little things add up. But if you are not using it as a functional language is it worth it? I think so. Instead of using it as just a functional language you can use it as something else. more? By leveraging caseclasses, Extractors and pattern matching you gain in expressivity while retaining declarative elegance. your mileage may vary.<p>So the problems are: You can't easily debug. But Mostly, building takes Forever. It takes 4-5 minutes to build the simple hello world activity. I humbly suggest the scala team look at their android support.<p>Getting F# on WP7 was a piece of cake in comparison. Building is normal, debugging is there and getting it to work was a matter of referencing a targeted dll.
vorg超过 13 年前
&#62; Statically typed Java language pushed as alternative to JRuby and Groovy for building mobile Android apps<p>According to the SpringSource P.M. for Groovy: "Groovy is not able to run properly on Google's Android mobile platform. A project started porting Groovy to Android, but performance wasn't there (20 secs to startup a simple Hello World)" (<a href="http://docs.codehaus.org/display/GSOC/Groovy+Ideas" rel="nofollow">http://docs.codehaus.org/display/GSOC/Groovy+Ideas</a>)<p>Perhaps Scala is the ONLY alternative to Java.
fosk超过 13 年前
Drawback: the environment must load the Scala runtime.<p>Sometimes is better to add some semicolons instead of slowing down the whole device.<p>Scala is great, but in this case the choice must be made carefully.
评论 #2937843 未加载