tags:

views:

36

answers:

2

I remember from my Perl days the "use strict" statement that cause the runtime to do extra validations. Is there an equivalent for Groovy?

I do not enjoy being bitten during runtime by what can be detected on compilation, like passing too few arguments to a constructor.

+2  A: 

Is there an equivalent for Groovy?

Not that I know of.

I do not enjoy being bitten during runtime by what can be detected on compilation, like passing too few arguments to a constructor.

Then Groovy is probably the wrong language for you and you should use something like Java or C# instead. Alternatively, there is a version of Groovy, known as Groovy++ which has much stronger type-checking, but I don't consider it sufficiently mature for production use.

IntelliJ (and possibly other IDEs) provides a lot of warnings about dodgy Groovy code. Although these warnings don't prevent compilation, they almost give you the best of both worlds, i.e. the safety of a static language and the flexibility of a dynamic language

Don
What you say might be true, but it doesn't have to be. Such a flag could be implemented that improves the robustness for users that need it, while keeping the dynamic nature for those that do not.
ripper234
@ripper234: static typic vs. dynamic+metaprogramming are radically different approaches to language design. Supporting both at the same time would require a lot of effort and tadeoffs, and you'd probably end up aggravating both groups of users. But again: using Java is basically the same thing as your hypothetical "strict" flag for Groovy.
Michael Borgwardt
+2  A: 

No, there is no such thing, and there can't be. Perl's "use strict" only prevents the use of undeclared variables (and some very Perl-specific things that I don't think have equivalents in Groovy).

In dynamic languages like Groovy, "passing too few arguments to a constructor" is fundamentally not something the compiler can detect, because class definitions can be changed at runtime via metaprogramming. Also, you usually don't have the type information necessary to know what class to look at.

If you want maximum compile-time checks, use a statically typed language with no metaprogramming, i.e. Java.

Michael Borgwardt
An alternative to Java or C# would be Scala which allows you to be more expressive while still getting you the compile-time checks and whatnot.
xlson