Luke Daley | 6 Sep 11:48

[groovy-user] Support for 'unless'

The previous thread about unless was a bit complex as it combined the  
concept of 'unless' and having conditions after statements. I am bit  
worried that 'unless' by itself got a bit lost in that.

The consensus seemed to me to be that almost everyone who had used  
'unless', sees it's value.

To be clear,

unless (condition) {
	// stuff
} else unless (otherCondition) {
	// other stuff
}

which is equivalent to…

if (!condition) {
	// stuff
} else if (!otherCondition) {
	// other stuff
}

I didn't see the point of unless until it was available to me, now I  
am a big fan. It seemed very foreign to me when I started using perl  
and ruby and at that point I did question it's usefulness. Now though,  
it seems such an obvious win to aid readability.

Just wanted to get some people's opinions on this (and only this).

(Continue reading)

Alexander Veit | 6 Sep 23:29
Picon
Favicon

Re: [groovy-user] Support for 'unless'

> Luke Daley wrote:
> [...]
> To be clear,
> 
> unless (condition) {
> 	// stuff
> } else unless (otherCondition) {
> 	// other stuff
> }
> 
> which is equivalent to.
> 
> if (!condition) {
> 	// stuff
> } else if (!otherCondition) {
> 	// other stuff
> }
>
>  [...]
>
> Just wanted to get some people's opinions on this (and only this).

A prefix 'unless' would fit into the current Groovy grammar without
problems, I think.

--

-- 
Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:
(Continue reading)

Jochen Theodorou | 7 Sep 00:02
Picon

Re: [groovy-user] Support for 'unless'

Alexander Veit schrieb:
>> Luke Daley wrote:
>> [...]
>> To be clear,
>>
>> unless (condition) {
>> 	// stuff
>> } else unless (otherCondition) {
>> 	// other stuff
>> }
>>
>> which is equivalent to.
>>
>> if (!condition) {
>> 	// stuff
>> } else if (!otherCondition) {
>> 	// other stuff
>> }
>>
>>  [...]
>>
>> Just wanted to get some people's opinions on this (and only this).
> 
> A prefix 'unless' would fit into the current Groovy grammar without
> problems, I think.

it is a new keyword ("if not" would go without additional keyword), but 
it fits in the grammar pretty easily, yes.

bye blackdrag
(Continue reading)

Mingfai | 7 Sep 07:45
Picon

Re: [groovy-user] Support for 'unless'

It's not 100% relevant to the if and unless discussion. 

I'd like to see a widen usage of "not". 

if ( a not instanceof BigDecimal && b not in [1,2,3]) {
  // do sth
}

or 

if ( a !instanceof BigDecimal && b !in [1,2,3]) {
  // do sth
}

to an extent, "unless" or "if not" is for simplifying the code so we don't need !(). And such simplification is useful for every boolean expression. My view is, the code will be much cleaner and easy to understanding without the clumsy !(). In SQL grammer, it has usage like NOT LIKE or IS NOT NULL.

what do you think?

regards,
mingfai

also refer to an email about syntax improvement in Apr:


On Sun, Sep 7, 2008 at 6:02 AM, Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org> wrote:
Alexander Veit schrieb:

Luke Daley wrote:
[...]
To be clear,

unless (condition) {
       // stuff
} else unless (otherCondition) {
       // other stuff
}

which is equivalent to.

if (!condition) {
       // stuff
} else if (!otherCondition) {
       // other stuff
}

 [...]

Just wanted to get some people's opinions on this (and only this).

A prefix 'unless' would fit into the current Groovy grammar without
problems, I think.

it is a new keyword ("if not" would go without additional keyword), but it fits in the grammar pretty easily, yes.

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



Alexander Veit | 7 Sep 14:37
Picon
Favicon

RE: [groovy-user] Support for 'unless'

