Archive for the ‘Groovy’ category

Super Tuesday!

November 17th, 2009

One of my coworkers recommend combining some posts together than one a bunch of ‘one offs’ of links or news of interest.

I’ve accumulated a set of links, thoughts, experiences, etc… over the last few days (I’ve been busy). 

New Sharp Architecture Release

http://devlicio.us/blogs/billy_mccafferty/archive/2009/11/12/s-arp-architecture-1-0-2009-q3-with-nhibernate-2-1-1-ga-released.aspx

Basically Sharp Architecture is about as close as you can currently get to a Spring/Hibernate MVC architecture in .NET.  My last project used several pieces of Billy’s previous ‘NHibernate Best Practices’ that I retrofit for asp.net mvc.  Then, Billy helped put together Sharp Architecture!

A snippet of what Sharp Architecture is at the wiki:

Pronounced "Sharp Architecture," this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate. The primary advantage to be sought in using any architectural framework is to decrease the code one has to write while increasing the quality of the end product. A framework should enable developers to spend little time on infrastructure details while allowing them to focus their attentions on the domain and user experience. Accordingly, S#arp Architecture adheres to the following key principles:

  • Focused on Domain Driven Design
  • Loosely coupled
  • Preconfigured Infrastructure
  • Open Ended Presentation

 

SpringSource updated to 2.2.1 includes new GSP Editor

I updated my SpringSource (STS) – (see more below about STS + Grails)
The update to 2.2.1 is here: http://www.springsource.org/node/2172

Grooy and Grails Random Thought

As a very well done project for building web applications…what is it’s popularity out in the world?  Are companies afraid of it?  Take NHibernate in the .NET world, in spite of it’s best of breed position, companies would rather use less to not use open source (the ‘it’s not from MS position’).  Is Groovy and Grails popular out there ?  If you do Grails/Groovy development – ping me please – let me know where your at, how you like it, etc… I’d like to see if it’s made much of a dent out there!

What I’m reading: ‘Grails in Action’ : Some Thoughts While Reading

 
Shout out to Manning for this e-book, love their setup, easy to purchase, prices are fair, many up and coming books on topics you don’t see in the mainstream yet!

Chapter 1 – good start.  Steps through the creation of a sample grails app.  Covers the basic commands.  Only issue I had was using the ‘file db’ – so I setup Grails to run on MySQL, which was a good exercise.  Tests still run in memory, which is good.  Final part was using prototype with taglibs to do some simple ajax.  I like how it starts by not bogging down into details, but getting something up and running.    

Highlights:

  • convention over configuration
  • removal of much of the xml configuration
  • testing built in.
  • Domain focus, code generated is clean and ‘pojo’.
  • Built in common functionality ie. prototype.
  • Good helper support with tablibs.

Chapter 3

…Chapter 2 was a nice overview of Groovy.  I’m now moving on to ‘Modeling the domain’:
This chapter covers
â–  What GORM is and how it works
â–  Defining domain model classes
â–  How domain classes are saved and updated
â–  Techniques for validating and constraining fields
â–  Domain class relationships (1:1, 1:m, m:n)

STS and Grails

http://www.grails.org/STS+Integration
Nice setup I’m using, shows how to create or import an existing Grails project into the workspace

I like the way that Grails provides integration tests as part of the framework that automatically handle transactional rollbacks.

I like the integration that STS does provide for Grails.  But I do think doing the work from the command line is faster and more efficient.  After adding new items, just refresh the Eclipse project and it’s there.  This is especially good for quickly running tests.

Grom

One thing I see in other frameworks (ie. asp.net mvc) is the concentration on views and controllers.  Whereas in Grails, I think the pattern all starts with the domain model.  Generate the model which has what I would call ‘built in DAO support’.  GROM makes life easier  :)

Validation

Grails validation is very well done, it’s built on a ‘constraints’ model with a built in validation DSL.  From Grails in Action:

static constraints = {
        userId(size:3..20, unique:true)
        password(size:6..8)
        homepage(url:true, nullable:true)
    }

This says ‘userid must be unique (in db) and be between 3 to 20 characters long’  – nice eh?

 

Software Craftmanship Manifesto


Did some pair programming last couple of days.. it was fun to say ‘whoa, this needs a new class here!’, refactor, make it more readable, etc… Must have been the next day I was shown this manifesto.  The only part that is still missing is the testing part, although some of the code is using legacy code that doesn’t lend itself well to testing… nevertheless, there is a real sense of accomplishment and success in writing code when there is craftsmanship put into it… so this manifesto is spot on!

