Archive for the ‘Groovy’ category

GroovyMag and JSMag issues

August 17th, 2009

The August issues of GroovyMag and JSMag are both out.  They’ve been out since earlier this month, but I didn’t publicize them here yet.  :)

GroovyMag‘s content this month includes Part I of building a Grails Portal, Part II of  Logging in Grails, a deeper look at Groovy Typing, the Clojure Plugin, Grails with RMI, and more.

JSMag this month includes pieces on using Cross-Domain AJAX, Events with JavaScript, Yahoo Query Language, ExtJS Plugin Development, Mobile App Development with Dojo, and more.

I mentioned it on the JSMag blog, but not here, so I’ll repeat myself.  One of the pieces of feedback I got on JSMag a few months ago was that the topics looked a bit advanced.  While that was intentional, I’ve added a monthly column aimed at people new to JavaScript.  The column is written by Shea Frederick, so whenever you see anything from him in JSMag, it’s for JS beginners.  I’m still looking for a name to give the column (“Beginner’s Corner” sounds a bit too cliched, no?) so if you have any suggestions, let me know.  :)

Traveling around a bit – Denmark May 18, 19, 20

May 17th, 2009

I’ve been in London most of the last week, and had a great time meeting up with people (DylanS and Sam from the Dojo project, Rajat from Yahoo, some locals putting on a minibarcamp, and others).  I’ve done some video and audio of some of these meetings and hope to put them up someplace in the next week or so. 

I can’t sleep, have a cold, and am catching a taxi to Heathrow in the next 30 minutes, so I figured I’d just post this quick update here.  I’m heading to the GR8 conference in Denmark this morning, and should be there by noonish.  If you’re in Copenhagen on Wednesday and care to meet for lunch, let me know.  I’ve got no firm plans at this point, and don’t leave Copenhagen until Wed evening (6pm I think).  Would love to meet up with some web people from Denmark (PHP, Grails, Ruby, CF, Java, C#, ASP.NET, Flash – even JavaFX!)  :)

PPP PHP question v2 – the humbler post

March 22nd, 2009

Obviously I rubbed some people the wrong way, and didn’t explain my question(s) clearly enough from the outset, then got wrapped up in taking some offense from some of the responses.  Reviewing everything today I can see where I could have responded differently, and more clearly, earlier on.  Apologies to anyone who was offended (if anyone was).

I do think the original point(s) were somewhat lost.  To the original poster who offered the banking analogy – thank you.  However, I don’t think it’s enough, and is clearly at odds with some of my other experiences with Java/Groovy.  Let me show two code samples here (assuming WP doesn’t mangle the code too much – I need to get one of those code display plugins in here!)

In Groovy (Java), if I run this:

===========================
class person {
private email = “person email”
protected phone = “person phone”
public name = “person name”
def showInfo() {
println this.email + ” ” + this.name + ” ” + this.phone
this.onlyInUser()
}
}
class user extends person {
private email = “user email”
protected phone = “user phone”
public name = “user name”
def onlyInUser() {
println “I’m in the user class definition”
}
def showInfo() {
super.showInfo()
println this.email + ” ” + this.name + ” ” + this.phone
}
}
def u = new user()
u.showInfo()
===========================
I get this output:

===========================
person email person name person phone
I’m in the user class definition
user email user name user phone
===========================

*All* the *this* property accesses are class-bound, it seems, but the this.onlyInUser() call still calls the method in the child class.

In C# (my C# isn’t hot, but this *seems* to be a correct re-implementation of the same logic) if I run :

===========================

using System;
class person  {
public string name = “person name”;
protected string email= “person email”;
private string phone = “person phone”;

public virtual void showInfo() {
Console.WriteLine(“In the person showInfo method”);
Console.WriteLine( this.name + ” ” + this.phone + ” ” + this.email);
}
}

class User : person {
public new string name = “user name”;
protected new string email= “user email”;
private new string phone = “user phone”;

public override void showInfo() {
base.showInfo();
Console.WriteLine(“In the user showInfo method”);
Console.WriteLine( this.name + ” ” + this.phone + ” ” + this.email);
}

// Main begins program execution.
public static void Main()
{
User u = new User();
u.showInfo();
}
}

===========================

I get

===========================

In the person showInfo method
person name person phone person email
In the user showInfo method
user name user phone user email

===========================

Running seemingly equivalent code in PHP (5.2.5)
===========================
<?php
error_reporting(E_ALL);
class person {
private $email = “private person email”;
protected $phone = “protected person phone”;
public $name = “public person name”;
public function showInfo() {
echo $this->email.” – “.$this->phone.” – “.$this->name.”\n”;
$this->onlyInUser();
}
}
class user extends person {
private $email = “private user email”;
protected $phone = “protected user phone”;
public $name = “public user name”;
public function onlyInUser() {
echo “I’m in the user class definition\n”;
}
public function showInfo() {
parent::showInfo();
echo $this->email.” – “.$this->phone.” – “.$this->name.”\n”;
}
}
$u = new user();
$u->showInfo();
===========================
I get the following output:

===========================
private person email – protected user phone – public user name
I’m in the user class definition
private user email – protected user phone – public user name
===========================

There’s clearly a difference here, and it’s likely related to an logical difference between super and parent.  My limited Java-fu and C#-fu being what they are, I’m not able to quite grok why there’s a difference in behaviour between the examples ago.

Hopefully this is humble enough to garner some collective wisdom.  I’m not bashing PHP here, nor anyone’s contributions or anything of the sort.  Simply asking – why are these behaving differently?

Groovy and Grails presentation at Lexis Nexis

March 14th, 2009

My friend Curtis Mitchell invited me to speak to some of the developers at Lexis Nexis about Groovy and Grails.  I was honored to speak, but also slightly nervous.  For some reason I’d got it in to my head that they were a Java development shop.  *Me* presenting to experienced Java developers makes me slightly nervous.  I don’t know all the terms or have the battle scars to relate to them.  I’ve not done EJB work, nor J2EE work (JEE now?), etc – so that was making me a bit nervous.

I got there a bit early, then realized I’d forgotten my stupid macbook vga adapter (one of the more acute drawbacks of having a macbook).  Then I realized they were mostly a .net shop, which made me even more nervous.  Why was I here?  How would I relate on a technical level?

I ended up using my slides for “Groovy/Grails for non-Java developers” which seemed to work out OK.  There were a few aspects of Groovy they seemed impressed with over C#.  At least one specific point I remember is the automatic private properties and automatically compiled get/set  methods – I think that appeared cleaner to some of the devs there. 

I got some good questions about some of the Java aspects, and just some of the dynamic aspects of Groovy.  Some of the devs seemed pretty up on dynamic language stuff in general, and talked of some of the stuff going on in the upcoming .net DLR.  I learned about extension methods in .net 3.5, which seem to be a similar way to modify existing classes (like adding new methods on to the sealed String class, for example).  Whether or not you can add stuff at runtime with extension methods, I dunno – forgot to ask.

All in all, after a few minutes I relaxed more.  I quickly changed my brain from thinking about Groovy/Grails specifically, to 1) talking more generally about dynamic languages (some slides had Ruby and PHP example code too) and 2) bashing Java the language for its verbosity relative to dynamic languages like Groovy.  Once I’d made the presentation more about “here’s what’s going on in Java re: dynamic languages”, it felt more comfortable to me, and hopefully to the audience.  I wasn’t there to get them to switch from .net (no good reason to do that!) but I think it gave some of them a fresh view of what’s going on in other camps, and also what dynamic languages bring to the table re: productivity.

