Go support for Android
docs.google.com
docs.google.com
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.
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.
That's a feature to me. Respect my Cache-Control headers!
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.
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.
Part of the problem with Java exceptions is too many people feel obliged to catch exceptions, when they should be propagated.
Ideally, the only catches would be in the top-level loops (request / response dispatch for server, event loop for GUI, arguments for command-line).
Wrapping exceptions as they bubble up is only helpful if the wrapped exception adds context that aids in diagnosing the issue. Otherwise it's just boilerplate that obfuscates and gives a certain type of developer warm fuzzies. "Exposing implementation" is a non-counterargument - the component failed because its implementation preconditions were violated, you need to address those implementation preconditions to fix the problem!
You don't need to import dependencies unless you intend to catch the specific originally thrown exceptions, and that's not normally what happens in the top loop; it normally logs, dumps or transmits the exception message and possibly its stack trace. These operations are normally only rely on the base exception type, so there's no need to catch a more specific exception.
Problem languages for this approach, though, are C++ (where the culture makes a single base class for exceptions awkward) and Java (where throws clauses, a deeply misguided feature, may force dependency imports unless you specify 'throws Exception' - or my preference, wrap in RuntimeException).
PS: I should add the other fundamental problem with the Java throws clause is that it uses static types to analyze dynamic data flow in a language with polymorphism, which makes it a usability disaster. When the code being invoked is indirectly accessed via polymorphic references, exception flow checking falls apart. There's a reason Google Guava's Function and Predicate interfaces don't throw. But that's enough of my bugbears.
The "finally" clause is underused in most Java programs and the "catch" clause is overused.
I don't think this is necessarily true; assuming an XML parsing library that throws exceptions on malformed XML, you are more likely to have simply supplied generally invalid XML than to have hit an implementation-specific exception type.
So, the exception is only implementation-specific in the sense that it was created by an implementation of the class of software you wanted.
But really, in my mind the issue of not wrapping exceptions means all of your client code is now tied to the transitive library, which means the implementation can't be changed without breaking API compat.
The top-level application is usually a composition of libraries.
So in practice, I'm sanguine about apparently transitive dependencies. I prefer when exceptions from one library's plugged-in dependency flow through unmolested, as I see the libraries as mostly a flat dependency of the larger application. If you pull in dependencies transitively without paying much attention to them, you're sowing seeds for trouble with versioning, security scope, risk of stale projects if they're open source, etc.
I think of this as a corollary of Spolsky's law of Leaky Abstractions. Passing through exceptions means not trying to fool anyone into thinking they can work with the high-level abstraction without understanding anything about what's going on underneath.
Ideally the standard library provides base classes that act as core categories for different kinds of exceptions - IO, programmer error, data format error, etc. - so that general code can be written after a fashion when necessary. But I think you're fooling yourself if you think that such general code can be written the majority of the time, much less all the time. What's underneath always leaks through, one way or another, and if you try to ignore the thing that's underneath, you'll end up with brittle inefficient code.
Where high-level wrapping exceptions are justified is where there is an obvious chokepoint in the design - where the interface between several layers is very narrow. But this typically is at the junction between a service and a client - e.g. a web front end and back end, or async job queuing service, etc. - something where there is a service loop and probably service-specific logging of original exceptions, anyway.
Except this is not what happens in reality, very few people see an internal exception type and go investigate the details.
Sure it's shitty practice, but it seems orthogonal to whether the internal exception types are exposed.
I'm not saying people should just ignore what is underneath, I just think that as a library developer, you significantly constrain what you can do without breaking API compat by exposing internal exceptions.
You could take a hard line stance and say that it should be a breaking change and people should go and re-evaluate the library after the change, etc, and then rewrite their code to deal with new exceptions. But in reality it just means that library will no longer get updated, and will effectively become stale for no good reason.
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.
https://github.com/rust-lang/rust/wiki/Doc-building-for-andr...
More recently:
https://mail.mozilla.org/pipermail/rust-dev/2014-June/010323...
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.
Who is "he"? The poster michael was replying to said s/he was waiting for Rust to be viable.
That's a ridiculous assertion.
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.
The hole point is getting advantages. Lucky us that it's hard; others won't keep pace!
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.
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..
Eg. Basic, Javascript, Objetive-C
As i dont think people actually conciously choose to write in those languages because of its features.. thats why we have so many people grumpy about those technologies..
Languages that we choose because of better features, pretty often loose in popularity and adoption..
Sometimes those languages have some heroic comunity efforts and a vibrant community that can make it stand.. but this is pretty rare.. Python, Ruby(because of Rails)
It has almost the same mechanics of the fashion industry.. Some influential people decide what we gonna wear on the next 5 years..
We can use our "hobby language" of choice, because its our own decision.. but in the end of the day.. we have to mantain and work in code on those languages missing the "features, abstraction power and maximized interactivity" we love so much
Incorrect, or at least badly lacking historical context and perspective.
Basic: interactive. (Primitive REPL.)
Javascript: it was there. If it wasn't there, everywhere but influential people just wrote about it then it would have languished. Also, it is interactive.
Objective-C: has a lot of very good OO which was heavily influenced by Smalltalk. It is precisely the OO excellence that it was known for and which engendered fierce love for it in certain circles.
Remember also that these languages have been around for a long time, on hardware far less powerful than what we have today or even had a decade ago. The youngest of these languages is Javascript by far, and it is almost 20 tears old! For their day, they were advanced with respect to the programming mainstream by at least one measure. (In the Apple II days, BASIC was there, and it was interactive, and that was enough.)
I'm not saying these were the best available. But there is more to it than just fashion and influence/hype. (Otherwise we'd all just be using Java in the browser and for app servers.)
Also: Ruby was a hobby language once upon a time.
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.
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.
But I agree, finding a good Android developer here in central europe is rather hard. Also finding a good Android job is rather hard - payment offers are usually atrociously bad.
Do you have a source for this? My observation is that it's much easier to hire iOS developers than Android developers.
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.
As for IDEs, personally I grew to prefer Android Studio to Visual Studio (well, no ReSharper), although I have much more working experience with the latter. Especially in terms of navigating around the project. VS native refactoring tools are very rudimentary, too, even in VS 2013 - not much seems to have changed in YEARS.
In short, what I'm saying is, that at the current state of Android, implementing Java 8 features would bring simillar benefits than switching to a whole other language without having to rewrite whole runtime and most of the operating system.
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.
That doesn't even make sense. Thunderbolt and USB/HDMI cater to different needs. When they added thunderbolt they DID take out their Firewire ports. And when they added USB they did take out legacy mouse, keyboard etc ports.
>Anyway, let me get back to writing my IOS apps in AppleScript
Again, doesn't even make sense. Applescript is a legacy language they maintain. Designed pre-OS X. Not something they actively designed for iOS or anything.
>and hosting my website on my Xserve
They would, if enough people were interested. They weren't, so they killed the product. Same for ping.
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.
https://developer.apple.com/library/prerelease/ios/documenta...
"The grammar described here is intended to help you understand the language in more detail, rather than to allow you to directly implement a parser or compiler."
A language specification is for people who want to implement a parser/compiler/VM/etc. It's something you need if you want to standardize it (e.g. TC39 [ECMAScript] and TC52 [Dart]).
A language specification is also generally clearly labeled as such.
http://en.wikipedia.org/wiki/Programming_language_specificat...
PHP, for example, doesn't have one.
Edit: I forgot to mention that both Go and Java lack ECMA and ISO specs.
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.
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.
ART and Dalvik fill the same role, and are redundant with each other. They both take DEX (which I suppose you could call Dalvik bytecode, but now that it's runtime independent it should just be DEX bytecode) and ART ahead-of-time compiles it into native code, while Dalvik JIT compiles it into native code where possible.
That makes the difference sound greater than it really is. In reality ART is simply "rebuilding Dalvik from the ground up based upon everything that had been learned". It isn't 100% reliable right now because it's an incomplete runtime with some issues.
Dalvik bytecode (DEX) was designed to efficiently interpreted. Eventually, Dalvik added a JIT compiler suitable for battery powered platforms. What ART stops short of is replacing Dalvik bytecode, perhaps with a more efficient intermediate representation for the purposes of pre-compiling.
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.
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.
http://blogs.unity3d.com/2014/05/20/the-future-of-scripting-...
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.
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.
Any language with automatic memory management, be it via dataflow analysis, RC or GC is managed.
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.
Look at go-android (already working for quite a while).
.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-...
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.
And the NDK is a rather neat solution to the compilation issue. Once you've set up the toolchain properly, different architectures are simply not an issue. There's no architecture that Android runs on that doesn't accommodate native code.
After all, don't forget that under a rather thin layer of Java, the native code "cancer" is what is driving Android.
If you are talking about BINARY portability (which is what everyone was actually talking about), then native code isn't portable for shit, whereas Dalvik code happily runs on multiple flavors of ARM, MIPS, and x86 with official or partially-official support.
Unless you are proposing that Android adopts a Goobuntu design of "compile everything from source", then the portability of native code source is utterly irrelevant. And if you are proposing that, you are hopelessly naive. Not to mention you must really, really hate having battery life if you want to spend over an hour compiling & installing, say, Firefox.
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.