Draft proposal: allow the use of relational operators on Comparable classes

Marek Kozieł develop4lasu at gmail.com
Wed Mar 18 04:05:41 PDT 2009


2009/3/10 Vilya Harvey <vilya.harvey at gmail.com>

> I've attached a draft of a proposal to allow classes which implement the
> Comparable interface to be used as operands for the relational operators.
> So
> for example if you had two Strings, a and b, you would be able to write
>
> if (a < b) {
>    ...
> }
>
> instead of
>
> if (a.compareTo(b) < 0) {
>    ...
> }
>
> and you could do the same with your own classes as well.
>
> Thanks in advance for any feedback,
>
> Vil.
>
>
>
> I'm against.

Normally I use up to 4 kinds of comparators for each object. This solution
is not able to handle this.

I would suggest:

< operation :: (operator) > :: blockWhereOperatorWork

< operation :: (operator) > :: ; // work to end of this block

usage:

value|variable (operator) value|variable


Sample (short):
< comparator.compare(A,B) :: A(>)B >::{

   if (someA (>) someB) {...}

   ...

}




< A.compareTo(B) :: A(>)B >::{

   if (someA (>) someB) {...}

   else if (someC (>) someD)...

}

-- 
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł

http://lasu2string.blogspot.com/



More information about the coin-dev mailing list