GrailsInAction / graina2

Source code for the 2nd edition of Grails in Action
90 stars 92 forks source link

MEAP v11, chapter 5, usefulness of `parseDate()` ? #42

Closed marcpa00 closed 10 years ago

marcpa00 commented 11 years ago

At end of section 5.2.1, code snippets are using a parseDate() method that is not defined in the text. I know there is a paragraph stating not to worry and that its actual implementation is irrelevant, but, if others are like me, they will end up running most (if not all) code snippets in a grails console and the snippets with parseDate() will fail. Changing them is not terribly difficult, but I fail to see the benefit of having this hypothetic parseDate() method in there.

I would suggest to use new Date() (and variants) as it is done in some other snippets in this chapter. I prefer to have code that I can copy/paste in my grails console to experiment as I learn rather than have code that looks like production code (if that was the intent?).

Same thing for sub-section "5.3.2 Introducing Criteria queries" where the first fragment use a parseDate(params.fromDate) while a ge "dateCreated", new Date() -1 would do the job, like what is done in the second fragment in that sub-section 5.3.2.

pledbrook commented 11 years ago

Fair point. I can't remember offhand exactly why that method is there, but the existence of a method call is the important bit I think. Hence why the implementation doesn't matter. I wasn't terribly happy about this little sleight of hand, so I'll revisit this.

pledbrook commented 10 years ago

I've reviewed this and I think you're right. I wanted to follow on from the example in the previous section and make it look like it was part of a controller action. And of course dates in params are strings. So I added the method in.

I'm going to explicitly put the example query in a standalone method. You can easily copy and past that into the Grails console and call it with any arguments you choose. I'll also add a little sidebar somewhere explaining how to run BootStrap.init in the console.

pledbrook commented 10 years ago

lol, just realised that I already talk about trying out queries in the console later in the chapter.

marcpa00 commented 10 years ago

Proves it is a pretty good idea :-)

Le 2013-10-14 à 10:45, Peter Ledbrook notifications@github.com a écrit :

lol, just realised that I already talk about trying out queries in the console later in the chapter.

— Reply to this email directly or view it on GitHub.

pledbrook commented 10 years ago

Next MEAP will have the modified example. Not parseDate() any more. Should be easier to follow. Thanks for bringing it up.