http://manifesto.softwarecraftsmanship.org

 

How to start agile development in your team:

http://weblogs.asp.net/rosherove/archive/2009/11/16/how-to-start-agile-development-in-your-team.aspx

Thanks to Roy Osherove, as my current client was recently asking it’s team ‘are we agile’… From the link above:

    1. start doing daily stand up meeting
    2. start doing automated builds
    3. start working in pairs on relatively complicated problems
    4. start doing code reviews
    5. start showing visible progress
    6. start trying to show demos every two or three weeks
    7. start learning unit testing
    8. learn how to code better, design better
    9. start doing TDD

As a company, there are maybe 2 items here, as a team, more like 50% ?  I will say this: more and more it’s about the culture.  Happens everywhere, even on ESPN radio there was talk about the ‘culture’ on a team in the NFL, take a so-so quarterback, joins a new team, with a different culture, and he does well…(Denver Broncos) take a star on one team, move him into another culture… and he struggles…(Chicago Bears). 

More work needs to be done to promote a new culture in companies.  How to ‘sell’ to upper management who doesn’t seem to care ‘how’ you do it, as long as you go it… vs.  technical people in a company that totally reject anything new.   Where I’m at now, every new idea is really rejected, the company is fine with it’s ‘it was made here’ approach, but it is already showing it’s age and it’s big, bulky and hard to move it forward.  Some work was done to add some domain driven design concepts, add some tests, etc…  In the end… culture… If you haven’t watched ‘Pimp My Architecture’– watch it! 

Here is a related article from InfoQ:

Tips to Select a Pilot Project for Agile Adoption (InfoQ) :

One of the most important factors which influences the success of Agile adoption is the set of learnings derived by applying Agile to a pilot project. These learnings significantly influence the organization to go ahead with Agile or fall back to their usual process. This places a lot of emphasis on the selection of the pilot project. A wrong type of pilot could end up aborting, which would be a poor advertisement for the new process.

and

An engaged business sponsor can help the team if it needs to push against entrenched business processes, departments, or individuals. The time and energy of a business sponsor are critical to the success of the project…all these factors become meaningful with a strong team. Hence, choosing the right team is a precursor to all the above factors.

It takes a “strong/right” team with a mindset to embrace the agile methodology.  They later become the flag bearers for other projects within the organization.  

NServiceBus – Web Asynchronous Publishing


nservicebus includes an async pages sample.  Publishing a message asynchronous to a queue and it returned back to the page.  Get 2.0 beta – and learn how nservicebus works.  This brings to mind a lunch conversation today..SOA isn’t just ‘web services’ – there is much more to it.  NServiceBus helps provide a message based architecture.   

ie. Command Query Pattern

The command service publishes messages about changes to data, to which the query service subscribes. When the query service receives such notifications, it saves the data in its own data store which may well have a different schema (optimized for queries like a star schema). The query service may also keep all data in memory if the data is small enough.

Learn More

TCP Sockets, Chat Program

Don’t ask about this one.  I am working on some port listener code for a flying sim hobby I enjoy.

Good start …

Building a Chat Server

Building a Chat Client

… by the way… Groovy does it better  :)

s = new Socket("localhost", 8283)
s << "Groovy Rocks"
s.close()
 

(reference : http://gallemore.blogspot.com/2008/01/socket-client-for-groovy.html and Groovy Sockets: http://pleac.sourceforge.net/pleac_groovy/sockets.html)

 

asp.net mvc 2 beta released at PDC


http://haacked.com/archive/2009/11/17/asp.net-mvc-2-beta-released.aspx

Here are some highlights of what’s new in ASP.NET MVC 2.

    * RenderAction (and Action)

    * AsyncController

    * Expression Based Helpers (TextBoxFor, TextAreaFor, etc.)

    * Client Validation Improvements (validation summary)

    * Add Area Dialog

    * Empty Project Template

I hope to see some ‘grails like’ command line scaffolding and richer domain class support in upcoming versions.   In my post there, Phil says ‘Version 3’… so.. stay tuned!

I’m really glad to see Microsoft continuing this project, it’s a breath of fresh air – I have a 1-1/2 year project that is using it and I never grow tired of the technology part of it.   

LifeCycle Data Services (LDS)

 

Huh?  :)   This is one a bit out of my normal range, but I was curious about an InfoQ article talking about Flex/Flash/AIR, etc… and one of the tools they are making is LDS.   LDS is about domain modeling.

