|
Man, every time I go to write some Java code these days, I just cringe at all the effort.
public class Person {
private final String firstName;
private final String lastName;
private final int age;
public Person(String firstName,
String lastName,
int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public int getAge() {
return age;
}
}
Sure, it didn't take me too long to write the Java code because of the handy dandy source code generation features in my IDE. But the real problem is the maintenance. I or someone on my team will have to read this cluttered code many more times than the one time I wrote it.
Take a look at the equivalent Scala code:
class Person(val firstName: String,
val lastName: String,
val age: Int)
Which version would you rather maintain?
The C# gets a little closer to the Scala.....
public string FirstName { get; set; }
public stirng LastName { get; set; }
public int { get; set; }
Yes, I agree that C# has done a better job in the evolution department
while Sun has focused on backwards compatibility. I'm not sure if
properties will ever be added.