358 points · by myko · 12y ago · 156 comments
Yeah, I'll be trying out Go for Android. Give me an excuse to learn Go. Still don't like the idea of going without generics and exceptions, but maybe it'll surprise me. I figure we're all just biding our time until Rust is ready.
https://github.com/rust-lang/rust/wiki/Doc-building-for-andr...
More recently:
https://mail.mozilla.org/pipermail/rust-dev/2014-June/010323...
It isn't integrated, and as they note as one of the gaps, doesn't currently support CGO (meaning you can't compile C code or libraries in with your Go executable), but it has worked quite well for some time.
While I did jokingly say "Serious UI Toolkit", there's more than a few awesome applications on Android that have very, very simple UI widget requirements. Particularly games, which according to the article, they're focusing on.
That's a ridiculous assertion.
Who is "he"? The poster michael was replying to said s/he was waiting for Rust to be viable.
I'm pretty sure that was contributed by Samsung.
val, err := error_prone()
if err != nil {
return nil, err
}
let val = try!(error_prone());
Personally, I find that error handling isn't that bad in go. I think it's at least no worse than exceptions. Exceptions make it too easy, for me at least, to just mindlessly propagate the error. Sometimes that's the right thing to do, but in go it's a lot less repulsive to handle the error since to propagate the error you would need handling code anyway.Rust strikes a nice balance. You have to explicitly handle every error, but if you go with the by far most common handling code, you get some nice sugar that makes it mostly painless.
I think Dart or another JVM language are the only hope for getting away from Java on Android. Dart is maybe a longshot at this point though.
Looking back I wouldn't mind developing on Android again but I wouldn't want to necessarily do anything with Java by itself.
The level of hackery even drips down to their own documentation and code examples. There is a line in an old example for a TabPager I believe that said "It relies on a trick." How is this acceptable API writing and role-modeling from Google?
Kotlin seems approachable and modern. Also compiles down to JS.
Case in point: To make a list on Android, you need to jump through hoops, assign stuff to a "Tag" property (a field intended for hacks and workarounds), typecast your ass of, or if you don't do all that your list will perform absolutely shitty. So, the easy flow is a crappy, slow, buggy list. The "best practice" (which is not the easy flow, because hey, why would we make good stuff easy) is a "View Holder Pattern" [0] that involves using intended-for-hacks framework features.
On top of that, to my feeling there's also a big difference in quality between the enterprisey Java ecosystem and the Android ecosystem. Android-o-world is full of not-entirely-good advice and bad examples. Jumping into Android reminded me of past PHP experience: lots of well-meaning, but ultimately not-very-experienced people set the tone. Enterprisey Java might have AbstractFactoryFactoryProviders, but at least they have no buggy/wrong/hacky/insane code with 300 stackoverflow upvotes.
[0] https://developer.android.com/training/improving-layouts/smo...
You don't have to do that. For a list with homogenous items you can use a regular ol' ListAdapter, implement getView sensibly (i.e. re-use views, which is very little work) and it will perform just fine. We tried this with a list of 2,000 items (each item had two TextViews and an ImageView) and it was completely fluid on a Samsung Galaxy Ace.
> Android-o-world is full of not-entirely-good advice and bad examples. Jumping into Android reminded me of past PHP experience
I could not agree with this more. I'd say somewhere around 2/3 of StackOverflow Android answers are downright wrong.
Everyone else just uses CursorAdapter which is easy to use and ties in nicely with things like Loaders and ContentProviders.
That's why there are all these crutches like Joda, Guava etc.
Anything GUI or system-related you have to do in Java. You won't be able to use Go to run other apps, enable wifi, receive GPS locations, communicate over bluetooth, etc. etc.
Qt is worth a look, but it's still not quite ready.
The hole point is getting advantages. Lucky us that it's hard; others won't keep pace!
It's got nothing to do with open source. Instead it reflects the different approaches taken by Apple and Google.
Apple designs something new, tries hard to get it right the first time, and commits to it completely. Swift is the way to write for Apple's platforms, period. It's appropriate for a "social media application, all the way up to a high-performance 3D game." There's no doubt that Swift is meant to succeed Objective-C.
Google experiments more, sees what sticks. Go, Dart, Dalvik, v8, NaCl... You sure have lots of choices, but the relationships between these technologies is unclear, and has the character of uncoordinated teams working in isolation.
While Go is a feasible replacement for C/C++ for native parts of Android applications (which are just normal Linux .so libraries linked against bionic) it would be a terrible fit for main application language without a full rewrite of most of the operating system (note that ART is certainly NOT a magic bullet here!). Note here that native (NDK) code has practically NO access to Android OS APIs (only APIs available are bitmap manipulation, OpenGL, OpenAL and limited sensors access).
It's staggering just how many misconceptions and lack of understanding of Android structure is there in those "Go for Android" threads.
For us Android devs pretty much three points would improve the Android development experience:
1.) Add Java 8 language feature support to ART/Dalvik runtime. This would clean up code immensely, especially in so concurrency and callback heavy use-case as a mobile app is.
2.) Clean up Android APIs and fix broken implementations. Add modern block/callback based APIs to replace listener-heavy code. Perhaps look at RxJava design patterns for core Android APIs as well.
3.) Improve tooling. Not the code editors (IDEA/AS with Maven or Gradle are decent enough), but the profiling tools, hiearchy viewer, tracing tools and other tooling which wasn't touched in years and are SORELY needed for good app development. Figuring out why a certain animation stutters right now requires stitching together several partially working tools with poor documentation.
Note that NONE of those issues would be improved by adding Go as a language to interact with Android and would just cause additional issues on Go/Java boundaries.
Oh really? That must be why they removed all of their USB and HDMI ports to replace them with Thunderbolt ports. Anyway, let me get back to writing my IOS apps in AppleScript and hosting my website on my Xserve. While I'm doing that I'll being sharing my music listening habits will all of my friends on Ping.
The point of that is that they hardly ever commit to things as 'completely' as you imply. They just have a conservative marketing strategy where they won't release anything until much later than most companies would.
Quite the opposite.
Wouldn't there be more people to write books and to work on SDKs when a language is openly developed?
Android is fairly open. You can run whatever you want on that platform. If you want to use LuaJIT, no one can stop you.
Also, this isn't "Google". It's one guy working for Google. He's on the Go team. He wants to make Go a viable option for games on Android.
If you like Go, this is a good thing.
go language spec hit #1:
dart language spec hit #1:
https://www.dartlang.org/docs/spec/
java language spec hit #1:
http://docs.oracle.com/javase/specs/
For Swift, I can only find guides and references.
There are quite a few more Android developers than iOS ones, not sure what point you are trying to make.
Go will probably have zero impact on Android but Java has certainly been instrumental to Android's success.
Do you have a source for this? My observation is that it's much easier to hire iOS developers than Android developers.
Around here (Central Europe, Austria) it's the other way around. It's a little bit harder to find good Android jobs than iOS jobs.
Maybe because Java has always been one of the more popular languages here and the amount of Android devs is just higher than the number of iOS devs.
Go in this case is seen sort of an in-between C and Java. But Go is not really as fast as C as much as we want it to be. So I don't know. Maybe it will be useful for something already written in Go to be ported. But I would rather see Dart succeed as a higher level-than java development language (both on Android and on the Web).
Years back I hoped Python would do that (being Guido was at Google and all). But as he confessed there was a minor political struggle internally over it and Guido lost. Not too long after he left Google.
Because of the phones and batteries, AOT languages are more valued and even ordinary jitted languages are getting a AOT compiler.. ART for Java and even .Net
So Dart would need to have a AOT compiler first to make it more appealing to mobile phones.. also i think a lot of apps would not like to be distributed in source code form..
So langs like Go now are on the rise.. its funny how technology trends change over the decades... not while ago it was all about dinamic languages..
It may be several step beyond what a small team could do in a short time, but not intractable.
Shooting from the hip, the job looks like this:
1. Add Go language and debugging support to the ART runtime environment
2. Port the standard Go packages, using a single-architecture backend modified to produce ART compatible binaries to bootstrap
3. Add equivalent support for RPCs (AIDL) and Renderscript
4. Build equivalent APIs for those in the android.__.__ packages that make sense in Go, possibly taking this an an opportunity to redesign some APIs
5. Create equivalents for the apache.__.__ and java.__.__ that don't have equivalents or alternatives in the Go packages
6. Splice in an intermediate representation and refactor the Go compilers to be ART pre-compilers, or take the easy way out and compile go to a possibly enhanced Dalvik bytecode
It may seem daunting that Dalvik and ART embody Java runtime support, and that the current (near-future, really) toolchain goes Java -> Java bytecode (and acquires a lot of Java-oriented tooling this way) -> Dalvik bytecode -> native code precompiled for ART. But I do not think it would bloat an Android runtime too much to add Go as a first class citizen. The build chain has become a little awkward anyway with Dalvik bytecode as an intermediate step that making a Go back-end that compiles for an ART-specific intermediate language might be cleaner.
How do I put an asterisk in a comment here?
Without the intermediate step (bytecode), you are pushing the awkwardness to every individual developer.
The real problem would be porting all the current APIs. If Google actually decided to do this though it would be a good opportunity to clean up the current APIs and provide a new version free from legacy cruft. So it is doable, but a fair amount of work to provide UI bindings etc.
The obstacles are more political and monetary than technical.
Android is open and the potential number of hardware targets is limitless. It's not just about the size of the binaries; the app and the programmer should ideally be agnostic of the hardware. On an open-platform with closed-source applications, the least awkward way to do this is to push the native translation to the run-time.
Currently, ART uses Dalvik bytecode as a platform independent intermediate representation. I wonder if Dalvik bytecode is ideal for that purpose.
AFAIK, ART doesn't "use" Dalvik. It is an ahead-of-time-compiling run-time for Dalvik. IOW, ART wouldn't exist without Dalvik.
What would be cool/interesting is if you can write half decent audio processing code in Go for Android without the GC kicking in at the wrong moment.
They're 100% right about the broader API though.
I'd really love to see Google throw some serious engineering muscle behind Rust, with the long-term goal of making it the default first-choice language for Android development. I'm not holding my breath for this though.
The design of Swift was somewhat hobbled by ObjC/Cocoa legacy requirements but it's still much better language for native client development than Java, IMO. Sooner or later Google is going to need a better story here.
I'd be happy to be convinced otherwise by someone who knows more. :)
Since you are not forced to think about lifetimes, then you get memory leaks, double frees and dangling pointers, usually leading to crashes in totally unrelated locations or worse, security exploits.
Also XNA is reborn as MonoGame. Microsoft wants to decouple from it's APIs and tools by offloading to OSS and third party (Unity3d).
So this way C# got a foot on the door, long before XNA and Managed Direct X came into the picture.
Our client dev is all Unity, however, and I don't quite see Go entering our client dev cycle at all. And I'm a huge Go fan.
Having said that, I'm not at all interested in writing an app that was Android only so I'll be sticking with javaScript for a while yet.
.so support on Android is pretty broken even with C/C++ code. For example, do you know the Unix versioned .so convention? Compile to foo.so.1.142, then create a soft link called foo.so -> foo.so.1.142? Android doesn't support this in general, even with C/C++ code (see [1] for discussion; my recent experience with this issue is that it hasn't since been resolved).
[1]: http://grokbase.com/t/gg/android-ndk/11ae9h0sm5/how-to-load-...
Look at go-android (already working for quite a while).
However, I like Ruby. In that department, RubyMotion the popular iOS/Mac alternate programming toolset is coming to Android. Seems the floodgates of "use your language of choice" are opening...
If you are interested in alternate languages and tool sets for your development I'd give this a look. http://www.rubymotion.com
1 - The tour. Seriously, just go through tour.golang.org and...you know Go. From there it's just little tricks and best practices, many covered in 'effective go'
2 - It's a tiny language. That's a plus or minus depending on who you ask.
If you aren't new to programming in general, you can pick up the majority of Go in a day I think.
https://groups.google.com/forum/m/#!topic/golang-dev/eqBihsj...
For most cases it's just not worth it.
The point I was making is that despite the downsides, even people from inside google are using it now. Makes the android teams 'pretend ndk does not exist' stance rather ironic.
NDK is just a preconfigured GCC for cross-compilation anyway (with custom build script). Native C code compiled with NDK is used all over Android core and it's used regularly in apps to provide speed boosts. But it has practically no access to Android APIs (with exception of OpenGL/OpenAL some sensors and bitmap functions) so it's totally unsuited for development of a full app in C or C++. It's role is pretty much the same as C code in python libraries - to provide boosts for performance critical code.
Taking that into account, I really have no idea who acts like "NDK doesn't exist". It's widely used, it's just not suitable as a main way of developing an app.
Go has been on my radar since forever but I haven't written anything in it. This sounds like a cool announcement. I think my next mobile experiment will involve Apache Cordova though but now I'm tempted to give Go a shot (game is fine with me)
If you want to check out Go, then the Go Tour [1] and the various talks by Rob Pike [2] [3] / Sameer Ajmani [4] are great resources. The Go Tour stands on its own as an interest-building resource; the several programming exercises it has you do are fun and challenging.
[1]: http://tour.golang.org/#1 [2]: https://www.youtube.com/watch?v=f6kdp27TYZs [3]: http://blog.golang.org/concurrency-is-not-parallelism [4]: http://blog.golang.org/advanced-go-concurrency-patterns
And yet with Go there is more use of it for CLI apps and web apps. Adding mobile to that equation just makes it even more complete.
Good job Google.
What this proposal brings is access to the NDK APIs. You could run Go on Android since over 4 years now.