41 ms·
Kotlin 1.4
- argestes 6y agoSAM conversions finally. I'm in tears!
- wanttocommentt 6y agoI was looking forward to this as well. But then noticed you have to write the fun keyword in front of the interface. Which makes it more like a workaround than a language feature to me.
- rockyj 6y agoReally good to see these changes. Kotlin is a great language to work with, it has the stability and performance of the JVM and it writes like Ruby / TypeScript. I wish more companies were adopting it as their core language and it is not just limited to Android development.
- renke1 6y agoKotlin really is good and definitely an improvement over Java, but in my experience (like ~1 year) the language itself makes writing unreadable code too easy; it also doesn't help that IDEs like IntelliJ Idea often suggest shorter yet less readable alternatives because it's "idiomatic" Kotlin code. For perspectice, I am writing "enterprise software" and I am big fan of TypeScript.
- jillesvangurp 6y agoI find most intellij suggestions to be quite sensible. It basically teaches you idiomatic kotlin. I'd suggest not fighting the tools and letting them guide you. As for typescript, it's a nice step up from javascript but IMHO more of a gateway drug to other languages (like Kotlin).
- renke1 6y agoTypeScript really hits the sweet spot for me. A good type system (real union types, which Kotlin lacks), barely any special syntax to remember but still powerful enough. I do want nominal typing sometimes, though. Although I must admit that I wouldn't use TypeScript in the backend for the projects we work one (but I do for my personal projects).
- tejinderss 6y ago> Although I must admit that I wouldn't use TypeScript in the backend for the projects we work one Can u elaborate on that? Why is TypeScript not suited for some projects?
- renke1 6y agoFor us particular, we heavily rely on fat frameworks like Spring (and sometimes Java EE) and there is nothing like that in TypeScript/JavaScript world. It boils down to not having classpath scanning, reflection and annotations in TypeScript, I guess. I don't want to defend these frameworks, though, they certaintly have their flaws, but it is what we use and it is often also what is teached in Germany. We also follow a domain-driven design approach for which we not yet have found a good way to implement in TypeScript (at least not on the "tactical" level). Edit: Also, people don't grok asynchronicity ;)
- caoilte 6y agolast time I was working in Typescript (a year) ago, the date/time libraries were still disappointing and precision math libraries were very way too cumbersome. Both are well solved problems on the JVM and in other languages.
- dvlsg 6y agoLuxon makes for a good date lib stop gap while tc39 works on something built-in that is (hopefully) a bit nicer. https://moment.github.io/luxon/ https://moment.github.io/luxon/ https://tc39.es/proposal-temporal/docs/ https://tc39.es/proposal-temporal/docs/
- MrBuddyCasino 6y agoAgree Kotlin gives a developer definitely more rope to hang himself with than Java, and not all IntelliJ suggestions are really "improvements". Biggest danger is, as always, being too clever and/or being a purist.
- ImprobableTruth 6y ago>suggest shorter yet less readable alternatives What do you mean exactly? I feel like Kotlin's brevity is what actually makes it a lot more readable than Java. With Java there's just often so much noise and fluff that doesn't actually mean much, obscuring what the program actually does. Could just be my personal preference, but I feel like in general I have an easier time understanding terse, dense code rather than spacious, verbose code.
- renke1 6y agoI can't give specific examples, but something along the lines of suggesting to replace an early return in the form of `if (…)` by something like `… ?:return`. The former alternative makes it way easier to spot on first glance where the functions bails out. The latter hides it in an assignment making it harder to see. I should say, though, that I am by no means an expert Kotlin developer; maybe I just have to get used to idiomatic Kotlin.
- thu2111 6y agoDon't take idiomatic Kotlin too seriously. It's not Go where there's exactly one allowed way to do things. IntelliJ's suggestions go both ways - you can convert to short form and also back to long form automatically. It's that way for a reason: you're trusted to pick the right form on your own.
- renke1 6y agoI'd agree in general, but that hardly works for larger teams or even multiple teams. This can probably be solved by a good linting tool, but I am not too familiar with the state of linting in Kotlin.
- thu2111 6y agoThe best linter for Kotlin is the IntelliJ inspector, which is very powerful. You can run inspections from CI builds using TeamCity, at least, probably other CI builds. You may also configure project defaults to trigger various patterns as warnings or errors. Even better, in the latest IntelliJ you can create new inspections from structural search, which is an AST based matching system. So you have a lot of flexibility to make your own lints and warnings without needing to write plugins. However, I think there's a more general issue here, which is that if you don't trust your team to write tasteful code, linters will be of limited use. It may be better to invest in more rigorous code reviews, trainings, style guidance, mentoring etc. I've spent five years managing technical teams using Kotlin (yep, early adopter!) and found most of them could handle it just fine. A little training goes a long way. The worst problems came from developers creating overly complex abstractions, not playing code golf.
- on_and_off 6y agoas somebody who has written a lot of java and kotlin, often I prefer the most explicit option. Code will be mostly read, not written, so if something will make a junior (or in some cases even seasoned) dev scratch their head to be understood, it is best avoided. EG Often I prefer writing an "if != null else" instead of chaining takeIf{}s.
- MrBuddyCasino 6y agoIn my own experience, some large (and usually conservative) companies are already using it (DAX 100). The combo of Kotlin & Spring Boot is definitely not exotic anymore. I suspect the fact that it is running on the JVM and makes code safer due to null-checks plays a big role in that. It is just very well suited to modeling business logic, unlike Golang which has its strength more in infrastructure code. Kotlin is also a popular fallback choice in situations where a team was initially using Scala, but it didn't work out. Many such cases.
- jpgvm 6y agoWe are using it heavily in data infrastructure/data engineering space. Makes a ton of sense because the ecosystem is already JVM and Kotlin makes writing data-munging code quite pleasant.
- jillesvangurp 6y agoBoth the Android and Spring ecosystems are very much Kotlin centric at this point. Both still support Java because there are just so many older projects out there that won't or can't switch. So Google won't come out and pull the plug on lifesupport for that just yet; though they are making it very clear that they are focusing on Kotlin in their presentations, documentation, etc. I've been in a few conservative backend projects in the last year where they were stubbornly insisting on Java. I've managed to convince a few on a path to Kotlin. For those not familiar with the situation. With Spring 5 & Spring Boot 2, Spring started supporting Kotlin properly (i.e. 2 years ago). It worked fine before that but now Spring comes bundled with a lot of Kotlin extension functions that bridge the gap to idiomatic Kotlin. E.g. all the reactive stuff that Spring has you can (and IMHO should as it simplifies things a lot) do using kotlin co-routines. Things like Flows, suspend functions, etc. all just work seamlessly with Spring's Flux. Also the documentation is now updated with kotlin code examples and increasingly it seems a lot of features are more Kotlin than Java centric. If you don't need Spring, Ktor is emerging as a nice lightweight alternative. It's more of a express.js/ sinatra style framework. You can actually use Spring in a similar way with the bundled Kotlin router DSL but not everybody does that.
- lllr_finger 6y agoThe good news is this is already happening - lots of Java orgs in my market (not SV, but still a large US market) started working on new server-side things in Kotlin a year or two ago. This includes several Fortune 100 companies, so not just startups or smaller, more "nimble" companies.
- pjmlp 6y agoAre the same ones that were jumping into Scala 10 years ago, and into Groovy before that? I love those porting back to Java projects after the pixie dust fades away.
- snafu109 6y agoOfficial announcement: https://blog.jetbrains.com/kotlin/2020/08/kotlin-1-4-released-with-a-focus-on-quality-and-performance/ https://blog.jetbrains.com/kotlin/2020/08/kotlin-1-4-release... What's New in Kotlin 1.4: https://kotlinlang.org/docs/reference/whatsnew14.html https://kotlinlang.org/docs/reference/whatsnew14.html
- ocdtrekkie 6y agoKnowing this wasn't a Google thing, I was a bit thrown by the update being announced by Google. Definitely recommend headlining the original developers' announcement instead.
- dang 6y agoOk, we've changed to that from https://android-developers.googleblog.com/2020/08/new-language-features-and-more-in.html https://android-developers.googleblog.com/2020/08/new-langua....
- lordnacho 6y agoIf you haven't tried it yet, here's my seal of approval for Kotlin. Normally I'm quite reluctant to start a new project in a new language, but Kotlin edited on IntelliJ just seems so very smooth. I'm doing a side project which is a game, where most of the website parts are Kotlin. Most of what I'll say will be a bit vague, I mainly write Python and C++. I'm also not too clear on what benefits come from the language and which from the IDE, my understanding is that JetBrains had a lot to do with it so they are probably connected. - Compile times seem pretty fast. - Errors seem clear, haven't been as stumped as I'd expected with a new language. - Greytext types that are inferred are super useful. I do wonder how I'd do if the IDE didn't tell me what the types were. But it basically means you get all the benefits of type annotation without having to write out the types. - The style of using a lot of filter/map/reduce makes my code more terse, but the greytext hints keep it easy to understand. - Great sugars. No need to add getters and setters for every member. Likewise it seems to change the calls to old Java lib getters and setters. Data classes can be short and sweet. One-liner functions in-line for simple stuff to keep simple stuff short. - Can still do whatever you want with Java libs. Unit testing for instance works much the same. - Ecosystem has moved nicely with Kotlin. Ktor and Ebean seem to be on board and pretty mature. - Null safety built in makes it clear where you need to do something about it.
- Semaphor 6y ago> Greytext types that are inferred are super useful. All the Jetbrains IDEs have that. When they enabled it, I was annoyed for a while (not enough to turn them off), but now I love them :) Especially, as you mention, for LINQ (in C#, essentially chained operations like map/reduce/etc.)
- 1f60c 6y agoYou probably already know this, but if you spread the query over multiple lines, it’ll show you the exact type at each step.
- jansan 6y agoI am using IntelliJ's WebStorm for my own project and Visual Studio Code for a company project, because all other team members are using it and we agreed to use the same tool. I like WebStorm so much better. The inline parameter names on function calls, the local history, the awesome diff tool, the refactoring capabilities (even for Javascript). This makes is well worth the money. Also, I like IntelliJ's perpetual fallback license policy. Feels very fair to me.
- PostThisTooFast 6y agoKotlin's similarity to Swift is convenient. I just wish Google would settle on one language for a while and be done with it.
- Jestar342 6y agoKotlin is exploding in the Android sphere. I am seeing more and more announcements/job postings for Kotlin mobile devs.
- jamil7 6y agoQuite rightly! I recently used the multiplatform features on a side-project and was able to share a decent chunk of business logic between iOS and Android. As someone coming from JS and Swift it was fairly straightforward to pick up.
- pjmlp 6y agoNaturally, Google is pushing it down our throats, providing minimal compatibility with Java language features post Java 8 and zero JVM capabilities regarding modules or newer bytecodes.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- kevsim 6y agoAs a guy who has written a lot of modern JS but was working in a JVM-only shop (all tooling etc assumed services were running on the JVM), Kotlin was like a breath of fresh air. Doesn’t go as FP as Scala (which is a plus for me) but still has all the nice collection APIs etc that I use frequently in JS. Really looking forward to seeing what happens with Kotlin native. Compile times were pretty bad last I tried it but I’d give it another go if they improved those.
- throwaway8941 6y ago>Doesn’t go as FP as Scala (which is a plus for me) If anyone reading this thinks about using Kotlin and has more positive views towards FP, there's this project to bridge the gap somewhat https://arrow-kt.io/ https://arrow-kt.io/
- The_rationalist 6y agoArrow meta is a compiler extension that will bridge the gap even more e.g by bringing union types https://github.com/arrow-kt/arrow-meta https://github.com/arrow-kt/arrow-meta
- valenterry 6y agoUnfortunately, the gap will stay huge due to the lack of capabilities the type-system, e.g. in higher kinded types and implicits. However, most people who choose Kotlin probably don't want to do "fully fledged" FP anyways and prefer to take the faster compile times etc. over it. I like the Scala side better though. ;)
- WkndTriathlete 6y agoI'd argue that more day-to-day problems are solved with extremely usable record types (data class) than are solved with natively-supported HKTs.
- 6y ago
- The_Colonel 6y agoKotlin seems finally like a language designed by people who actually develop in it. OTOH Oracle people seem to always focus on the platform issues - green threads is the next big thing, but it doesn't actually affect 99% of developers since Java's threading model is just fine for most business applications. Yet things like missing ability to reasonably express non-nullability (and the resulting NPEs) hit me every single day, but for Oracle it's apparently not an interesting enough to work on.
- thu2111 6y agoVirtual threads will probably have a lot more impact than you imagine. Basically any server gets written in weird ways currently due to the need to conserve threads, or belief that you might need to in future. Blocking IO is just simpler to program but nobody does it anymore for that reason. The amount of code that will become "tech debt" the moment Loom becomes widely available is very large. Oracle are improving the Java language, but of course Kotlin could go much faster as a greenfield project with no community to involve or please. It's got a long way to go to match Kotlin. That said, Kotlin the language is now stable for quite some time and isn't really changing, so it's a relatively static target.
- The_Colonel 6y ago> The amount of code that will become "tech debt" the moment Loom becomes widely available is very large. 1) As I understand green threads will not require vastly different programming model (no colored functions). So my code can stay mostly the same as it is. 2) My microservices are working just fine now, without performance/scalability issues (certainly nothing related to thread count limit) so why would they turn into tech debt? > That said, Kotlin the language is now stable for quite some time and isn't really changing, so it's a relatively static target. Yes, but Java is not moving towards it in some respects at all. There's no effort to tackle the nullability problem for example.
- thu2111 6y agoYour code can stay as it is, yes. Loom is fully backwards compatible. By tech debt I mean, it will become code that is needlessly complex and hard to maintain for what it does and thus become a candidate for simplifications and refactorings. I didn't mean it'll stop working.
- thu2111 6y agodang, can you update the URL to the actual official announcement instead of Google's shorter copy? https://blog.jetbrains.com/kotlin/2020/08/kotlin-1-4-released-with-a-focus-on-quality-and-performance/ https://blog.jetbrains.com/kotlin/2020/08/kotlin-1-4-release... It's got more detail and is more canonical.
- heinrich5991 6y agoJust mail hn@ycombinator.com (see footer).
- deleted 6y ago[deleted]
- pron 6y agoAs far as the Java platform (AKA "the JVM") goes, Kotlin is painting itself into a corner. Kotlin was designed in 2009-10, in the Java 7 days, around the time of the Oracle acquisition, and at a time of stagnation for Java due to Sun's decline. At the time, Android was also quite similar to Java. Kotlin was a great design in those conditions. Things are very different today. Kotlin's design goals are now contradictory. It seeks to be a low-overhead language, i.e. provide abstractions that don't add overhead over the target platform, give access to all platform capabilities, and at the same time target multiple platforms -- Java, Android, LLVM and JS -- over none of which does Kotlin exert much influence (maybe a bit on Android). Since 2010, Java has moved away from Android, to the point that there are very big gaps between the two, and they're only growing. By both trying to target multiple platforms (with no say in their design) and trying to add little or no overhead, Kotlin will soon find itself in a bind. It's coroutines are in conflict with Java's upcoming virtual thread's design, and its inline classes will cause problems with Java's Valhalla vs. Android. Kotlin will have to choose to either give up on low-overhead abstractions, give up on some of its platforms, give up on giving access to full platform capabilities, or split into multiple languages, each targeting a different platform. For example, if Kotlin's inline types will make use of Valhalla, then they won't work on Android, at least not without much overhead. TL;DR: A full-capability, low-overhead, multi-platform language is hard to pull off in the long run when you have low market share on all of those platforms (except Android) and little or no influence on any of them. This was viable under some accidental circumstances, but those are no longer holding.
- The_rationalist 6y agoReplacing current courtoutine implementation to use Loom threads or inline classes to use Valhalla are both implementation details that should not at all change the user facing API and complexity. Your second point somehow stand: exploiting such optimizations will either need a runtime check or to be enabled automatically based on your JVM target specified in your gradle/maven. As for the long term, google devs are heavily contributing to Kotlinc and I hope they will pressure Android architects to replace dalvik with openjdk.
- alex7o 6y ago
- mikece 6y agoGiven the litigious nature of Oracle, how hard would it be for Kotlin to be useful without reference to the JVM at all? Is Kotlin/Native ready for prime time and can it be used for mobile/embedded/IoT applications currently or is it still a work in progress?
- jillesvangurp 6y agoIt's used a lot already for cross platform development for android and ios even though that has been experimental so far. This is where they've been focusing most of the effort and as far as I know it's usable for that and some people have already built apps using this. I've been looking at multiplatform development recently and maintain a few oss projects on github that are now multiplatform. The build tools are getting there. The multiplatform gradle plugin has improved a lot over the last year. Generally you can get stuff working pretty easily. If you need to target IOS and Android, it's worth a look. Also if you want to share some code with browsers, it can do that too. The main issues is with gaps in functionality. E.g. kotlinx datetime just reached 0.1. There were a few third party alternatives but if you needed dates, not having a usable datetime library is a bit annoying. That's just one example. When stuff is missing, you can actually fix it yourself. But of course that ends up being quite a bit of work. I think for e.g. command line development on Linux or WASM development for browsers, the native compiler is not that great yet. They just started working on WASM only a few weeks ago and posix and Kotlin have not had a lot of attention. This is also an issue when using kotlin-js with node.js; they've just not done the work to expose all of the built in node.js stuff to Kotlin yet. On browsers you get a smoother experience with kotlin-js. Of course people doing stuff on servers can use the jvm and that's why there's just less attention going towards native on that front. So, wouldn't recommend it for IOT just yet unless you are willing to deal with what is likely to be a rough experience and some gaps in functionality. The big next pieces are finalizing the transition to the new compiler backend and improving the multiplatform library ecosystem. They have alpha versions of the new compilers currently but they are not ready yet. I also expect there will be lots of activity with both Jetbrains and others releasing multiplatform libraries. I've actually worked on a few of those and would love to see this get traction.
- BossingAround 6y ago
- mancini0 6y agoI love it. Coroutines make async code concise and much cleaner than Java completable futures, Kotlin is a supported gRPC language, and the gRPC service signatures are much cleaner than the java gRPC service signatures, and there is decent Bazel support. I think the biggest threat to this language is the $399 iPhone.
- maxpert 6y ago2 years back we had huge debate to choose between Kotlin or Java. While Java folks thought it was immature to even discuss anything other than Java, we ended up adopting Kotlin company wide. Looking back at it we don't regret the decision even single bit! We are using Kotlin and Coroutines to run extremely heavy services (almost 1K req/sec per pod, with complex logic, few hundred threads, 6GB RAM and 2 CPU cores). People concerned with Project Loom, should remember it's backwards compatible & upgrade path can be done multiple ways. I would highly recommend Kotlin for backend services, you won't have to code review IDE vomit, depend on annotations, or live with callback hell (project reactor, rx-java).
- brzozowski 6y agoAs a grad student who has been using Kotlin in research for the last few years, it can also be a great language for data science. Kotlin is one of the few statically typed languages with scripting and Jupyter notebook support, and offers some great features for parallel and asynchronous data processing. Once you set up a project and import the right dependencies, the workflow really clicks. It works smoothly with the JVM and JS ecosystems, which have a bunch of fantastic libraries for data processing and visualization. Happy to answer any questions about using Kotlin for DS/ML if anyone’s curious.
- posedge 6y agoHow about tooling/the ecosystem? Python has all the scipys, pandas, scikits, tensorflows, pytorches.
- bmc7505 6y agoThe tooling is ahead in some ways and behind in others. As a statically typed language, Kotlin's autocompletion and static analysis is already miles ahead. More broadly, the JVM has a rich ecosystem of libraries for data processing, from natural language processing (CoreNLP) to big data analytics (Spark). If you're looking for something similar to Pandas/Numpy/Matplotlib, maybe check out Krangl [1], EJML-Kotlin [3] or lets-plot [4]. There are also efforts to port TensorFlow [5] and PyTorch [6] to the JVM. While not all libraries as mature as their Python cousins, there are a growing number of native libraries and JVM wrappers for scientific computing, which provide most of the functionality and are very ergonomic to use in Kotlin. [1]: https://github.com/holgerbrandl/krangl https://github.com/holgerbrandl/krangl [2]: https://github.com/mipt-npm/kmath https://github.com/mipt-npm/kmath [3]: https://github.com/lessthanoptimal/ejml/tree/SNAPSHOT/main/ejml-kotlin https://github.com/lessthanoptimal/ejml/tree/SNAPSHOT/main/e... [4]: https://github.com/JetBrains/lets-plot-kotlin/ https://github.com/JetBrains/lets-plot-kotlin/ [5]: https://github.com/tensorflow/java https://github.com/tensorflow/java [6]: https://github.com/pytorch/java-demo https://github.com/pytorch/java-demo
- blargmaster33 6y ago"Semicolons are optional as a statement terminator" Deal breaker
- lokedhs 6y agoI like Kotlin, but I also feel it's a huge missed opportunity. I have used Kotlin quite a bit. In particular, I've been working on a multiplatform project recently which definitely have helped me learn about some of the less developed parts of the language. Long ago, I used to do a lot of Java and I liked it a lot (having worked at Sun back around 2000 was certainly part of the reason). Kotlin, in my opinion, is a better Java. It does a pretty good job of providing a nice syntax for it, and these benefits are the first things that are explained in beginners tutorials to Kotlin. But, it doesn't really do anything new. There are so many things it could do to fix long-standing problems with Java, which Jetbrains refuse to implement due to the fact that the implementation will not be natural to the JVM. An obvious example is generic functions, or multimethods. This was discussed on the forums, but quickly dismissed with one of the main reasons being that it would have to introduce a new dispatch mechanism and so wouldn't be natural on the JVM. This argument has been made to dismiss many suggested features. Another reason Jetbrains uses dismiss suggestions is that the new feature would make the language more complicated and difficult to learn. The refusal to implement some kind of macro facility falls into this category. At the same time, this position leads to truly bizarre language behaviour such as the strange behaviour where declaring a function inline changes the semantics of the code. This insistence that the JVM dictate the features makes even less sense since they also have native as well as JS code generators. The only unique Kotlin feature that I can think of which is not a result of the JVM is their support for suspending functions, which is used to implement their async framework. The problem here is that it semantics can be really confusing, and can in fact lead to deadlocks if you have a library the needs to be exposed to Java which internally is implemented using suspending functions. If these functions are then called by Kotlin code which itself use suspending functions, you can end up with really strange behaviour.