Thanks Curtis and the L/N gang for your invitiation and hospitality (and cheap sodas!)  :)

Groovy and Grails training classes

February 5th, 2009

GroovyMag has recently announced Groovy and Grails training classes. These are web-based and able to be taken anywhere you’ve got a computer with Flash and an internet connection.

I’m excited about offering them, and working with Robert Fischer (of SmokeJumperIT) to finish putting together the course materials. He’s taught Groovy and Grails classroom-style before, as have I (well, PHP, not Groovy), but we’re working on reorganizing the material to work better over the web.

You can read more about the class offerings here, and read a bit more rambling about the training here.

If you’re interested in taking the class, or just have some questions about the training or Groovy in general, give me a call at 919-827-4724.

January GroovyMag out

January 4th, 2009

The January 2009 issue of GroovyMag is out. Grab it now!

This issue includes:

  • Community News from Dave Klein
  • Grails WebFlow walkthrough from Brian Doyle
  • Regular Expressions with Groovy from Ted Naleid
  • Feed Plugin overview – once again from Dave Klein!
  • Rich Swing Apps with Groovy from Andres Almiray
  • Interview with IBM’s Project Zero team
  • Excerpt from Grails In Action – Glen Smith and Peter Ledbrook

This issue clocks in at 40 pages, and is pretty content-rich, if I do say so myself.  Unlike many other tech magazines, we don’t rely on advertising.  Yeah, I know, you kinda like looking through ads sometimes.  Go to the web for about 9 seconds and get your fill, then come back to GroovyMag.

Honestly, it’s not like we have a strict ‘no ads’ policy – there’s one ad in the December and January issues each, and we might have another one in February.  However, the point of the magazine is content – stuff to help make you a better developer and expose you to new techniques.  Helping you find new writers that you haven’t heard of before is a nice side benefit of publishing Groovymag.

