News for hackers. Stuff that matters.
Re:Kotlin 1.4 by lordnacho on Tuesday August 18, 2020 @04:41AM (#24196475)
If 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.

Re:Kotlin 1.4 by Matthias247 on Tuesday August 18, 2020 @02:47PM (#24202596)
> - 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.

Actually the strong-type-inference plus greytext thing is one part of Kotlin where I'm not sure what to think about it.

When I first saw Kotlin examples on the internet with all the "it.something" I was "What is going on there?!? What is that supposed to do".

Then the first time I tried writing Kotlin myself everything became super clear due to that Greytext shown in IntelliJ. However 80% of the time I'm looking at code is not in an IDE. It's either on code reviews or in the browser (github, internal code browsers, etc). All the information is not available there, and one has to be aware again what the implicit types will be.

The challenge certainly also exists in other langues with type inference (auto in C++, var in Java/C#, inference in Rust, etc), but for some reason I found it worse in Kotlin. Maybe due to the commonly used methods which take a closure/interface as last parameter, and and the fancy builders.

Re:Kotlin 1.4 by thu2111 on Tuesday August 18, 2020 @03:08PM (#24202915)
That's definitely an issue.

The good news is there's GitHub integration in the IDE so you can review code with type inference hints. And adding/removing the types (converting between the inlined hints and real text) is a hotkey away. I tend to treat it as a matter of experience and style, when to specify the types explicitly vs not. Quickly disabling the hints is also reachable via hotkeys and then it is often apparent when a type isn't immediately obvious.

Re:Kotlin 1.4 by john_miller on Tuesday August 18, 2020 @03:16PM (#24203042)
btw it's "type inference", not "type interference"
Re:Kotlin 1.4 by Matthias247 on Tuesday August 18, 2020 @03:39PM (#24203351)
thanks - I'll try to remember it. Fixed the text
Re:Kotlin 1.4 by listenallyall on Tuesday August 18, 2020 @06:26AM (#24197077)
I believe scope functions are a killer feature of the language. Being able to chain methods and write compact functions without having to declare variables, it makes so much code act and feel functional and direct. Immutability isn't on your list, it also contributes to the functional feel of the codebase.

Definitely my favorite language currently, and extremely well-suited for server-side, it's certainly not just about Android.

Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @10:09AM (#24198718)
I'd even say well-suited for the web!

KotlinJS feels so much more natural, safer and faster to write (in IntelliJ especially) than writing plain JS does.

Re:Kotlin 1.4 by agumonkey on Tuesday August 18, 2020 @07:02AM (#24197269)
It's impressive how many people are screaming "will never leave android" when discussing kotlin.

Thanks for your input

Re:Kotlin 1.4 by hocuspocus on Tuesday August 18, 2020 @07:36AM (#24197480)
I've honestly never heard anyone say that. Since Spring 5 it's pretty clear there's some interest in server-side Kotlin; there are several heavy-weights behind that.

However, it's fair to make a distinction between the slowly evolving Android runtime and the JVM. Java language features are catching up with Kotlin, and might even surpass it (I believe pattern matching might land in Java sooner than in Kotlin). Also Kotlin might get stuck for a while when big breaking changes finally come to Java (like Valhalla). I understand why some companies/teams think it's not worth it.

Re:Kotlin 1.4 by matsemann on Tuesday August 18, 2020 @08:04AM (#24197639)
Still lots of kotlin-features I don't see land in java soon. My favorite is passing a lambda in brackets when it's the last argument to a function. Makes it easy to make semi-dsls and nice-looking code. So instead of

  myFun(someVar, { it.something() }) 
it can be written like

  myFun(someVar) {
    it.something()
  }
or if no parameters to the function other than the lambda like

  myFun {
   it.something()
  } 
making the function almost look and behave like a language keyword. I also use extension-functions a lot. Especially for libraries or legacy-java code we wont touch. Where I work we now use Kotlin for all new backend code. And we don't do any Android.
Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @10:08AM (#24198707)
I abuse the hell out of this and @DSLMarker. Such a small but amazing feature.
Re:Kotlin 1.4 by lokedhs on Wednesday August 19, 2020 @07:16AM (#24209186)
I do that too, but a real macro facility would be a lot nicer. There are a lot of things that cannot nicely be implemented using the existing syntax.
Re:Kotlin 1.4 by thecupisblue on Wednesday August 19, 2020 @08:01AM (#24209534)
Yep, wish we had that. I had to satisfy myself with annotations and kotlinpoet for now.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @10:40AM (#24199109)
Very Groovy.
Re:Kotlin 1.4 by agumonkey on Tuesday August 18, 2020 @08:37AM (#24197874)
is that modeled on ruby ?
Re:Kotlin 1.4 by vvillena on Tuesday August 18, 2020 @08:45AM (#24197942)
This is a very common idiom in Scala. Function definition is slightly different, but usage is the same.
Re:Kotlin 1.4 by agumonkey on Tuesday August 18, 2020 @09:13AM (#24198153)
Any example ? or an idiom name I can google ?
Re:Kotlin 1.4 by swsieber on Tuesday August 18, 2020 @09:49AM (#24198490)
Groovy also does it. I have no idea what the name is though: https://mrhaki.blogspot.com/2009/11/groovy-goodness-passing-...
Re:Kotlin 1.4 by matsemann on Tuesday August 18, 2020 @05:09PM (#24204373)
Not sure about the exact name. But kotlin also has "function with receiver" that together with this makes it very easy to write almost a custom domain language on top of kotlin.
Re:Kotlin 1.4 by matsemann on Wednesday August 19, 2020 @03:31AM (#24208042)
Re:Kotlin 1.4 by jayrhynas on Tuesday August 18, 2020 @03:11PM (#24202964)
Swift calls it trailing closure syntax
Re:Kotlin 1.4 by agumonkey on Tuesday August 18, 2020 @04:43PM (#24204106)
Ok so it's an explicit parameter, the function is just ~curried so you can just write it nicely.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @10:41AM (#24199129)
Not at all, it is very common in ML languages, Smalltalk, and even Groovy already had it.
Re:Kotlin 1.4 by agumonkey on Tuesday August 18, 2020 @01:56PM (#24201887)
I never saw that idiom in any ml classes.. I'm honestly surprised
Re:Kotlin 1.4 by pjmlp on Wednesday August 19, 2020 @05:40AM (#24208688)
It is a common idiom for dealing with deterministic resource management, and takes advantage that in ML all functions are single parameter actually.

So you can partially specialize, and then the lambda gets the already allocated/opened resource, thus acting as region/arena resource allocator.

And you can combine it with currying to apply the concept to multiple kind of parameters.

Re:Kotlin 1.4 by untog on Tuesday August 18, 2020 @09:48AM (#24198478)
I don't know, but you can do the exact same thing in Swift.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @08:37AM (#24197869)
Spring sells to everyone, I am old enough to have seen that playbook with Groovy as main actor.
Re:Kotlin 1.4 by BossingAround on Tuesday August 18, 2020 @03:26PM (#24203176)
Groovy was good in what it set out to do, i.e. bringing Python freshness into the vast Java ecosystem.

I loved Grape for single-file scripts. Does any language have similar single-file dependency manager? I guess Go, but then, you have to compile Go, so it might not be as useful, because you distribute binaries anyways.

Re:Kotlin 1.4 by hocuspocus on Wednesday August 19, 2020 @04:15AM (#24208277)
Scala does, thanks to Ammonite:

https://ammonite.io/#import$ivy

Re:Kotlin 1.4 by asdfthvaa2 on Tuesday August 18, 2020 @08:00AM (#24197615)
>I believe pattern matching might land in Java sooner than in Kotlin

Depends on what you call pattern matching. Kotlin had pattern matching from day one, but it's just one level, Java might have it recursive by java 19

Re:Kotlin 1.4 by hocuspocus on Tuesday August 18, 2020 @08:48AM (#24197963)
Calling Kotlin's when pattern matching is a stretch. Even the official documentation doesn't call it like that anywhere.
Re:Kotlin 1.4 by asdfthvaa2 on Wednesday August 19, 2020 @11:14AM (#24211193)
Well, fr sealed classes it's quite good, but yeah, nothing like the scalas and haskells of this life
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @08:36AM (#24197866)
Because Android is Kotlin's selling platform, on the JVM it will be as relevant as Beanshell, jtcl, jython, clojure, scala, and many other guest languages.

Guest languages relevance always fades away as the platform language improves and the FFI gets out of touch with that old version of the language.

C18 on UNIX vs C++, JavaScript vs Typescript (see private members), and when time comes inline classes/reiffed generics/SIMD types vs being able to target both Android and JVM on Kotlin's case.

Re:Kotlin 1.4 by The_Colonel on Tuesday August 18, 2020 @08:59AM (#24198034)
Old men are always trying to discount progress as reiteration of what they already saw to fail.

But in reality, it's not the same thing, it's not the same time, not the same market environment.

Kotlin can succeed where others failed before because just about everything about it is incomparable with sorts like Beanshell.

Re:Kotlin 1.4 by dimitrios1 on Tuesday August 18, 2020 @09:12AM (#24198146)
Young men are always trying to count progress as the reiteration of what has already come before them.

In reality, while the differences are minor, they are the same thing. Time fades away, and market dynamics operate the same as they did 10,20..100 years ago.

Re:Kotlin 1.4 by The_Colonel on Tuesday August 18, 2020 @09:26AM (#24198250)
Yes, that happens with young people as well.

The hubris is in using absolute statements ("platform languages always win") instead of being a little bit more humble with their projections. Old men should know better that history rarely unfolds as expected.

Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @10:15AM (#24198789)
Old wise men know that young people forget history too soon, and we all know what happens when history gets forgotten.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @09:12AM (#24198149)
Indeed, bare my words, in about 10 years time, Kotlin will only be a thing on Android, assuming Fuchsia wasn't brought into the market as Android's successor.
Re:Kotlin 1.4 by hitekker on Tuesday August 18, 2020 @03:32PM (#24203258)
I’ll second this prediction.

Kotlin has made too many promises that it can't keep.

Re:Kotlin 1.4 by agumonkey on Thursday August 20, 2020 @02:35AM (#24220500)
Care to remind us ?
Re:Kotlin 1.4 by mping on Tuesday August 18, 2020 @04:07PM (#24203712)
Relevant for who? I will always strive for using the language that fits my needs regardless of what the majority thinks
Re:Kotlin 1.4 by int_19h on Tuesday August 18, 2020 @04:24PM (#24203890)
Can you explain what the difference is between C18 and C++ on Unix?
Re:Kotlin 1.4 by pjmlp on Wednesday August 19, 2020 @05:59AM (#24208775)
C++ copy-paste compatibility with C is based on C89, since then C has introduced many features that won't compile under a C++ compiler.

ISO C++ has kept upgrading the support regarding ISO C libraries, as long as new grammar features aren't required.

Even ISO C++20 has finally added support for structure member initialisation, it is just a subset of what is possible in C.

So while UNIX vendors are free to use all C features, due to their symbiotic relationship, ISO C++ applications can only safely compile C89 code.

No full structure member initialisation, restrict, VLA,...

Re:Kotlin 1.4 by amitheonlyone on Tuesday August 18, 2020 @06:52AM (#24197206)
I agree. I tried Kotlin when I was working on an Android app and it was a pleasant experience. Somehow, everything easily makes sense and the Android Studio support for Kotlin is excellent. I followed two Udacity courses before starting on the app. If it helps anyone, these are the courses:

Kotlin Bootcamp for Programmers[0]

Developing Android Apps with Kotlin[1]

There's also an advanced android development course which is a follow up which I am going through now.

[0] https://www.udacity.com/course/developing-android-apps-with-...

[1] https://www.udacity.com/course/developing-android-apps-with-...

Re:Kotlin 1.4 by scns on Tuesday August 18, 2020 @07:07AM (#24197301)
I would recommend working through Google's Codelabs if you wanna learn Android Programming with Kotlin. They are split up in Basic and Advanced.
Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @10:10AM (#24198733)
I would recommend skipping anything google recommended and finding courses made by people with real android development experience.

Google has it's own way of doing things - boilerplate, overengineered and full of ugly practices. Anyone will be better of learning from a source that isn't a bunch of interns that got thrown into the Android team.

Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @08:39AM (#24197886)
Android team makes it on purpose to use Java harder on Android, for obvious reasons.

Even the samples use Java 7 style code when comparing for terseness.

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

Re:Kotlin 1.4 by jansan on Tuesday August 18, 2020 @08:01AM (#24197620)
I 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.

Re:Kotlin 1.4 by Semaphor on Tuesday August 18, 2020 @09:02AM (#24198063)
> Also, I like IntelliJ's perpetual fallback license policy. Feels very fair to me.

It required a huge outcry, but they did the right thing in the end :)

Re:Kotlin 1.4 by donmcronald on Tuesday August 18, 2020 @10:54PM (#24206703)
> Also, I like IntelliJ's perpetual fallback license policy. Feels very fair to me.

That's nothing. You should have been here when they used to let us buy the tools :-)

Re:Kotlin 1.4 by 1f60c on Tuesday August 18, 2020 @06:55AM (#24197223)
You probably already know this, but if you spread the query over multiple lines, it’ll show you the exact type at each step.
Re:Kotlin 1.4 by vips7L on Tuesday August 18, 2020 @11:09AM (#24199582)
I have a love and hate relationship with Ebean. On the outside it's a breath of fresh air compared to JPA (which is extremely stagnant atm), it provides ActiveRecord [0] if that's your thing, built in type safe generated query beans [1], built in migrations [2], and it's pretty easy to setup and easier to use than say Hibernate.

But, at least at my company, we always tend to hit some corner case that the documentation doesn't cover or some bug that isn't searchable because let's face it probably < 1% of people using a Java ORM is using Ebean compared to JPA or Hibernate.

In the end it's left me longing for a proper JPA implementation.

[0] https://ebean.io/docs/setup/activerecord

[1] https://ebean.io/docs/query/query-beans

[2] https://ebean.io/docs/db-migrations/#db-migrations

Re:Kotlin 1.4 by notjustanymike on Tuesday August 18, 2020 @09:45AM (#24198446)
The way you describe it sounds a lot like the Typescript / VSCode pairing. Is that accurate?
Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @10:03AM (#24198655)
Not even close.

I've been primarily writing Kotlin for the last.. uhh, 3-4 years I guess. TS and VSCode pairing is good, but Kotlin + IntelliJ is both more faster and accurate in terms of knowing what you want and when you want it. Autocomplete, code generation, refactoring, moving works so good it is a huge productivity boost. And the "peeking" at types (the implied type is shown in a small gray box) lets you keep your code clean but very readable.

Re:Kotlin 1.4 by ragnese on Tuesday August 18, 2020 @09:49PM (#24206393)
Honestly, considering that JetBrains wrote both Kotlin and IDEA, I'm often surprised at the little papercuts when editing Kotlin code.

I can't tell you how many times it has autocompleted FooClass.Companion.functionName() for me and then immediately suggested that I should remove the Companion part. "Ya think?"

The performance also doesn't seem that awesome for me. It doesn't require a very large file before it starts taking several seconds to highlight and analyze it. Granted, I haven't upgraded to 1.4 yet, which supposedly improves performance.

Re:Kotlin 1.4 by andyfleming on Tuesday August 18, 2020 @10:53AM (#24199333)
All that works well TypeScript as well. The difference is that Kotlin only really works well in IntelliJ. TypeScript works well in both WebStorm/IntelliJ and VS Code.
Re:Kotlin 1.4 by BossingAround on Tuesday August 18, 2020 @03:33PM (#24203263)
Autocomplete in VS has always been kind of 'meh'... Works OK for Go, should work fine for TS (until your type packages are off, in which case good luck to you), but IntelliJ code completion for stuff like Java and Kotlin is just on another level.

It's very hard to pin point, but if you're developing a large project, you'll notice when autocomplete works 100% of the time (IntelliJ), and 93% of the time (VSCode).

Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @06:38PM (#24205181)
> you'll notice when autocomplete works 100% of the time (IntelliJ), and 93% of the time (VSCode)

Exactly this. You notice the "smoothness" is off, which when accumulated burns your context faster and kills your flow.

Re:Kotlin 1.4 by vips7L on Tuesday August 18, 2020 @04:10PM (#24203742)
In Java I don't notice many differences in the autocomplete in VsCode (eclipse) vs IntelliJ.
Re:Kotlin 1.4 by thecupisblue on Tuesday August 18, 2020 @11:57AM (#24200242)
Not even close in my experience. Autocomplete is slow, generation offers quite less and refactoring is quite slower.