> Mingfai wrote:
> 
> It's not 100% relevant to the if and unless discussion. 
> 
> I'd like to see a widen usage of "not". 
> 
> if ( a not instanceof BigDecimal && b not in [1,2,3]) {
>   // do sth
> }
> 
> or 
> 
> if ( a !instanceof BigDecimal && b !in [1,2,3]) {
>   // do sth
> }
> 
> to an extent, "unless" or "if not" is for simplifying the 
> code so we don't need !(). And such simplification is useful 
> for every boolean expression. My view is, the code will be 
> much cleaner and easy to understanding without the clumsy 
> !(). In SQL grammer, it has usage like NOT LIKE or IS NOT NULL.
> 
> what do you think?

I'm a friend of Ockham's razor and of simplicity, and so I dislike it.

If (!instanceof T) was introduced here, it would be either a unary operator
or an extension of the instanceof keyword to form the new keyword
!instanceof. In the first case it would break the current groovy grammar and
make it much more complex. In the latter case it would introduce new
keywords without need, imo.

If (not instanceof T) was introduced it would be either a unary operator or
an extension of the instanceof keyword to form the new keyword 'not
instanceof'. Then the same holds as above. Moreover, if 'not' was introduced
as a new operator (as a synonym for !) then 'and' and 'or' should naturally
be there as synonyms for && and ||. Besides Ockham's argument there is
Charlie's argument from a previous post that states that using 'not', 'and'
and 'or' is widely discouraged even in Ruby. The reason for this is quite
clear to me: code can become quickly obfuscated if a language has too many
synonyms, especially when teams of developers work at the same code.

--

-- 
Alex

"Experience with many protocols has shown that protocols with few options
tend towards ubiquity, whereas protocols with many options tend towards
obscurity."
RFC2821

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Ladislav Thon | 8 Sep 08:40
Picon

Re: [groovy-user] Support for 'unless'

I'm a friend of Ockham's razor and of simplicity, and so I dislike it.

For sake of simplicity, I propose to remove all number comparison operators but <, because with standard logical operators and number multiplication by -1, you can do all your comparisons with <.

Sure as hell, this is argumentation by reductio ad absurdum and I'm not serious in here. But again, I believe that these "negated" operators (not in, namely) would be great for DSLs, as they resemble natural language.

LT
Ladislav Thon | 7 Sep 22:49
Picon

Re: [groovy-user] Support for 'unless'

if ( a not instanceof BigDecimal && b not in [1,2,3]) {
  // do sth
}

My wet dreams comming real! Yes, this is precisely the thing I always wanted since I first poked with "instanceof" operator. Or with "in" operator back in the days of Object Pascal... And now I see Groovy has "in" too. Always learning.

LT
hartsock | 10 Sep 15:35
Picon

Re: [groovy-user] Support for 'unless'


Actually, my feeling on this is that you need to support post-conditionals
_first_ before you consider supporting "unless" because the most compelling
syntax for an "unless" is...

changing...

foo() if !bar

... into ...

foo() unless bar

... my favorite use if post-conditional and unless in combination is in a
return short-circuit like this...

def fred() {
  // ... stuff ...
  return barney unless something
  return wilma
}

IF you don't have that. Don't bother with unless. Really. Without that it's
syntax noise.

Luke Daley wrote:
> 
> The previous thread about unless was a bit complex as it combined the  
> concept of 'unless' and having conditions after statements. I am bit  
> worried that 'unless' by itself got a bit lost in that.
> 
> The consensus seemed to me to be that almost everyone who had used  
> 'unless', sees it's value.
> 
> To be clear,
> 
> unless (condition) {
> 	// stuff
> } else unless (otherCondition) {
> 	// other stuff
> }
> 
> which is equivalent to…
> 
> if (!condition) {
> 	// stuff
> } else if (!otherCondition) {
> 	// other stuff
> }
> 
> I didn't see the point of unless until it was available to me, now I  
> am a big fan. It seemed very foreign to me when I started using perl  
> and ruby and at that point I did question it's usefulness. Now though,  
> it seems such an obvious win to aid readability.
> 
> Just wanted to get some people's opinions on this (and only this).
> 
> --
> 
> LD.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 
> 
> 

--

-- 
View this message in context: http://www.nabble.com/Support-for-%27unless%27-tp19344900p19413748.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane