7 ms·
I started using Kotlin daily about 8 months ago. Recently had to go back to an older Android codebase, and immediately decided I had to start converting. The
by gibolt 7y ago
I started using Kotlin daily about 8 months ago.
Recently had to go back to an older Android codebase, and immediately decided I had to start converting.
The amount of boilerplate is unbelievable. I'm able to cut the number of lines by half while increasing readability. Type/null safety is a huge added bonus
P.S. Kotlin extensions are the best
- yetihehe 7y agoNeeded some POC code on android last week, that was my first use of kotlin and my most memorable encounter: kotlin-stdlib / kotlin.experimental / and . So kotlin has bitwise "and" operator for bytes, but it's still experimental? > I'm able to cut the number of lines by half while increasing readability. What I've seen from kotlin code on the web is that sometimes code is so terse that it's too hard to understand, but it's probably because of not being accustomed to kotlin yet (I've written so convoluted erlang list comprehensions that I'm still ashamed, but those can squeeze 10 lines of java into one erlang line).
- gibolt 7y agoLike with any language, out can make it short to the point f obfuscation. The goal (and the opportunity) is to make your code very declarative. view.removeSelf() vs. ViewGroup parent = (ViewGroup) view.getParent(); parent.removeChild(view); Extension Properties and data classes further help centralize the contents of a class.
- vbezhenar 7y agoLooks like a band-aid for bad API.
- joe_fishfish 7y agoWelcome to Android.
- wtetzner 7y agoOf course. And if you are using any sort of 3rd party library, there's a good chance it has some bad design decisions in it. Having extension methods allows you to clean them up. If the library is open source, you can of course try to contribute changes, but they may or may not be accepted, and maybe the library is in such wide use that they don't want to break backward compatibility.
- gambler 7y agoThis is the worst thing about Java. Almost all other languages have some way to deal with bad libraries or missing features in those libraries. Java has nothing of this sort and it gives library provides all kinds of tools to fuck you over.
- pjmlp 7y agoThe worst thing are developer that don't learn to use the tools that Java makes available at their disposition. In any language it is possible to fix broken libraries.
- pjmlp 7y agoNothing prevents one to achieve the same in Java with adapter classes or utility methods statically imported.
- wtetzner 7y agoThat’s true, but adapter classes can be pretty clunky to use, and while static methods are fairly lightweight, they aren’t very convenient if you’re trying to extend a fluent API.
- pjmlp 7y agoWith proper Java support that could be written as removeSelf(view) Not that bad, but then it doesn't sell Kotlin.
- pjmlp 7y agoMost of the Android boilerplate is related to stagnation of Android Java and the platform's cruft with every IO rebooting how things are supposed to be done in the platform. Jetpack Composer is the latest example of such, finally is ConstraintLayout and the GUI editor gettting usable, they reboot the whole thing ('cause Flutter) without even having an idea how to support ConstraintLayout and MotionLayout with Jetpack Composer based UI tooling.
- tommyage 7y agoAbout one and a half year ago we also decided to give kotlin a shot. After a few months my opinion was similiar to yours. Extension-functions, yeah! Anyway, nowadays you wouldn't see me making the same statements anymore. My first issue appeared when I was maintaining an Android app written in Java. I needed an library for some functionality. The only maintained ones were kotlin-libs. But interoperability, right? I didn't hesitated to include it. There is no way to use or extend functionality with typealiases in your java code. IntelliJ can compile Kotlin into Java and it is easily accessible. But there is no adb debugger for kotlin. Null Safety is just overhead imho. I know when it is appropriate or neccessary to check for null, otherwise i can get rid of it. And its more easily grep-pable the Java way. Writing Kotlin is not so fluent as one would guess, the tooling only fools you, that it is. You can easily make use of actions like typing pfi (extends to public final int) for java aswell. But when your property changes from nullsafe to nullable, you need to rewrtiging eeevverything. Additionally, i do not like the implicit type on member property declarations used by almost anybody. The benefit of typing less boilerplate becomes annoying when reading sources outside your ide. Boilerplate in my opinion is code i need to write by myself. When it is generated by any IDE, i do not bother about it. We are so familiar with Java that we can abstract this boilerplate when reading sources. Spelling Kotlin to somebody via telephone is also strange for me. I stopped promoting Kotlin as a Java killer. Code style is too different between different developers. And why are we creating the same libraries once again?
- t-writescode 7y agoAre you sure there’s no debugger? I’m pretty sure I’ve debugged code in Kotlin from inside Android Studio running on an emulator.
- tommyage 7y agoYes, provided from android studio, but via adb there is only jdb available
- deleted 7y ago[deleted]
- 7y ago