And so the way it works is that, we have a model that becomes the centre of the universe, if you want, of the server-side developer and you create a model that represents your data. You can create it from scratch or you can introspect the database as a starting point

…

There is a new plugin that you add on top of Flash Builder: that is the Model Designer. The process that I just described here is actually done within Flash Builder in a kind of a visual way; so we have a visual model editor. In that model, it’s more than what you typically do in a pure data model – you can add constraint and validation rules, you can specify things that typically you would have to specify again and again in view components

…

Once you create your model, you deploy the model and basically you don’t have to write server side code because, based on the model, we have enough to really provide a persistence layer

Nothing new here right..? Well, what caught my eye was that they are using Hibernate (my bff) !!!  So, even Adobe is hopping into the mix here :)

Behind the scenes, this is implemented using Hibernate – the persistence layer is provided by Hibernate – and then we also do some code generation on the client side, again the value objects and the service proxies. The key point is that the foundation for that is still the data management service

There you have it.  Now if we can just get Microsoft to embrace NHibernate and see the light…  :)

And last…. but not least… I saved the best for last:

Slashdot post: ‘Less than Free’

 

On the day that Google announced its new service, the stock in the two companies that had controlled the market for map data, Garmin and TomTom, dropped by 16% and 21%, respectively. (Those companies had bought Google’s erstwhile map-data suppliers, Tele Atlas and NavTeq, in 2007.)

Read more about ‘the strategy behind Google’s releasing turn-by-turn mapping for free…’ .  Wow.

Quick How-To for Grails with MySql

November 5th, 2009

1. install mysql  (I’m running 5.0.83)
2. get java driver for mysql http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.10.zip/from/pick#mirrors

3. Open the zip file and extract the jar file into the lib directory of your Grails application.
4. alter the DataSource.groovy file in conf

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration
dataSource {
    configClass = GrailsAnnotationConfiguration.class
    pooled = false
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}

5. development {
        dataSource {
            dbCreate = "update" // one of ‘create’, ‘create-drop’,'update’
            //url = "jdbc:hsqldb:mem:devDB" //jdbc:hsqldb:file:devDB;shutdown=true
            url = "jdbc:mysql://127.0.0.1:3306/test"
        }
    }

6. create a catalog in mysql – ie. test    check your url, mine was 127.0.0.1:3306
7. I ran grails console and then wrote some groovy/grom statements to test it  ie.  println Quote.count()

Next book – Grails in Action

November 4th, 2009

I’ve placed my ebook order for Grails in Action (I’m a Manning fan – lol).  I’m really looking forward to this one.  I wanted to point out that while reviewing this book, I had a chance to sit down and read chapter 1.  I recommend anyone interested in learning more about Grails to check it out.

Sample Chapter 1

Good stuff!

Groovy Grails… so groovy!

November 4th, 2009

Well, I wasn’t content enough to just develop with Netbeans, I just had to reach out to Eclipse and get the Grails/Groovy  going. So, ran into SpringSource.  (see here http://www.grails.org/STS+Integration ).

Couple of potential gotchas, one of which will be updated in next release I’m told:

  1. on windows, don’t install to like c:\program files   -  use a path with no spaces… ie. I installed to c:\Tools\springsource   This is suspose to get fixed soon in next release of springsource
  2. make sure again you are pointing to a 32-bit jdk.  I have the following environment variables setup.   And the installer will ask you for a jdk:

GRAILS_HOME   ie. C:\Projects\Grails\grails-1.1.1

JAVA_HOME   ie. C:\Program Files (x86)\Java\jdk1.6.0_11

So, I created a new Grails project…

to get around this issue or disable the native translation by putting "grails.enable.native2ascii=false" in your grails-app/conf/Config.groovy.

That did work. So, off I go again, finding my personal favorite series on Grails … starting with Mastering Grails: Build your first Grails application.  I enjoy the IDE integration, and yet, I find it best to just have the command prompt window open with the IDE, and issue commands via the command prompt window… Although it’s really easy to issue commands by using Control + G (not sure what mac shortcut is) to get a dialog that lets you issue commands quickly to the console. From there you can run-app, etc… pretty handy. I’m really enjoying this experience, I did a quick screencast on using grails ui  – great stuff.  There are many plugins.   The beauty of the plugins…. is the installation for sure.  Simply run, in this case

grails install-plugin grails-ui
 

Don’t forget your jQuery plugin! :) ( http://www.grails.org/plugin/jquery )

Update: I highly recommend for those wanting to learn more to check out: http://blogger.forgottenskies.com/?p=513