Live data from Hacker News

Anko – Pleasant Android development in Kotlin

github.com

11–20 of 38 posts

Re: Anko – Pleasant Android development in Kotlin

#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.

Re: Anko – Pleasant Android development in Kotlin

#12
post #8
post #3

Earlier quoted context omitted.

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 )

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.

Re: Anko – Pleasant Android development in Kotlin

#13
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.

It looks good unless you actually use layout qualifiers frequently. Then it becomes a pain, because you now have to keep consistency among all your layout variations and with Java code. Moreover, there's no tool in Android SDK nor in Android Studio that could help you sort it out.

Re: Anko – Pleasant Android development in Kotlin

#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 your automated build logs. You will also miss it when using other text editor or IDE). I can put a view inside another view (not a viewgroup) - and it will pass as well. Since we waste CPU time on XMLs preprocessing - it would be nice if they also warned us about our errors at this stage, not crashes in runtime.

- The file hierarchy is terrible. All XMLs must be in the same folder, no nested folders. Having a large project makes you have dozens of XMLs on the same layer of hierarchy. Since we have OS with directories - it would be nice to use that feature like we use it for java packages.

- There are some styles, but they are too limited comparing to, say, CSS. If one ever tried LESS or SASS - he will love the mixing, variables, calculated expressions etc. It's fast to write, it's easy to read, it's reusable. You don't have to jump around multiple closely related files to tie it all together in your head. You have them in one place. Since XMLs are processed - it would be nice if I could write something like "android:background=darken(@color/mycolor, 30%)"

- There is some responsiveness, but it's too limited. If you have 3 nested views, and the topmost has margin in landscape and no margin in portrait - you have to have two (almost identical) files. Or three, if you want to use merge/include. In fact now they are all in different folders, despite they are very closely related!

- There is no way to merge with unique ids (child layout will have the duplicated ids when included twice).

- There is no mixins or macros. If I have layout with textview+button pairs - I will end up copying those two tags everywhere. If I have macros - I would write it once, and then would only type `` - that is supposed to be expaded into with some texview and button attributes substituded to the given actual values.

- There is no data binding.

Re: Anko – Pleasant Android development in Kotlin

#17

I've been using this since it was still a side project by yanex under the name of Koan. I'll never go back to writing XML layouts.

Oh, so Anko and Koan is the same project? Stupid me, I wondered what happened to Koan when I saw Anko first (and I didn't think of an anagram).

Re: Anko – Pleasant Android development in Kotlin

#18
post #3

Earlier quoted context omitted.

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 )

Anvil looks really promising. I wonder why doesn't it use "linearLayout {}" instead "v {}" syntax?

I'd guess because Anvil began as a Java project, and Kotlin is what provides the sugar that allows Anko to provide a nice DSL.

Re: Anko – Pleasant Android development in Kotlin

#19

Earlier quoted context omitted.

Anvil looks really promising. I wonder why doesn't it use "linearLayout {}" instead "v {}" syntax?

I'd guess because Anvil began as a Java project, and Kotlin is what provides the sugar that allows Anko to provide a nice DSL.

Almost correct. I never thought of this kind of syntax sugar initially. But technically (and people posted an issue about it) it's possible to generate functions like linearLayout() etc from android.jar for Anvil/Java. This will work with Anvil/Kotlin as well.

I plan to keep v anyway because it works nice with custom views when there is no generated syntax sugar.

Re: Anko – Pleasant Android development in Kotlin

#20

> 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…

> resources.arsc: a file containing precompiled resources, such as binary XML for example

yes, SO answer: http://stackoverflow.com/a/6646113

Post reply on HN