Archive for the ‘Groovy’ category

Acegi on Grails and plugin ponderance

November 14th, 2008

There’s a few little pain points I just encountered setting up Acegi on Grails.  I appreciate the ‘grails generate-manager’ functionality, and the ‘grails generate-registration’ stuff as well, and the basic tutorial is a good start.  Unfortunately, they still left off the part about having to define a role (using the role controller, for example) before the self-registration works.  Specifically, you’ll need to define a ‘ROLE_USER’ in the Role controller to match the defaultRole in the security{} block in the SecurityConfig.groovy file.

I just added 

         def r1 = new Role(authority:”ROLE_USER”, description:”User”).save()

         def r2 = new Role(authority:”ROLE_ADMIN”, description:”Admin”).save()

in my BootStrap.groovy file and this gets me going.

 

On a related note about Grails plugins, I’m already concerned about directive name clashes.  When a plugin is registered, it can expose extra functionality to the grails command line user.  In the above example, the Acegi plugin also gives you “grails generate-manager”, “grails generate-registration”, among others.  Those names are pretty generic – no other Grails plugin can really depend on being able to use the term ‘generate-manager’ because it’ll conflict with the Acegi plugin should it also be installed.  

I’d think it would make more sense to have a convention whereby all plugins’ functionality was prefixed by the plugin name, so the above would be “grails acegi-generate-manager”, for example.

 

TIOBE and Groovy and Grails random thoughts

November 13th, 2008

So having recently launched a magazine on the Groovy language, I decided to check out the TIOBE index and see where Groovy sits.  Not terribly high (#41) but not too bad for a relatively new language.  Certainly higher than many others with much longer pedigrees.  The TIOBE index also has a couple other interesting notes:

  • The trend for the last year for dynamic languages (vs statically typed languages) has gone down slightly. 
  • Perl is at an all-time low

Not much to do with me really, I was just somewhat relieved to see Perl start slowing down.  Yes, it’s going to be around for a long time, and yes, it’s powerful and CPAN has functionality to do everything except take out my garbage.  It’s just a difficult language for me to be productive in.  Always has been, likely always will be.  So, to the extent that alternatives make headway against Perl, I’m happy.  :)

How does all this affect Groovy?  Groovy is a unique beast, being able to be statically or dynamically typed, and compiling down to Java.  Many fans are eager to say Groovy *is* Java, but can be more if you want it to be.  Groovy brings the power of Java to the ‘scripting world’, and brings the power of scripting to the Java world, yet even that nifty phrase feels like it’s shortchanging Groovy some.

G2One, a consultancy based around Groovy and Grails (founded by the project leads of both Groovy and Grails) was recently acquired by SpringSource.  SpringSource is a consultancy and product development company built around the Spring framework.  I have to admit, not coming from a Java background, I still don’t 100% grasp how Spring fits in to the Java ecosystem, but I’m learning fast.  The shorthand version I’m getting from people is that the Spring framework simplifies Java development.  Anything that simplifies Java development is good in my book, but it apparently didn’t go far enough, because Grails seems to simplify Spring development, by bringing a standardized approach to web development and building on top of the Spring framework where appropriate.

I suspect that the acquisition will see a tighter integration of more Spring framework functionality in to the Grails framework.  It’s too early for me to say whether that would necessarily be a good thing.  Frankly, as a primarily non-Java person looking at the web development world in Java, the no-nonsense Grails approach has been much more productive for me than anything else (and I’d looked and tried out multiple web approaches in Java before discovering Grails).

SpringSource has an application server which looks to be a bundle of a modified Tomcat system and the Spring framework.  I installed it, and there seems to be less server management functionality than even a base Tomcat gives you.  From a ‘bloat’ standpoint, perhaps that’s good, but it seems to me that there’s still work to do to address the needs of the small web hosting business.

