News for hackers. Stuff that matters.
Re:Kotlin 1.4 by rockyj on Tuesday August 18, 2020 @04:28AM (#24196402)
Really 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.
Re:Kotlin 1.4 by MrBuddyCasino on Tuesday August 18, 2020 @05:17AM (#24196673)
In 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.
Re:Kotlin 1.4 by jillesvangurp on Tuesday August 18, 2020 @06:27AM (#24197085)
Both 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.

Re:Kotlin 1.4 by jpgvm on Tuesday August 18, 2020 @05:47AM (#24196849)
We 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.
Re:Kotlin 1.4 by renke1 on Tuesday August 18, 2020 @04:45AM (#24196498)
Kotlin 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.
Re:Kotlin 1.4 by ImprobableTruth on Tuesday August 18, 2020 @06:55AM (#24197222)
>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.

Re:Kotlin 1.4 by renke1 on Tuesday August 18, 2020 @07:06AM (#24197294)
I 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.

Re:Kotlin 1.4 by thu2111 on Tuesday August 18, 2020 @07:45AM (#24197530)
Don'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.
Re:Kotlin 1.4 by renke1 on Tuesday August 18, 2020 @07:51AM (#24197574)
I'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.
Re:Kotlin 1.4 by thu2111 on Tuesday August 18, 2020 @10:51AM (#24199289)
The 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.

Re:Kotlin 1.4 by hitekker on Tuesday August 18, 2020 @03:47PM (#24203450)
I think you're onto something.

Developers look at their freshly written code, marvel at how succinct it is and then pat themselves on the back for being so clever. "It's just one line and I read it. Boom! Readable!". A few months later, another developer comes to look at the code and has to spend 10x more time parsing each character in that statement before they can even understand the logic behind it.

Brevity might be a kind of "vanity metric" when it comes readability.

Re:Kotlin 1.4 by MrBuddyCasino on Tuesday August 18, 2020 @05:19AM (#24196688)
Agree 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.
Re:Kotlin 1.4 by jillesvangurp on Tuesday August 18, 2020 @05:11AM (#24196638)
I 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).

Re:Kotlin 1.4 by renke1 on Tuesday August 18, 2020 @05:18AM (#24196680)
TypeScript 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).

Re:Kotlin 1.4 by tejinderss on Tuesday August 18, 2020 @05:34AM (#24196785)
> 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?

Re:Kotlin 1.4 by renke1 on Tuesday August 18, 2020 @06:13AM (#24196992)
For 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 ;)

Re:Kotlin 1.4 by caoilte on Tuesday August 18, 2020 @06:38AM (#24197136)
last 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.
Re:Kotlin 1.4 by dvlsg on Tuesday August 18, 2020 @11:02AM (#24199474)
Luxon 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://tc39.es/proposal-temporal/docs/

Re:Kotlin 1.4 by ragnese on Tuesday August 18, 2020 @01:05PM (#24201208)
For me, it's the Node ecosystem. The probability of even popular libraries having really basic bugs is way too high.
Re:Kotlin 1.4 by on_and_off on Tuesday August 18, 2020 @02:16PM (#24202150)
as 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.

Re:Kotlin 1.4 by lllr_finger on Tuesday August 18, 2020 @08:31AM (#24197824)
The 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.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @08:42AM (#24197914)
Are 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.