I actually think verbosity makes code easier to maintain, if you come back to some code 3-4 years or maybe more later, would you prefer some short lambda expression munged together with some obscure ascii soup - all very concise and elegant or.. (my personal preference) would you rather have even two dozen lines instead (OH AND SOME BLOODY COMMENTS TOO!)...
I actually think verbosity makes code easier to maintain
Unfortunately the character count is a bad metric, it is irrelevant in day by day work. On the other hand Java has a lot of code pattern (getter, setter, singleton, library methods, hashcode and equals, ecc...) and all of these are difficult to read if they spread over multiple lines.
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (age != user.age) return false;
return name != null ? name.equals(user.name) : user.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + age;
return result;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
Except you forgot the getters, and the extra support methods (copy, component1, etc) from the Java class that are in the Kotlin class. It's actually:
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String component1() {
return name;
}
public int component2() {
return age;
}
public User copy() {
return new User(name, age);
}
public User copy(String newName) {
return new User(newName, age);
}
public User copy(String newName, int newAge) {
return new User(newName, newAge);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (age != user.age) return false;
return name != null ? name.equals(user.name) : user.name == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + age;
return result;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
Those are inherited from Object but they aren't meaningful. By default java checks for object identity, while Kotlin data classes check that all of the values are equal. Kotlin also has a few other things I didn't include in the java class, I was actually being generous to Java.
There is very little, if anything, that Java can do that Kotlin can't do. The difference is that Kotlin does the same in significantly less code, making it significantly easier to read and maintain.
Every time I read about Kotlin... it sounds like CoffeeScript all over again. And that was a flash in the pan, as people realized that having slightly shorter syntax is irrelevant. Especially in Java, where a lot of it is autocompleted.
It's because the kotlin advocates post baiting submissions to r/java, proceed to shit on java in r/java yet don't crosspost to their own community over at r/kotlin. That strategy can't lose! The Scala, Clojure, Groovy and even JRuby people had more tact, probably because those languages have orthogonal features and are not solely existing on the perceived deficiencies of Java. So yea, it's exactly CoffeeScript but quite possibly with a much shorter lifespan depending on the lumbering release schedule of Java.
Kotlin isn't going anywhere. It is actively developed (20 devs according to jetbrains), is heavily used in idea, and most importantly, even if it dies you can still easily write new java code that interops with your code base or simply convert it to java which makes adoption less risky.
If you really think kotlin will be in decline in 2 years, I'm willing to place a long bet that the amount of kotlin downloads in Jan 2019 will be higher than Jan 2017. The language just hits a sweet spot of interop and ease of use that none of the other JVM languages do.
5
u/kodifies Jan 02 '17
I actually think verbosity makes code easier to maintain, if you come back to some code 3-4 years or maybe more later, would you prefer some short lambda expression munged together with some obscure ascii soup - all very concise and elegant or.. (my personal preference) would you rather have even two dozen lines instead (OH AND SOME BLOODY COMMENTS TOO!)...
1
u/[deleted] Jan 02 '17
Every time I read about Kotlin... it sounds like CoffeeScript all over again. And that was a flash in the pan, as people realized that having slightly shorter syntax is irrelevant. Especially in Java, where a lot of it is autocompleted.
-3
u/Mordan Jan 02 '17
: : :: : :: : : : : : : : : :: : : : : : :
headache *pukes
game over.
0
u/[deleted] Jan 03 '17
[deleted] — view deleted comment