8 ms·
Android KTX: Kotlin Development for Android
- bitwize 9y agoStill working in Java on Android. Have a feeling that I will be left behind soon.
- wootie512 9y agoSame here. On my my most recent project the client requested we use Java, since after they take over they can use devs with Java knowledge.
- firefruit 9y agoIt will take a week or two to convert experienced Java devs to Kotlin.
- wootie512 9y agoYea I agree. I like Kotlin a lot and found the transfer from Java to Kotlin fairly straightforward. Just not all clients are open to one more thing for their devs to do/learn. In the specific case for us, the devs were new to Android so they wanted to use a language they were comfortable in.
- pennaMan 9y agoIf they are new to Android how are they comfortable in Androids' take on Java? Trying to use paradigms from enterprise/server side Java in Android is going to backfire hard on all but the most trivial projects.
- shrewduser 9y agoyou really wont be, it's like a couple of weeks and you'll be up and running in kotlin.
- bitwize 9y agoI don't mind Kotlin, but I don't want to get a big middle finger from Google for choosing to remain with Java for this project I already started in Java.
- kllrnohj 9y agoKotlin & Java interop really seamlessly, that's one of kotlin's biggest features. Not interops like there's an FFI that is obviously an FFI, but interops like there's not much obvious difference between calling either way. You won't get the kotlin syntax sugar, of course, but you're not going to be missing any features, either.
- BoorishBears 9y agoI’ve used Kotlin enough to be comfortable but Java is still my go to for personal projects. Java + StreamSupport + RxJava (and formerly + Retrolambda) is a very modern feeling language. Heavy use of Optional makes the null safety issues a little less worrying and all my apps are built around AutoValue objects which are a bit like Kotlin data classes.
- mrath 9y agoAnd apparently Java 10 has ,`var` keyword. It won't be long before Java has all the goodness.
- saagarjha 9y agoWe've already seen something similar before: when Apple "modernized" many of the their Cocoa Touch APIs to work better with Swift.
- jchw 9y agoI thought that was purely just Swift's own translation layer to make Objective C APIs more Swift-y, not an API change.
- euyyn 9y agoThere were API changes to make the translation happy, in many cases where conventions weren't being followed strictly.
- Techonomicon 9y agoWhat does "already seeing this" have to do with any meaningful input on the subject?
- saagarjha 9y agoI was providing a parallel from my experience, which I thought might foster discussion on how such an API improvement might proceed based on historical anecdotes. Was this not a welcome addition?
- ambulancechaser 9y agoi think people are interested in the lessons learned in the past. are you sceptical or hopeful? how did apple's stab at this work out in the past? is it fundamentally flawed or deeply overdue.
- saagarjha 9y agoI think Apple did a pretty good job in most cases when getting their code to work well in Swift. I'm hopeful that this will also be the case with Android, but the hitch is that a lot will have to change. Swift's closures, extensions, etc. already had Objective-C counterparts which were not difficult to translate; but Java, on the other hand, doesn't provide many of the features that Kotlin does (hence the drastic reduction of boilerplate we can see in the blog post).
- merb 9y agosome examples are fine, but come on... > Uri.parse(myUriString) vs. > myUriString.toUri() I'm not sure if I would prefer the second one...
- kornish 9y agoDiscoverability via autocomplete is much higher in the second one. Extension methods probably seem really strange to anyone coming from a FP background (myself included), but in practice they've ended up being pretty useful when paired with Intellij.
- TheAceOfHearts 9y agoDoesn't it get a bit overwhelming to get a huge list of choices with autocomplete? I've never done any serious work with Java or Kotlin, so I'm genuinely curious. As long as you have good docs, I find discoverability is rarely an issue. One of the first things I do when picking up a language is look through its built-in constructs, to familiarize myself with the available options.
- kornish 9y agoTyping a couple characters is generally enough to cut out most of the noise, so long as you know vaguely what you're looking for and the methods are sensibly named. I don't think it's the built-in constructs which are hard to find. In JVM-land, it's sifting through often verbose library interfaces that makes discoverability a huge win. Looking in Javadoc for that single function to convert from Type A to Type B properly can be a real pain.
- Groxx 9y agoOnly when things become ambiguous semantically. E.g. if they had `toUri` and `asUri` and `parseUri` etc then sure. But even then it's far more discoverable / less overwhelming than "I have a String. I want a Uri. Do I use a UriBuilder, UriParser, Uri, StringConverterFactory, etc?". Not only do you have all classes to choose from, you need to pick the one with the right methods (usually not visible when choosing the class) for the data you have. Some IDEs can and do improve the helper-classes case a bit by letting you type e.g. `myString.uri` and showing you "uri" methods both on string and static methods anywhere which accept strings... but it's not widespread, sometimes unhelpful (there are far too many "parse" methods), and you're still missing out on the class context which sometimes has important info.
- evancox100 9y agoWhy is it that these large web companies can put out such sophisticated tools, and yet can't make a functional web page? Literally cannot see the content you are trying to show me. https://imgur.com/a/lXY8J https://imgur.com/a/lXY8J And no, there's no scrolling or zooming allowed. Seriously, let's stop the focus on web framework du jour and actually make web sites that work, please.
- agildehaus 9y agoThere's more chance for human error at a large company. Looks like it could be fixed by adding a CSS "white-space: pre-wrap" to the <pre> elements they're using to display this code.
- dguaraglia 9y agoWell, if you think about it in terms of priority, making better tools that literally millions of engineers will be using to develop apps for billions of people has a higher impact than improving a blogging platform that is used by a handful of people at Google. That's not to excuse the shitty state of web on mobile, but let's face it: we are talking about completely different teams and priorities.
- vesinisa 9y ago> You may notice that Android KTX uses package names that begin with androidx. This is a new package name prefix that we will be using in future versions of Android Support Library. We hope the division between android.* and androidx.* makes it more obvious which APIs are bundled with the platform, and which are static libraries for app developers that work across different versions of Android. Ugh, okay. It's going to be a blast refactoring all my existing code and custom tools to reference this new package.
- jontro 9y agoHopefully just a couple of simple global search and replaces? Anyways I think the current support library structure is confusing and it's a good thing that they will refactor it.
- izacus 9y agoAndroid Studio handles that pretty well and it'll probably fix most of those in a single "Optimize imports" pass.
- on_and_off 9y agoAbsolutely, it sounds like something that tools can handle for us or that would not take long to change even on a large codebase anyway (because you would just do a pattern replace)
- deleted 9y ago[deleted]
- mncolinlee 9y agoIt's worth noting that one of the great features of Kotlin is how it simplifies deprecating code and writing quick fixes. This is why Google scrapped Java for writing Lint rules entirely. I expect a simple Option-Enter may resolve these kinds of issues across an app. https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyIUY6UK1cgVsbdPYA3X5WLam5&index=9 https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyI...
- barbs 9y agoNot to be confused with Kotlin Android Extensions, which although handy is really just a convenient way to reference views in XML. https://kotlinlang.org/docs/tutorials/android-plugin.html https://kotlinlang.org/docs/tutorials/android-plugin.html
- wiradikusuma 9y agoMaybe a combo of that and Anko (https://github.com/Kotlin/anko https://github.com/Kotlin/anko)?
- mncolinlee 9y agoKotlin Android Extensions is a tad more than that. It's also a View cache that grabs all view references in a single pass. I routinely have to explain to other senior Android developers that findViewById() traverses the entire view hierarchy until it finds that ID each time you call it. This won't be noticeable with simple views, but becomes a bigger problem as complexity increases. Which also results in more wasteful calls to findViewById(). Android Data Binding does something very similar to Kotlin Android Extensions, which is why it also perplexes me to see experienced devs bind a model to a view and then call findViewById() to alter it. I'll see calls to binding.getRoot().findViewById(), which is crazy redundant.
- MBlume 9y agoCurious, is anyone inside of Google using Kotlin for their Android apps, or is this all for third party developers?
- euyyn 9y agoI know of one app for sure, but I don't know if I can tell :)
- mncolinlee 9y agoI heard the Android data binding compiler was written in Kotlin. At KotlinConf, they announced that Google had dropped Java altogether for writing Lint rules because of Kotlin's much greater capabilities for handling deprecated code and IDE quick fixes.
- ptx 9y agoWasn't the linter thing just about moving the lint rules (for checking proper Android API usage) to a language-independent format so that they could be shared by Java and Kotlin? Previously they only worked for Java code.
- mncolinlee 9y agoYou can watch the KotlinConf session video by Tor Norbye. It was what you said and more. To clarify, I meant they dropped Java internally for their own lint rules, not that they dropped support. https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyIUY6UK1cgVsbdPYA3X5WLam5&index=9 https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyI...
- daram 9y agoDirector of project management, Android, said of Kotlin last July: "we're already using it ourselves to write code in Android Studio which gives us more ideas for making our support even better." https://adtmag.com/articles/2017/07/20/android-ama.aspx https://adtmag.com/articles/2017/07/20/android-ama.aspx
- Rockvole 9y agoAs an alternative to learning Kotlin on Android, you can spend the time learning flutter. Then you get concise code which works on Android and IOS now and on other platforms in the future - including desktops.
- nolok 9y agoAnd it's made by Google, unsurprinsingly. A big plus for Kotlin is that being a jetbrains project, it has top of the line intellij tooling support right at release date.
- Anm 9y agoFlutter's dev tools are built on intelliJ.
- ClassyJacket 9y agoIf it's made by Google, shouldn't we avoid it as it's likely to be discontinued in a few months?
- xbmcuser 9y agoAbout half of all tech on the internet today originated by google open sourcing it. Your and other google hate does not take into account the fact that many things that exist on the internet and tech is because of google I cant believe you guys are still crying about reader. Personally I think it was bad move on their part but I really don't get all the crying you guys do for something that shutdown 5 year ago.
- akmittal 9y agoFlutter will be official development platform for Google Fuchsia, their next big OS*. Google is supporting Android and iOS with flutter So that they can have plenty of apps available already when Fuchsia is launched. With the big investment they are doing in Fuchsia it seem unlikely they will abandon it soon.
- 9y ago
- vorg 9y agoLaughed when I saw this Apache Groovy code slinking away at the bottom of the article: > To start using Android KTX in your Android Kotlin projects, add the following to your app module's build.gradle file: repositories { google() } dependencies { // Android KTX for framework API implementation 'androidx.core:core-ktx:0.1' ... }
- swsieber 9y agoYes - that's Gradle's language de jour right now, though there is a ton of effort being put into supporting Kotlin as an alternative scripting language for it. I think you could use it right now actually.
- karag 9y agoFlorina killed it again! go go girl (She's a genius)