The first couple issues I was a bit embarrassed by having ‘only’ 33 or 36 pages.  And this issue, with 40 pages, still is small compared to many magazines you get on the newsstand.  But then I compared GroovyMag with an ASP magazine I picked up.  Cover price is $6.95 (IIRC) for 60+ pages, but 20 of them were ads.  Dollar for dollar, I think we’re delivering a pretty good value.  And apparently many of you do too, judging by the growing number of purchases between November, December and now January.

If you’ve purchased your January GroovyMag already – thank you!  If not, what are you waiting for?  Grab it now!

Are traditional object models enough? Can we evolve usefulness in OO models?

December 15th, 2008

Just a quick thought here after looking at someone’s code I just stumbled on. This person had a “isReadOnly()” method inside of a generic “set” method which would allow them to determine if a property should be allowed to be modified or not.

It got me to thinking again how the traditional notion of “visibility” in OO is, imo, broken. Perhaps that’s going a bit far. It doesn’t address the day to day needs most developers have. I’d say more developers need some sort of a way of making properties “read only” than they do dealing with “public, protected, private” PPP notions which we get in traditional OO implementations. What PPP gives is all-or-nothing – you get full access to this property (or method) or you don’t get any at all.

Short port (I gotta run) – why do we not have some sort of default “read only” property modifier in OO implementations? The Groovy approach would be to create a setXXX() method that was empty, effectively overriding the default setXXX() method to not perform any manipulation at all. It’s not *bad*, and is pretty clear, but some modifier like, oh, I dunno:

readonly String name

would be useful, no?

Did you get your GroovyMag yet?

December 4th, 2008

Yes, yes, a minor blatant plug for GroovyMag here :)

Current December issue has articles on building Swing apps with Groovy, developing iPhone-oriented apps with the iUI plugin, an article on GORM’s strengths, an interview with ContentSieve on their use of Groovy/Grails (their entire stack is now Grails-based), community news and an overview of the Testing plugin (to help with unit testing of controllers).

Upcoming issue topics include

  • more Swing apps with Groovy :)
  • using regular expressions with Groovy
  • Grails’ webflows tutorial
  • a preview of the upcoming Grails In Action book
  • a look at the feeds plugin
  • how to write a Grails plugin
  • community news
  • more interviews with real-life companies using Groovy and Grails in production settings
Other topics you’d like to see?  Definitely let me know!

If you haven’t picked up your copy yet, I’m interested in knowing why. Email mgkimsal@gmail.com, or post a comment here – either is fine. Is it just something that’s a bit too pricey for you right now? Do the topics not interest you enough? Are you on the fence about Groovy or Grails?

GroovyMag December 2008 is out

December 1st, 2008

The December 2008 GroovyMag is out now.  I could tell you all about the articles contained within – some meta-thoughts on GORM’s strategy, iUI iPhone development with Grails, Testing Plugin use, Rich Swing Apps with Groovy, and so on.  Or… you could just watch the video below before you go buy your copy.  :)


 

Switching Grails views

November 22nd, 2008

This is a repost from my post over at GroovyMag.

I’m planning to do this on a couple other projects, and thought I’d share this with you. It’s not specifically something related to GroovyMag magazine, but is a technique I’m using in a Grails project to make it easy to switch layouts based on the user.

All the default generated views use the meta tag ‘layout’ to point to a GSP file which will get merged with your view file (using sitemesh) to generate the final rendered HTML. Unfortunately these are always hardcoded to ‘main’ rather than a configurable option. So, I’ve taken to modifying the templates used during generation to point to a configuration value.

Run “grails install-templates” then look in src/templates/scaffolding. You’ll see the create/edit/list/show GSP files which are used as the basis for generation.

Edit the files such that the meta line

<meta name=”layout” content=”main” />

looks like this

<meta name=”layout” content=”\${session?.layout?:grailsApplication.config.sitemesh.layout}” />

(Note the Elvis :? operator above)

Then edit your grails-app/conf/Config.groovy file to have a line that reads

sitemesh.layout = “main”

If you then generate views for an app, everything will continue to work as it normally does by default; specifically, all the views will use the grails-app/views/layouts/main.gsp as a sitemesh wrapper for rendering.

However, you’re now able to set the layout to something different for each user by setting the session.layout value.

If a user has authenticated and is an administrator, perhaps you’d want to have

session.layout = “admin”

in a controller action, which would use the grails-app/views/layouts/admin.gsp file for rendering views for an admin.

If views for entire controllers require a different view, you should be able to set the global config value for all users by doing something like

grailsApplication.config.sitemesh.layout = “layout2″

in a controller action.