Readit News logoReadit News
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
vips7L · 6 years ago
Unless it's Android, if they can't access the latest features of Java they more than likely can't access the latest features of Kotlin either.
driver733 · 6 years ago
That's not always the case, since Kotlin can generate Java 6 compatible bytecode.
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
jeroenhd · 6 years ago
Why don't the nullability examples use Java's Optional?

This code:

  if (nullableVariable != null) {
      boolean success = nullableVariable.someMethodCall()
      if (success) {
          return success
      } else {
          return fallbackIfNullMethodCall()
      }
  } else {
      return fallbackIfNullMethodCall()
  }

Could also be written something like this:

  result = Optional.ofNullable(nullableVariable)
                   .map(NullableType::someMethodCall)
                   .orElse(fallbackIfNullMethodCall());
Sure, it's no Elvis operator, but it's a lot more readable than the "standard" if/else structure of traditional Java. If we're comparing Java and Kotlin, we should at least give Java a fair chance. I dislike the verbosity of the Optional wrapper, but it's a lot better than if/else checking.

driver733 · 6 years ago
I completely agree. I'll make that change soon.

Thanks for the feedback.

driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
cosarara · 6 years ago
How does the order of evaluation work in the second form there? Will fallbackIfNullMethodCall() be evaluated even if not returned?
driver733 · 6 years ago
It can be done this way:

  result = Optional.ofNullable(nullableVariable)
                   .map(NullableType::someMethodCall)
                   .orElseGet(() -> fallbackIfNullMethodCall());

driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
vips7L · 6 years ago
Yeah this is nonsense and isn't an argument against the language. Embedded devs aren't allowed to use Rust, does that mean we shouldn't compare C++ 20 to Rust? Does that mean Rust is a bad language? If these said devs are limited to Java 6/7/8 does their company have the inertia to use a brand new programming language (Kotlin) that their devs don't know? Does this mean Kotlin is bad because they're not using it?

This is a bad argument.

driver733 · 6 years ago
My goal is to compare Kotlin with the current version of Java along with any Java libs that are commonly used (such as Lombok). I have mentioned the fact that some teams are still on older versions of Java just to highlight that not every developer can access the features of the latest Java release.
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
twic · 6 years ago
Absolutely wild how people are all in favour of Either/Result, but still look down on checked exceptions.
driver733 · 6 years ago
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
bitL · 6 years ago
OK, but where are the advantages? The page has just a different syntactic sugar resembling Pascal/Scala; sine JVM nihil Kotlin anyway. Sometimes Kotlin's "advantages" there have more boilerplate than Java...
driver733 · 6 years ago
I leave it to the reader to decide whether the advantages are clear or not.

For instance, in Kotlin you can perform operations on collection without converting them to a stream first, and collecting them with a certain collector afterwards. So in order to perform a single filtering operation on a collection, you need to do three steps in Java and just one in Kotlin.

Another advantage is coroutines, which not only allow you to write asynchronous code in a common, synchronous manner, but also get rid of shared mutable state, since coroutines can send/receive shared state through channels.

driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
vips7L · 6 years ago
Probably should do 13 since it's the current release.
driver733 · 6 years ago
Sure, but you have take into account that Android devs are limited to Java 6, most enterprise devs (based on my experience) are still on Java 8 and some are still on Java 5 or below.
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
xwowsersx · 6 years ago
Comparing to

>>> public static void main(final String[] args) { System.out.println("Hello world!") }

Is just a glamour shot. How many times does one actually have to type public static void main? Once per application, by definition.

driver733 · 6 years ago
It is, however, even in the scope of the "Hello world" app, Kotlin performs much better than Java in terms of bringing out business logic to the front.
driver733 commented on Kotlin vs. Java   kotlinvsjava.com... · Posted by u/driver733
JanecekPetr · 6 years ago
The I/O example is moot since Java 11 where Java got https://docs.oracle.com/en/java/javase/13/docs/api/java.base..., so we can do `Files.readString(Paths.get(doc.txt))`.

Java 14 is getting an experimental preview of Records (https://openjdk.java.net/jeps/359) which takes care of much (but not all) of ceremony around "data classes".

And Java 13 got a preview of text blocks, https://openjdk.java.net/jeps/355.

Things are coming. That said, I hardly believe those minor syntax improvements are what is so "good" about Kotlin. It has some better defaults (non-null by default, final classes by default), and is a more modern language. Java will stay with us for many years to come, though.

driver733 · 6 years ago
You are right, but you still have to catch the checked IOException.

u/driver733

KarmaCake day163December 23, 2018
About
Kotlin/Java developer, blogger, OOP and EO (elegantobjects.org) evangelist.

Blog: https://www.driver733.com GitHub: https://github.com/driver733

View Original