Live data from Hacker News

Anko – Pleasant Android development in Kotlin

github.com

21–30 of 38 posts

Re: Anko – Pleasant Android development in Kotlin

#21

> XML is parsed on the device wasting CPU time and battery It was my understanding the XML was compiled into a binary format for faster parsing on device, am I wrong on that? EDIT: http://en.wikipedia.org/wiki/Android_application_package "resources.arsc: a file containing precompiled resources, such as binary XML for example." Ah yes, I think it does. > Most of all, it allows no code reuse. If we are talking code reu…

> It was my understanding the XML was compiled into a binary format for faster parsing on device, am I wrong on that?

That's correct, but it still requires the additional overhead of parsing the compiled resources and using reflection to instantiate Views. Anko instantiates Views directly.

Re: Anko – Pleasant Android development in Kotlin

#22
This is great, and looks so much easier (as does Scaloid), but I have never found a commercial project that I can use it on. #1 by choosing Anko or Scaloid you are isolating future developers to only those familiar to Anko or Scaloid OR those willing to learn (as well as the fact that Scaloid doesn't sell very well on resumes IMO; my guess is the same for Anko).

It's a dilemma, as Java+XML is very verbose. still, with the amount of work Android Studio does, I'm not sure its a big problem for most of us Android Developers.

Re: Anko – Pleasant Android development in Kotlin

#23
post #3
post #2

After a quick skim this seems great, but just one piece of a much bigger puzzle. Android activities, regardless of whether the view is constructed declaratively or in code, seem to always become an untestable mess that does way too much. At least, that's what happens if activities are used as intended. IMO, the bare minimum necessary to fix this is some more elegant alternative to AXML that, crucially, has some kind…

You might like Anvil: it's a declarative react-like UI library for Android. I personally use it a lot, and I normally write single-activity applications (e.g. I have my own backstack of views inside a single activity): https://github.com/zserge/anvil http://zserge.com/blog/anvil-2.html Kotlin is supported as well ( http://zserge.com/blog/anvil-kotlin.html )

Apps like that are a pain. No matter how you reach it you end up on a infinite stream of things you don't care anymore and have to keep pressing back.

I think yelp is written as that. And to add insult when they moved to the material hype the home button on top left became yet another back button... they did add shortcuts on the left now. But it's all breaking stuff and adding bandaids on top of bandaids

Re: Anko – Pleasant Android development in Kotlin

#25

This is great, and looks so much easier (as does Scaloid), but I have never found a commercial project that I can use it on. #1 by choosing Anko or Scaloid you are isolating future developers to only those familiar to Anko or Scaloid OR those willing to learn (as well as the fact that Scaloid doesn't sell very well on resumes IMO; my guess is the same for Anko). It's a dilemma, as Java+XML is very verbose. still, wit…

It may not be a big problem for most of you Android developers, but for me at least what makes me not do Android development is how incredibly cumbersome it feels. I'd like to, but I just can't make myself suffer through it.

I think the kind of developer who dislikes the current Android dev alternatives enough to avoid it as much as possible is more likely to be the target audience for most of these alternative tools than you are.

Re: Anko – Pleasant Android development in Kotlin

#26

> XML is parsed on the device wasting CPU time and battery It was my understanding the XML was compiled into a binary format for faster parsing on device, am I wrong on that? EDIT: http://en.wikipedia.org/wiki/Android_application_package "resources.arsc: a file containing precompiled resources, such as binary XML for example." Ah yes, I think it does. > Most of all, it allows no code reuse. If we are talking code reu…

Actually resources.arsc only contains the resource table (think stuff in values/ folders, like strings.xml). The layouts still have their own xml files in res/layout. It is in Android's XML chunk format though, not plain-text xml.

Interesting point - the resource table still has references to the XML files for configuration-resolving purposes, but they are only strings. E.g. getString(R.layout.main) will actually work and return "res/layout/main.xml" or "res/layout-land/main.xml" depending on the device configuration (and assuming one has the layout-land version). Vice-versa, if you have a string resource with the value "res/layout/main.xml" and say, name foo, then calling setContentView(R.string.foo) actually works.

Re: Anko – Pleasant Android development in Kotlin

#27
I have a relatively medium implementation of a layout in anko here: https://github.com/burntcookie90/KotMeh/blob/master/app/src/...

I'm not sold on using it as a layout DSL, it's just not as easy to format as XML, and I don't think it looks syntactically that much better. However, I am sold on using anko as replacement for setters and getters (ie. `setText("test")` is just `.text = "test"`). Additionally, it's incredibly easy to add more extensions for other view types, like `RecyclerView` and custom layouts.

Re: Anko – Pleasant Android development in Kotlin

#28

I've had my eye on Kotlin for a while. I'm looking forward to seeing where this goes!

Same here. I'd love to start seeing it appear in various projects on HN, so we can have the discussion of pros and cons as we have had for the last 18 months on Rust and Go.

The Rust developers have done a fabulous job of posting here and answering questions in detail, and I hope the Kotlin guys at JetBrains will eventually start doing the same thing.

Re: Anko – Pleasant Android development in Kotlin

#29
post #16
post #11

What does it even mean for an XML layout to be type and null safe? This reads like a parody. XML resources give you orientation/screen size resolution and component re use. I haven't drunk the MVP kool aid that's the new hotness, but this is far too much in the other direction. If you're setting margins in code you're probably doing something wrong.

Let me try to answer it. I'm sure that I won't change your mind, but when I published Anvil (a similar library for Java) - I got lots of questions like yours. - XMLs are not type safe, I can type any tag name in there, and I can set almost any value to my attributes - AAPT won't even notice (yes, Android Studio is much smarter these days, it may give a warning, but it won't be a compiler warning, so it won't be in yo…

Thanks for the explanation. I don't really buy the wasted CPU cycles argument since any dynamic jank after lollipop is caused by inflating views at the wrong time, not really how they're inflated. The other stuff sound nice but being able to do simple arithmetic and operations in XML sounds like the major win

Re: Anko – Pleasant Android development in Kotlin

#30
post #12
post #8

Earlier quoted context omitted.

Looks really promising, thanks for the hint. It's on my to-evaluate list along with: http://robobinding.github.io/RoboBinding/ Also, if you're open to Xamarin, there's a great library there called MvvmCross that gives you in-AXML databinding and a general feel similar to Angular.

Thanks! Unfortunately neither of the data binding libraries for Android worked for me, because they are either too hard to extend or too big/complex. RoboBinding's idea is nice, but to me it's too implicit. It's really hard to tell what's happening behind the scenes. As for the Xaramin - I would like to try it, but I run linux on my development machine, and it didn't start with Wine.

The "magic" nature of databinding seems unavoidable. Either it's driven by reflection and then it's more or less understandable but the performance suffers. Or, the bindings can be generated through some kind of bytecode weaving or code generation, which are both opaque to some degree. Either way it's hard to debug and possible to screw up performance, and I've yet to see an implementation without such tradeoffs. But in the end I think it's worth it for the architectural wins.
Post reply on HN