Relative Content

Tag Archive for comparison

What do you call “X <= $foo <= Y" comparison?

While writing a Perl statement like if ( $foo >= X && $foo <= Y ) yet again, I wondered why many programming languages do not support the more comfortable form if ( X <= $foo <= Y ) and what this is called. I came up with “3-legged comparison” but no results when searching for it. By the way there is also the “element-of-set” form if ( $foo in X..Y ) which I only consider more readable when provided via a short keyword.

Scala as a language for Generic Programming

In the paper “An Extended Comparative Study of Language Support for Generic Programming” by Garcia et al. an interesting comparison of programming languages features for generic programming is given:

Best practice to sort then reverse, or write “backwards” comparator?

I wrote a comparator for a custom class of mine and when I ran my code I realised the output of my list of these objects was in the reverse order as to what I wanted. It was “ascending” as opposed to “descending”. This was because I stuck to the spec of compare where a return value of less than 0 means the other object is less than this and so on.