tracker issue : CF-4010512

select a category, or use search below
(searches all categories and all time range)

Three-way comparison operator ( <=> ) & Comparable interface

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 06/22/2015

Components: Language

Versions: 11.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: CF11_Final /

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 5


Also add a Comparable interface which CFCs can implement to allow objects to be compared.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4010512

External Customer Info:
External Company:  
External Customer Name: Adam
External Customer Email:  
External Test Config: My Hardware and Environment details:



As interesting a feature as this might be, I don't feel like we have any problems, and I don't think it makes code more readable. Terse does not equal simple.
Comment by External U.
7110 | June 29, 2015 08:11:33 AM GMT
if (e1 == e2) return 0; if (e1 > e2) return 1 return -1; Or... return e1 <=> e2; It's not a matter of being terse, it's a matter of being *concise* for a fair common operation when dealing with collections of objects which need to be sorted or otherwise compared. It's also far more clear in its intent than three separate if() statements (or whatever variation you decide might justify your comment). It does come into its own a bit when there's a Comparable interface one can implement on the objects too, that said. "not having problems" as a justification for not adding a feature is a bit facile too, don't you think?
Comment by External U.
7111 | June 29, 2015 08:17:03 AM GMT
so much typing saved and less mental compiling of cfif statements in your head
Vote by External U.
7115 | June 29, 2015 10:16:48 PM GMT
Vote by External U.
7116 | July 01, 2015 02:54:13 AM GMT
What types would it work with? Just numeric values? DateCompare does a similar thing. Should it work with dates too?
Comment by External U.
7112 | July 03, 2015 06:42:09 AM GMT
It should work with anything. It's the equivalent for compare() and dateCompare(), and fills that missing gap with numerics. If they also implemented a Comparable interface, one should then be able to use it with any object which implements Comparable. That's when the real benefit starts to come in.
Comment by External U.
7113 | July 03, 2015 06:46:47 AM GMT
This is a great suggestion. Within hours of reading this I have found I need it. It would be very helpful for implementing sorting algorithms over complex types. +1
Vote by External U.
7117 | July 03, 2015 09:40:35 AM GMT
+1 ......................
Vote by External U.
7118 | September 07, 2015 10:25:03 PM GMT
Can you please confirm in what version of ColdFusion this is going to be implemented in. It says "to fix" but does not say which version.
Comment by External U.
7114 | January 25, 2016 08:19:55 AM GMT
The operator is goofy IMO, but the idea that you might want to control how ColdFusion determines equality (or lack thereof) for your own components seems so fundamental that I'm blown away that anyone would push back on this. Java felt that was such an important thing that it put the equals and hashCode methods directly on Object, and the Comparable interface directly in the lang package. Java's not exactly a paragon of fine language design (doesn't have enough parenthesis for that =P) but I don't think this particular feature would be worth emulating.
Vote by Justin L.
31034 | July 16, 2019 04:33:54 PM GMT