Re: [groovy-user] Support for unless / if expressions
On Thu, 2008-09-04 at 21:20 -0400, Martin C. Martin wrote:
[ . . . ]
> def myFunMethod(int foo) {
> throw new RuntimeException("Arg must be positive") if (foo < 0)
> ...
I guess we could get into the linguistics etc. here -- I am sure that if
an experiment were done we would find that native English speakers and
native German speakers have different views on this due to the different
structures of sentence in their natural languages.
For me though this is a throw statement so I expect the result to be
throwing an exception. To find that the throws statement isn't actually
going to throw an exception, possibly most of the time, is a
comprehension problem for me. True, this is a personal thing, but
without doing an experiment, we are doing advocacy decision making based
on personal experience.
I agree that some functional programming languages, and indeed
mathematics, uses guards on the right in many contexts, however there is
a clear and obvious structure to when they are used. This Perl/Ruby
style condition on the right is actually a very different sort of thing
since it is not part of a bigger construct.
[ . . . ]
> Of course, it's possible to use this to write confusing code. Any
I guess this is where I lean towards Python and away from Perl and Ruby.
Perl especially, at least reputedly, has attempted to make it a benefit
of the language that for any algorithmic construct there are multiple,
preferably more, ways of expressing the same thing. Ruby, in trying to
be a better Perl, has gone the same route.
From the perspective of a C, C++, Fortran, Java, Python person, I prefer
my Groovy simple. True, I can avoid using constructs in my own code,
the issue is working with other people's code. Python often goes too
far in the simplicity stakes, indeed there are some decisions there I
disagree with -- cf. the conditional statement syntax which is ugly
because of the condition on the right ordering. However, I favour
Pythonic simplicity over Perlesque complexity.
--
--
Russel.
====================================================
Dr Russel Winder Partner
Concertant LLP t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road, f: +44 8700 516 084
London SW11 1EN, UK. m: +44 7770 465 077