I've adopted the practice of using 'def' in writing Groovy class
code only when I intentionally want to use the dynamic features of
Groovy. When I know that a property is a certain type or that a
method returns a certain type or consumes arguments of certain
types, I always specify those types. In Enterprise coding, being
explicit with type is generally considered to be a best practice.
Of course, Groovy offers metaprogramming and idioms that are so
valuable that in some cases I loosen the static typing requirement.
For example, being able to call methods with named arguments and,
therefore, needing to have the first formal parameter of the method
be a Map is extremely useful. In this case, the method
implementation needs to take extra pains to do argument checking.
And, there are plenty of other dynamic features of Groovy that I
cautiously use.
I do worry about code being as strong as it can be, so I'm hoping to
hear any opinions as to best practices of using def as compared to
specifying types that tend to make code more industrial strength.
Thanks,
Steve Amerige
SAS Institute, Senior Software Developer