Friday 28 March 2014

Survey: lists in CFML, and the naming of list member functions

G'day:
There's a conversation brewing on the Railo Google Group regarding string / list member functions ("String member functions and list functions"), and this touches on ColdFusion's approach to these.

TL;DR: the survey is here: "List function support as member functions in CFML"

Update:

The survey is now closed. Results are here.


The question being asked on the Railo forum is whether to bother supporting list member functions in Railo at all. And as an aside to this, some lack of uniformity in how ColdFusion 11 has implemented these has cropped-up.

Firstly, I'll "go on record" as saying that I think having a specific concept as a "list" as a (pseudo) data type in CFML is a bit rubbish. Strings aren't intended for implementing data collections, and aren't very good at doing it, so - IMO - it was a poor idea to facilitate it. If Railo and ColdFusion deprecated the concept of lists entirely, the (CFML) world would be a better place.

That said, they are in the language as a concept, so we have to acknowledge this I guess.

Adobe have added list member functions to CFML in ColdFusion 11.  Here's a table of their implementation ("Supported List member functions"):

Supported List member functions

The following List member functions are supported:
ListAppendsomeVar.append()
ListChangeDelimssomeVar.changeDelims()
ListContainssomeVar.contains()
ListContainsNoCasesomeVar.containsNoCase()
ListDeleteAtsomeVar.deleteAt()
ListFindsomeVar.ListFind ()
ListFindNoCasesomeVar.ListFindNoCase()
ListFirstsomeVar.first()
ListGetAtsomeVar.getAt()
ListInsertAtsomeVar.InsertAt()
ListLastsomeVar.last()
ListLensomeVar.listLen()
ListPrependsomeVar.prepend()
ListQualifysomeVar.qualify
ListRestsomeVar.rest()
ListSetAtsomeVar.setAt()
ListSortsomeVar.sort()
ListToArraysomeVar.toArray()
ListValueCountsomeVar.valueCount()
ListValueCountNoCasesomeVar.valueCountNoCase()
ReplaceListsomeVar.replace()

I've highlighted where I think they've got this wrong, and where they've got it right. And where I dunno how it's supposed to work, as there's already a differently-functioning function of that name already.

The problem here is that these are all string member functions (ie: you call them on a string object), and the fact they're actually designed to work on a special sort of string is lost in the current function naming. eg: what does a rest() function do in the context of a string? It makes no sense. prepend() is understandable (one can prepend to a string), but when one sees that one's string has been prepended with the substring specified, and a comma, it stops making sense. The function names have to "work" in the context they are being called. They should not require special knowledge that they are "list" functions. This should be reflected in the name of the function.

I've also created a survey to get your thoughts on the matter: "List function support as member functions in CFML". Please go and put your oar in.

--
Adam