On Github aaronhanson / gum-2013-where-be-dragons
Rapid Protoype Development
grails generate-all
Enterprise Development
grails install-templates
grails create-controller
def user = User.get(id)user.properties = params
slightly better
def userCommand = new UserCommand(params)def user = User.get(id) // still insecure probablybindData(user, params)
Grails 2.3 (new, but similar)
@Transactionaldef update(User user) { .... user.save flush:true .... }
Prototyping you might do this:
<g:select name="states" from="${State.list()}"/>
But you should probably do this instead:
class FooController { def list() { // ... [states: States.list()] }}
<g:select name="states" from="${states}"/>
GOTCHA!
<g:each in="${customer.phoneNumbers.sort()}" var="phoneNumber">
Use more templates
Use more taglibs
Be mindful of the need to
.encodeAsHTML()
.encodeAsURL()
g:* tags will do it for you
roll your own or output from model directly,
you're own your own
OK For CRUD Applications
ProductController
ProductService
Product
Better For Other Applications
CatalogController
ShoppingService
You're lazy. So am I.
Why do we often create services for everything?
class FooService { def barService ...}
Not everything needs to be a service.
Libraries with good old fashioned functions are OK too.
src/groovy
Try to keep your app out of your libraries.
Quit using your domain classes as services.
Domain instances should operate on the things they know about.
If you need to look up information or do more logic, use a service.
Services are good to funnel calls and add things like caching.
Think about DomainClass.* as DB.*
Foo.executeQuery('select * from Bar where id = 1')
Doesn't have anything related to Foo. Smell.
Why?
Is it really a service or is it a library?
Perhaps you're trying to do too much?
Testing can be difficult
Code coupling possibility higher
Stop it!
phases vs test type
unit - fast
integration - slow
functional - slow
Quit writing unitegration tests
(yes I made up a word)
Package naming/Plugins
Questions/Heckling?