Why address those needs?  Because that’s where many businesses start off.  Many of the ‘enterprises’ of tomorrow will start with modest shared hosting accounts today.  Right now, it’ a PITA to have a Java web app (and specifically a Grails app, but others as well) live at the root of a domain.  It’s very easy to have “http://domain.com/myWebApp/” but harder to have “http://domain.com/” point to a standard WAR file.  Tomcat lets you do this once per server instance by specifically naming your WAR file “ROOT.war”.  Totally ridiculous, imo, and we need a Java hosting system that can manage mappings between virtual hosts and application installations (if only WAR files).  

“But Java is for enterprise applications” many Java die-hards will be thinking.  That’s only because it’s ceded the low-end hosting space to PHP and others by default, not because of any long-term strategy.  I’ll reiterate – this is important to Java’s long term future in the web world (and what part of the software space isn’t web-related?).  Smaller companies (which often grow in to larger companies later) will make their decisions based on a number of factors, but hosting support is one.  Developer availability is another, and developer familiarity with hosting options plays a part in what those developers end up devoting time to learning.

Virtualized servers solve the problem to some extent, but it’s the virtual host mapping which makes LAMP-style servers attractive to many people.  Multiple domains, all with root-path goodness, on one server with multiple discrete directories hosting various code.  I realize I’m harping on this over and over, but it’s been shocking to me how poor the support for this sort of thing is.  No decent interfaces, no way to delegate this sort of management to anyone except a server admin who has to futz around with multiple XML files on a server.  This went out of fashion in the LAMP world about 10 years ago, and I believe played no small part in the fast adoption rate of LAMP applications as the dominant face of public web applications.

Have I missed something?  Is it so simple to do this that no one even bothers to write about it because everyone ‘knows’ how to do it?  Or is this another area of Java which people have quietly abandoned (like cross-platform desktop multimedia).  To the extent that Sun is renewing their efforts behind JavaFX, we may see some traction for desktop Java again.  I’d like to see them (or anyone) make the same commitment to low-end Java hosting.

SpringSource, with its Grails acquisition, may be in a good position to address the needs of this market, helping to nurture a next generation of Java developers getting their first start with Java on Groovy and Grails web applications.  I’ve no idea if this is in their plans, but it doesn’t seem out of the realm of possibility.  Or does it?  Am I barking up the wrong tree?  Or just barking?  ;)

 

 

SpringSource acquires G2One

November 11th, 2008

I wrote up a small synopsis over at the GroovyMag blog about the acquisition, then just got pinged that my own quote about it made it in to PC World.  I’m famous.  ;)

My initial reaction was that this might hurt Groovy and Grails development, but I don’t think that’ll happen.  At least unless Spring ends up going back on whatever commitments they may have made privately to Graeme and Guillaume from G2One.  G2One would have no reason to agree to be acquired unless they thought it would ultimately be a good thing for the communities they serve.  Additionally, this doesn’t strike me as one of those ‘cash out and retire’ sort of deals.  SpringSource is buying Graeme and Guillaume’s names, reputations and experience, if nothing else, and likely wouldn’t *let* them just walk away.  What would have been the point of an acquisition if your primary assets leave the next day?  :)

Ultimately, we’ll wait and see how this plays out, but I’m cautiously optimistic that this will help mainstream adoption of Groovy and Grails technology.

 

 

Regular expressions are like broccoli…

November 10th, 2008

This was the analogy I came up with when teaching a PHP class recently.  I needed to review the topic of regular expressions, but it’s one that neither I nor the students seemed to have much interest in.  The examples that I had were adequate, but explaining the examples was still unnatural.  The students didn’t want to spend much time on regex, but I pressed ahead.  I suggested that regular expressions were like the broccoli of programming – something that left a bad taste in your mouth, but was ‘good for you’.  Now, usually the broccoli I eat is drenched in ranch dressing or balsamic vinegar, so it doesn’t leave a bad taste in my mouth.  And I know I’m not joined by 100% of the population out there – there are people who *enjoy* eating broccoli (and enjoy the taste as well).  They are a minority, just like people who enjoy writing and using regular expressions are a minority in the programming community.

Given my premise that regular expressions are like broccoli, what comparisons would you draw to other programming concepts or functions?

