Tuesday, July 14, 2009

Groovy and Grails - why assert is great

well as always when you work with grails, well you work with closures in the controller and want an easy way to check if the parameter you require actually exist.

Now there are different ways to check for this, the old and long java version:


if(params.get("myField") == null){
throw new RuntimeException("please provide the\"myField\" argument");
}


now the assert statement makes this a lot easier to read and saves code


assert params.myField != null. "please provide the \"myFiled\" argument"


now isn't this simpler?

1 comment: