Luke Daley: Groovy TextMate and more
Luke Daley: Groovy TextMate and more
Join the DZone community and get the full member experience.Join For Free
How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.
[img_assist|nid=943|title=|desc=|link=none|align=right|width=90|height=90]Luke Daley is a newcomer to the world of Java, thanks to Groovy, and
the maintainer of the Groovy and Grails bundles for TextMate (a
popular text editor for Mac OS X). Learn more about the Groovy/Grails on TextMate, Luke's thoughts on Groovy and his own groovy projects. Enjoy.
Q: Luke, you are the current maintainer of the Groovy/Grails TextMate bundles, what can you tell us about them?
A: Both of the bundles were created by Graeme Rocher (of Grails fame) and are more or less forks of the Ruby and Rails bundles. I had been using TextMate for quite a while so when I started using Groovy and Grails I naturally wanted to use TextMate for that too. I more or less use TextMate for everything.
Graeme did a good job on the bundles, but he is obviously a busy guy so I offered to take over the bundles which he was happy with. One of the first things I did was to add 'GrailsMate' to the Grails bundle which allows you to run grails commands from inside TM, which is a huge timesaver. Another neat feature is the smart navigation within a grails project. You can very quickly and easily move around between related files. For example, navigating from a domain class, to the relevant controller, to the view, all with a few keystrokes.
Both bundles feature a plethora of snippets which make writing Groovy and Grails code a lot faster once you get to know them. To me, snippets are the real power in TextMate. The ability to replace a commonly typed piece of code with a succinct shortcut and have it be flexible enough to use in different contexts makes working in TextMate so productive. There are lots of other great features but this is the one I rely on the most.
The bundles are constantly evolving. I am continually refining the language grammars and adding features. So if you use the bundles be sure to watch the Groovy and Grails bundle rss feeds. Also, if you have any feature requests be sure to let me know through the TextMate mailing list or IRC room.
Q: Your site shows you have other Groovy related projects, what can you tell us about Injecto ?
A: Injecto was born out of the need to package bits of functionality to be added to classes at runtime, using Groovy's meta class system. In essence, it is trying to simulate Ruby mixins. It works by introspecting a given 'injecto' class and attaching the gettable properties to a target 'injectee' class through the ExpandoMetaClass feature. To add methods you simply define closure properties on the injecto. It also takes care of adding instance variables which can be a little tricky with EMC.
Another handy feature is the dynamic method dispatch. On the injecto class, you can annotate a closure (which acts like a method once injected) with a regex pattern that is used to try and dispatch methods that don't exist. This would allow you to easily implement something like dynamic finders in Grails' GORM for example.
I wrote Injecto to solve the problem of packaging dynamic functionality for my other project, Gldapo.
Q: What is the deal with Gldapo ?
A: Gldapo Gldapo is an attempt to take the pain out of LDAP programming on the Java platform. I come from more of a PHP/Perl background where both languages have reasonably well developed and easy to use LDAP toolkits. When I started to move in to the Java space I couldn't deal with JNDI for LDAP programming, it's just too difficult to do even the simplest things. I spend a lot of my time writing scripts to interface with directories and more and more I was needing to integrate with existing Java software as well. I was very much inspired by Grails and how easy GORM is to use, so I tried to bring that idea to the world of LDAP.
The premise behind Gldapo is "LDAP entries as Groovy objects". It should be possible to be very productive using Gldapo without having to know the particulars of LDAP programming because you just interact with plain Groovy objects and have the LDAP stuff taken care of for you. So far it's going well. I am about to release 0.5 which will add support for writing back to the directory (the current version only supports read). My goal is to have the easiest to use LDAP toolkit out there. Gldapo sits atop of Spring LDAP which takes care of the heavy lifting, I merely provide the object layer.
There is also a plugin available for Grails with integrates Gldapo into your Grails apps.
Q: So you have played with Grails, how has been the experience so far ?
A: In a word; liberating. My first web based apps where written in PHP, which I still like (you can't beat the simplicity of it), but only for apps up to a certain size. After writing my first decent sized PHP app it became painfully evident that I needed something with more structure and that gave me more for nothing so to speak. Sure there are PHP frameworks out there, but I was starting to hear a lot of noise about Rails and started looking in to that. The chances of getting support for Rails at my workplace were a little slim though. After a while spent looking at Rails I took a chance and asked Google if it knew anything about "java rails" and it responded with Grails. It made sense immediately. As a Sys Admin, I tend to write software that integrates functions of our enterprise. Grails is absolutely perfect for this as it lets me focus on the actual work at hand without burdening me with an overly complex API.
The integrated testing is another *big* feature for me. Our apps tend to be very fluid, so good testing is essential to stop regressions. My experience is that the easier you make code to test, the more it gets tested. Testing has got to be baked in for me.
To be fair though I haven't used any other Java web frameworks, which I am eternally grateful for. I have looked at a few but I just couldn't see myself using them. All the ones I looked at seemed way too complex and required so much plumbing to get up and running.
Q: So how did you get into Groovy ?
A: I was more or less being forced into using Java at work because of some recent technology purchases. I had never been big on Java. I was very envious of the wealth of libraries around and the fundamental virtual machine concept, but by and large I wasn't much of a fan. I had heard about things like JRuby and Jython so I was looking around for an alternative language for the JVM. I stumbled across Groovy, downloaded it, did a few tests by rewriting some Java and was immediately hooked.
Q: Is there anything on those languages (PHP/Perl) that you wish was available in Groovy ?
A: Groovy is lacking a CPAN or PEAR like package management system. I know this is being actively worked on by Danno Ferrin as 'Grape' and I am really looking forward to this. From what I have seen so far Danno has been doing some pretty amazing work.
The other thing that is missing is an easily searchable documentation base. PHP excels at this. Groovydoc still needed quite a bit of work last time I used it as well, though I don't use it anymore as the recent versions of the Groovy plugin for Maven generates Java stubs from your Groovy code which includes your documentation. Generating first class Javadoc for your Groovy code base is pretty cool.
Even though it would make some of my work redundant, I would desperately like to see first class support for mixins in Groovy. I am sure that it will happen eventually.
Q: Do you use groovy in your daily work ?
A: I am trying to more and more. I work as a Systems Administrator (though I have more of a developer background) and primarily focus on Identity Management and general automation. Where traditionally we have reached for Perl, I am now advocating Groovy. A lot of the good products/tools in the Identity Management space right now are very much Java based and Groovy allows us to leverage these tools without having to use Java. We are also starting to benefit from being able to use one of my favourite Java products, Maven.
I see Groovy as the perfect "glue" language for the enterprise. It's a perfect fit for me as I can write succinct, easy to read scripts that other sys admins who are slightly less programming savvy can maintain, all while leveraging the best Java has to offer.
Q: What techniques do you use to make your scripts easily understandable to your less programming savvy peers?
A: I place a huge emphasis on code readability and Groovy naturally supports easy to understand code. Things like builders, operator overloading and closures for example let you focus on just the 'what', not the 'how'.
Duck typing let's you avoid having to jump through type casting hoops which is helpful here. Anyone reading one of my scripts needs to extract a decent understanding of what it is doing very quickly and one of my grievances with Java is that the typing noise can obscure the purpose of the code sometimes. Conversely though, I really appreciate having the ability to enforce typing where it is appropriate which is something I miss when going back to Perl.
I also find that in certain situations you make an API a lot more concise by taking advantage of Groovy's shorthand map syntax to simulate named parameters. If you do it right you can express a lot more immediate meaning in your code.
Q: Do you use an IDE or groovy tools other than TextMate ?
A: Not at the moment. I tend not to work on huge code bases so the lack of an integrated debugger/profiler doesn't inhibit me. I have tried a couple of the big Java IDE's but I always go back to TextMate. I want an editor that I can use for everything. TextMate covers me for programming, editing config files, writing blog entries and much more (including writing this). The extensibility of it really allows me to get it to do whatever I want it to do.
Q: Does that include documentation too ? What do you use as resources for your Groovy needs ?
A: Yeah absolutely.
I use Maven for all of my projects so I try to cover all the documentation bases through good Javadoc and a Maven generated site. Having the documentation right there in my project along with the source makes it that much easier for me to manage it and keep it up to date. I use the APT markup format to write the site content, so I created a TextMate bundle for APT which I plan to make available soon. I am also about to make a Maven bundle available that lets you invoke Maven from within TextMate.
Development in TextMate feels very streamlined and productive to me. I would love to see more people using TextMate for Groovy/Grails/Java as I think it really has a lot to offer and it would also bring some new ideas for the bundles that I would be happy to implement.
Thanks for the interview Luke!
Opinions expressed by DZone contributors are their own.