Closures are like carbohydrates?  Or chocolate?

Classes are like ________?

Functions are like _______ ?

Unit testing is like _______?

What catchy similes can you help me come up with?  Are these similes?  Or metaphors?  I used to say that an analogy was to a metaphor as a simile was to a __________ (this was one of those comparison fill-in-the-blanks you get on standardized tests).  Can you fill in that blank for me?  :)

 

GroovyMag on sale for $3.49 – one day only

November 5th, 2008

To celebrate our US elections, GroovyMag is on sale for $3.49 today only (November 5, 2008).  President-elect Obama won 349 electoral votes, and in an effort to ‘spread the wealth’, GroovyMag has lowered the price to reflect the electoral vote count.  Visit http://www.groovymag.com/main.issues to purchase your copy today!

Groovy Magazine finally launched

November 3rd, 2008

Yeah, there was a small bit of hype about getting it out the door, but the magazine for Groovy and Grails developers is launched.  Work on issue #2 is underway.

Free sample file up at http://www.groovymag.com as well.

Vote this up on reddit and/or digg if you would, please  (thanks!)  :)

GroovyMag is coming soon…

October 29th, 2008

I’m getting ready to launch GroovyMag – the magazine for Groovy and Grails developers – next week.  This will initially be a PDF-only product, tentatively priced at $4.99 – but we may move to print quickly if the demand is there.  The first issue is a bit over 30 pages (we’re playing with layout right now, so it’s not final yet), and I’ve been fortunate to have a stellar set of contributors for the first issue.  Dave Klein, Andres Almiray, Shawn Hartsock and Robert Fischer are all known and respected in the community, and I’ve been honored to have them help launch this magazine with their articles.

Check out http://www.groovymag.com to sign up to be notified once the magazine goes on sale!

Groovy Awards Nominees

October 1st, 2008

I was more than blown away to learn that I was nominated (by 3 different people apparently) for an award in the Groovy community.  Honored beyond belief to have my name up there in lights with Graeme, Dave Klein, Andres Almiray and so many other luminaries.   Thank you all for the nominations, and thanks to the Groovy community for being so awesome overall.  :)   I’ve no place winning anything, but just to have my name up there with others is humbling in and of itself!

Stupid Groovy Tricks

August 27th, 2008

Someone recently asked how to get a random element from an array.  In PHP it’s pretty straightforward – array_rand($x) – but there’s not (AFAICT) a built-in way in Groovy to do this.  So I wrote a little something which should hopefully demonstrate the power of the metaClass stuff to boot.

ArrayList.metaClass.getRand = { number ->
 if(number==0) {
   return delegate[new Random().nextInt(delegate.size)]
 } else {
   def tempList = []
   def counter = 0
   while(counter>number) {
     tempList.add(delegate[new Random().nextInt(delegate.size)])
     counter++
   }
   return tempList
 }
}
def names = ['mike','matt','mark','lesley','jean','ron','jeff','martine']
println names.getRand()
println names.getRand(5)

The first call to getRand() on the names list will just return one name from the list.  The second will return 5 random entries (and some could theoretically be repeated).  I’ve added this getRand() method to the base ArrayList class at runtime, even though it’s likely declared ‘final’ in Java’s base libraries.  This is one of the core powers of Groovy, and is pretty slick, imo.

Grails scaffolding improvement

August 27th, 2008

I put together a small change to Grails’ scaffolding templates to help with one to many and many to many relationships.  Grails (well, GORM really) will manage these relationships under the hood, but you were always left to do the interface on your own.  This small set of file changes will give you better relationship management when you ‘generate all’ or ‘generate templates’ for you domains.

Here’s a small screenshot of what an editing screen looks like:

To use these, simply ‘grails install-templates’ in your project, replace the two files from the SVN repo (see link above) and generate away.  This only deals with editing right now, not the ‘create’ step.  That could be modified, I’m sure, I just didn’t do it (or did it but didn’t make it work right).  If you’d like to contribute to this project, let me know.