Debugging a Grails app with a text editor

428 views
Skip to first unread message

olivierntk

unread,
Apr 23, 2012, 12:16:45 PM4/23/12
to Grails User Group
Hi all,

I just got started with Grails a week ago for a project at work. So
far so good. One thing I could not find out is: is it possible to
debug a Grails app with Sublime Text 2 or Textmate? I see a lot more
videos of Grails 2 where the presenter would use the console and a
text editor. Is it the workflow for Grails 2.X or is it more common to
use STS?

My preference is to use a text editor and the console so I'd greatly
appreciate any pointers here.

Thanks a lot.

-Olivier

t.dave

unread,
Apr 26, 2012, 6:03:44 PM4/26/12
to Grails User Group
hi olivier, welcome to grails. i wrote a longer and nicer response
earlier today which google groups claimed to have posted but it never
appeared so trying again, in a probably more terse version. :)

i've used sublime text 2 for probably 6 months to code grails and
don't have any plans to return to an IDE. for ST2 i'd recommend using
the 4 panel grid layout - being able to see domains/controllers/
services/views/templates/taglibs/javascript/src files/etc (pick 4)
simultaneously is a huge productivity boost.

but, i still use STS for the very occasional step debug and the pretty
often SVN merge to trunk. i don't believe there's any way to debug
directly from a text editor.

that being said, my development approach has become such that i almost
never step debug. my primary suggestion for this is to install the
"console" plugin, which will let you run a grails console in a
separate tab in your web browser, and be able to execute snippets of
groovy code (good for figuring out how to chain collection methods
together, etc) as well as access to your domain objects (good for
figuring out how to navigate your various object relationships and see
what your domain methods are returning, etc) all while your
application is running.

TDD will help and you'll get the benefit of having tests around for
the future. and finally, littering println's throughout your code is
not recommended but may happen. :)

hope that helps! but let me know if you have any more questions, and
apologies that my more in-depth response disappeared.

dave

t.dave

unread,
Apr 26, 2012, 12:52:55 PM4/26/12
to Grails User Group
olivier -

welcome to grails. i originally started developing using STS and
eventually got fed up that i wasn't getting the benefits of the IDE
(method completion, correct syntax highlighting, etc) but still
getting all the drawbacks (slow, memory hungry, etc). they may have
made great strides in their ability to handle groovy's dynamic nature,
and i hear intellij is very good, but i've been using sublime text 2
(ST2) with the console for about a year and have no plans to go back.

my suggestion would be to try the 4 window grid mode in ST2. i find
that being able to see my views/templates/services/controllers/domains/
taglibs/src files/etc (pick any 4) simultaneously has made a huge
benefit in productivity. instead of having to flip back and forth -
what did i name that variable? - i can see it all at once.

but, you asked about debugging. i do still rely on STS for debugging
and SVN merging between branches. however, i've found that as i get
more comfortable/experienced with grails i almost never use STS for
debugging. (on a side note, if STS tells you that your project isn't
compiling you can often ignore it and it will run and step debug just
fine.) :)

i'd recommend installing the "console" plugin. that will give you the
benefit of a grails console in a separate tab in your web browser, so
you can easily run your app and test small bits of code at the same
time. i've found that works as a bit of on-the-fly TDD to figure out
any interesting or algorithmic bits of code before trying them in the
broader application context. as well, playing with groovy datatypes
and collection methods is way faster there, and easier to see what
works and what doesn't. for instance, yesterday i came up with this
in a taglib:

if ( value instanceof String[] )
out << value.flatten().sort().join("...")
else if ( value instanceof Map )
out << value.entrySet().sort { it.key }.flatten().join("...")

close, but subtly different. and much easier to get it right when i
don't have to click through multiple screens in the app to get to
where i want only to see a stacktrace in the console.

one other thing that will probably happen using the console, which i'm
not a fan of but find myself occasionally doing anyway, is littering
println's throughout your code. blech. but it does the job. :)

finally, straight up TDD will also work, and then your tests will
stick around for future benefit.

hope that helps!

dave



On Apr 23, 9:16 am, olivierntk <olivier...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages