The No.1 i-Technology Magazine in the World !
   
 
Clint Shank's Blog

Java vs. Scala Ceremony

posted 17 Nov 2009

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?

tags:    

links: digg this    del.icio.us    technorati    reddit




1. Chris E left...
20 Nov 2009 1:03 am

The C# gets a little closer to the Scala.....

class Person {

  • public string FirstName { get; set; }

  • public stirng LastName { get; set; }

  • public int { get; set; }

}

Is Java considering adding properties?


2. Clint Shank left...

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.

I'm not clear where Java the language is headed. It's become stagnant. Java the Platform is still exciting, which is why I spend as much time as I can working with Groovy and Scala, and seeing what Clojure is up to these days.