groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maciej Górski <maciek.gor...@gmail.com>
Subject Re: Groovy to develop for Android
Date Fri, 15 May 2015 23:26:57 GMT
Hello Dmitry,

I have to say I've no experience using Kotlin, so I won't say about it much.

We are developing an app almost 100% in Groovy. It's been only 4 months I
use Groovy for Android (or anything else for that matter), but for me it
works well.

So before I go to my language of choice, a few words on Kotlin:

You may find the document attached to this post interesting:
https://plus.google.com/+JakeWharton/posts/WSCoqkJ5MBj
Jake Wharton is one of the most recognizable personas in Android dev
community.
He wrote there a comparison of several languages, including Groovy and
Kotlin, that could be considered for Android development with some pros and
cons for each.

For me personally Kotlin is not ready (yet), because it doesn't have
support for Annotation Processing API (JSR 269) or AST transformations.
Groovy (since a release of Gradle 2.4) supports them both and had AST
transformations for quite a long time anyway.
A lot of libraries for Android are based on JSR 269, saving you time
writing and reading boring code.
Nevertheless I know a few people that develop in Kotlin in production.

So I will try to lay down a few cons I noticed when using Groovy.

Android Studio has a real nice set of features boosting productivity in
Android's Java + XML world. This will most likely be the same for Kotlin or
other languages.
In Groovy you cannot go directly to layout file by executing "open
declaration" action on R.layout.main_activity or R.id.text_view in code. It
goes it R.java file, which is useless.
In Java files you can extract resources (e.g. strings) via "show intentions
actions", which you cannot do in Groovy files.
There is no support for @IdRes and other annotations, which help avoiding
bugs during compilation.
There are more of such examples related to Android itself, but these bother
me most of the time.
A recent release of Android Studio 1.2 (based on IDEA 14) brings better
support to Groovy, but overall it's worse than Java: extracting methods
doesn't recognize other places with the exact same code, you cannot move
method to another class, etc. Of course I'm not blaming JetBrains for
anything here: Groovy is dynamic by nature, and they did a lot of good work
to support more and more from this language recently.

Like you mentioned, Groovy will be slower than Kotlin or Java. Using
@CompileStatic annotation on each and every class makes it better.
I don't have any benchmarks here. I would really like to see a non-trivial
app written in these 3 languages and if, as a user, I can perceive any
differences.

Yes, the binary will be bigger by a few MB. Not a big deal for me, but
sometimes it can be a problem.
There is also a consequence there that I write about as an answer to your
first question below (64k methods).

Groovy on Android is still new and so will hit you with some weird issues
from time to time, e.g. https://jira.codehaus.org/browse/GROOVY-7328

On the bright side there are all groovy things I learned in the last
months: DefaultGroovyMethods, closures, method pointers, currying, etc. and
even occasional @CompileDynamic that make you more productive. Writing less
code, writing more readable code and reviewing less (and readable) code.
Using RxJava without Groovy or Java 8 makes my eyes bleed.


2015-05-15 18:43 GMT+02:00 Dmitry Semionin <dmitry.semionin@gmail.com>:

