Skip to main content

Posts

Testing Groovy domain classes

If you are trying to test Grails domain class constraints by putting your unit test cases in the 'test/unit' directory, then your tests will fail because the domain objects will not have the 'valdate' method. This can be resolved in two ways: Place the test cases inside test/integration (which will slow things down) Use the method 'mockForConstraintsTests(Trail)' to create mock method in your domain class and continue writing your test cases in 'test/unit' What follows is some example code around this finding. I am working on a Groovy on Grails project for a website to help programmers keep up and refresh their skills. I started with some domain classes and then moved on to write some unit tests. When we create a Grails project using grails create-app , it creates several directories, one of which is a directory called 'test' for holding unit tests. This directory contains two directories, 'unit', and 'integration' for unit and ...

Groovy on Grails

Grails is a web application framework build on top of well known languages, frameworks and libraries. It uses the Groovy programming language which gives it power because of it's dynamic nature. Under the hoods, Grails uses Spring framework (for MVC), Hibernate (for OR mapping), Quartz (for scheduling), Log4J (for logging), JUnit for unit testing, and Canoo Webtest for functional testing. We already have a Gazillion frameworks, do we need Grails ? Typically web development in Java is a very long and arduous process. When a web project is started, many configuration files have to be set up after which the project development begins. Even then we have to create domain objects, basic controller functionality, the model, stylesheets, views, and other aspects of business logic. Grails makes things easier by allowing us to do all of these things rapidly and in fewer lines of code. So how does Grails allow us to do all this with fewer lines of code? Grails uses convention over c...

Internet and new media for teaching and learning

Today, Freeman and I did a video talk for a faculty development program at SCIT on how teachers can use the Internet and New Media for teaching and learning. Internet And New Media For Teaching View more presentations from parag . Some useful links for those who are new to this medium. Google Groups is a good and simple way to start a mailing list. Google Reader is a good blog reader. For hosting a blog, I recommend either Blogger or Wordpress to start with. If you want more control, you can download the Wordpress software and install it in your own server. ITunes is a good client software for listening to podcasts. But ITunes works only on Windows and Mac. For those running Linux, the Miro Player is a good option for video podcasts, and Amarok or JPodder for audio podcasts. ITunes university has several podcasts hosted by universities worldwide. If you want to create a podcast, you can use Audacity for recording them and Odeo for free hosting. Those interested in Twitte...

CompSci videos at Stanford

I came across some very interesting videos published by Stanford. These videos are recordings of some computer science courses offered at Stanford. I still have not had a chance to see all of them, but I am sure they will be very informative. Programming methodology series at Stanford (lectures 23/24 may be useful for developers who already know programming) - video Programming abstractions series at Stanford (looks like an interesting lectures. They focus on data structures, implications of using certain data structures, recursion, algorithm analysis like the Big O notation) - video Programming paradigms series at Stanford (Talks about imperative, OO, & functional programming. Also discusses many good low level things like pointers, big/little Endian, representation of data as bytes, and also touches on algorithms, assembly code, etc) - video Machine learning series at Stanford - video I hope you find these useful. I will share more links as I discover them.

Some more impressions of Python

List comprehensions: List comprehensions are pretty neat. Before studying Python I did not know what they were. This is a wonderful way to perform some operation on an entire list. Let me explain with an example. Let's say we have a list of numbers and want another list containing the double of all the numbers greater than 5 from the first list. In Java we would have to do something like this: private static List getDoubleOfMembers(List numbers) { List result = new ArrayList (); for(int num : numbers) { if(num > 5) { result.add(num*2); } } return result; } However, in Python we can perform this operation using list comprehension like this: [n*2 for n in numbers n > 5] Isn't this nice? Lambda expressions: Python supports Lambda expressions but it does not support closures like Groovy. I wish Python supported closures. Unchecked exceptions: The blogosphere has had more than it's share of discussions on checked vs. unchecked exceptions. I will not spam y...

My first impressions of Python for the second time

I had worked a bit in Python many years back. Since then I have forgotten almost everything I learned back then. I think the phrase "Out of sight out of mind" applies perfectly to my mind. Since the last few days, I have started relearning Python, and this time I am recording my impressions of Python after having come to it from a Java background. Indentation: Python uses indentation to specify blocks of code, instead of curly braces. I like this, because we anyways indent code to increase readability, so why not achieve two tasks together. Code looks much cleaner without the curly braces. However there may be a little downside. Everyone in the team will have to set up their IDE's in the same way. Things might fall apart if some people use tabs and others use spaces for indentation. Access modifiers: Python does not have public, private, and protected keywords. Everything is public. However, private members can be specified with a leading single underscore. If we use do...

String interpolations in different languages

I am learning Groovy and refreshing my Python skills as well. While working on some examples, I realized that the operation of concatenating string to produce a larger string is a very frequently used operation. Very often parts of the string we are creating are already held in variables. A crude way of creating the larger string, is to simply concatenate everything as shown in this simple toString() method of the Person object. public class Person { //showing only relevant code public String toString() { return "Name: " + name + " salary: " + salary + " address: " + address; } } However, this is not very readable. A better way is to use either string interpolation or templating. Java gives us a couple of ways to do templating. We can either write the toString() method like this to become much more readable: public String toString() { return String.format("name: %s salary: %d address: %s", name, salary, address); } Or we can use the M...