Scala's syntax heaven
Friday 22. May 2009 kl. 16:43
Posted by Hugi
I've been playing around with Scala in the last few days... I must say that the Scala syntax is really nice and concise - it really works hard to eliminate the boilerplate code we all spend far too much time writing.
If you don't believe me: see for yourself (it's an extreme example, I know - but it goes to show how a little change can go a long way). The magic that's going on here is that variables declared in the constructor will automagically become class properties. A lovely little feature.
Scala:
class DBConnectionInfo( var url:String, var username:String, var password:String ) {}
Java:
public class DBConnectionInfo {
private String _url;
private String _username;
private String _password;
public DBConnectionInfo( String url, String username, String password ) {
setUrl( url );
setUsername( username );
setPassword( password );
}
public void setUrl( String _url ) {
this._url = _url;
}
public String url() {
return _url;
}
public void setUsername( String _username ) {
this._username = _username;
}
public String username() {
return _username;
}
public void setPassword( String _password ) {
this._password = _password;
}
public String password() {
return _password;
}
}
Comments
No comments.
Express yourself!