> Hello everybody,
>
> Recently i decided to learn how to develop for Android. But after learning
> some Java and reading about the way the modern Java features are adopted by
> the Android toolchain, i realized that the "classical" Java is not my way
> towards Android. Some googling around showed that two of the most obvious
> alternatives are Groovy and Kotlin. Both of these options have their pros
> and cons, which i will mention below. And since the most typical Q&A place
> for programmers (StackOverflow) doesn't approve the "... vs ..." questions
> calling them non-constructive, my best option is to look for practical
> advice from the Groovy community. Hopefully that won't be against any rules
> =).
> Long story short, in theory both variants are not perfect, and i would
> really like to cut some corners and learn from someone else's practical
> experience. Asking the Kotlin community doesn't seem like a good idea since
> they are corporately backed and may have some bias towards the competitors.
> And Groovy is an open tool nobody's paid to endorse, so who could answer my
> questions better than you guys =).
>
> Anyway, that's what i've read so far about Groovy as a tool for Android
> development.
>
> Pros:
>
> 1. As of version 2.4, Groovy officially supports Android as a platform.
> 2. I seem to like Groovy's syntax compared to Kotlin's.
> 3. It's been around for a while, much larger userbase, tons of answered
> questions on SO, several books from independent authors, so it looks like i
> won't be alone in the woods on this path.
>
> Cons:
>
> 1. No official Android development guides, and not much 3rd party info
> that could work as a guide for Android development using Groovy.
> 2. From what i know, the shaky situation with project sponsorship, so it's
> unclear how well will the project be evolving.
> 3. The benchmarks i've seen show that Groovy is substantially slower than
> Kotlin and its runtime is heavier, which means performance drawbacks and
> bigger binaries.
> 4. Lots of resources claim that Groovy is a dead end and that the interest
> to it is on a steady decline. Don't know if it's true but i'd definitely
> like to avoid studying a dying technology.
>
> As for Kotlin
>
> Pros:
>
> 1. Strong support from a big and successful company who knows how to make
> development tools.
> 2. Is said to be small and fast.
> 3. In every "Groovy vs Kotlin" discussion i've seen so far, Kotlin is the
> one people recommend.
> 4. Has a section in documentation dedicated to Android development, so at
> least setting up the required tools won't be a problem.
>
> Cons:
>
> 1. Kinda immature, still in beta, not so widely adopted.
> 2. I don't find its syntax appealing.
> 3. Best suited for use inside the JetBrains ecosystem, which means that
> outside of it there might be some issues.
>
> To make myself formal, i'm addressing only those of you guys who had an
> actual experience developing for Android using Groovy/Kotlin:
>
> 1. When developing for Android with Groovy, did you encounter any issues
> that you could not easily solve and that made you consider switching to a
> different programming language?
>

Android has a limit of 64k methods (and 64k fields) for entire app,
including dependencies. Groovy brings almost 30k methods. This means, if
you use a few other bigger dependencies (facebook, google play services,
support lib), there is no place for your methods. There are two ways to
solve it: shrink with obfuscator like Proguard or use multidex support
(which makes your binary split into multiple dex files, each containing max
64k methods).
We hit this limit very early and I spent a few days on it.
Removing unused methods from the app wasn't a big problem, but there was
(claimed to be solved by now) a bug in Android tools from Google, making
instrumentation tests always fail when using Proguard.
In the end I didn't use that, but switched to multidex. This is also bad
because build time is 3 times slower, if you don't set minimum Android SDK
to 21 (Android 5.0) when testing on devices or running instrumentation
tests locally. So we do have it set locally most of the time.
We also had some issues there with running tests on Travis CI when applying
that.
You may see this commit if you want to save yourself time figuring this
out:
https://github.com/OrdonTeam/Groovy4Android/commit/8585a85c5d2df9b5b0cb3a8f600ec32a6677e3b9

But when I asked the other developer in face of these problems, what he
thinks about switching to Java, he replied, he would quit the job and go
somewhere where he can use Groovy ;)



> 2. Could you recommend Groovy as a primary Android development tool to a
> programmer with no previous Android experience?
>

I would recommend using Groovy for tests. Espresso looks neat without all
the brackets and Spock is fun for unit testing.
I also recommend using Groovy for any side / pet project.
I also recommend it to myself for my next Android project. It will be hard
for me to go back to Java.



> 3. (Optional, answer only if you feel you have enough of an outlook on
> this topic) What language (and related tools) seems the most optimal to you
> for Android development, if we took into account flexibility, learning
> curve, stability and the public adoption?
>

I'd say it's and will be Java. Android Studio (or Intellij IDEA) is a must.
Gradle comes with that as a standard now and is recommended by Google. All
the examples you find on StackOverflow are in Java. Optimal for most devs,
not so much for me.


>
> Please correct me if i did something wrong, it's my first time using a
> mailing list. And obviously thanks to everyone who'll find a time to read
> this email and answer my questions.
>
> - Dmitry Semionin
>

Mime
View raw message