tracker issue : CF-4126544

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

Object Literal Syntax for Ordered/Sorted Structs

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Abram Adams / Abram Adams (Abram Adams)

Created: 03/09/2016

Components: Language

Versions: 2016

Failure Type: Unspecified

Found In Build/Fixed In Build: Alpha3_v12 /

Priority/Frequency: Normal / Unknown

Locale/System: English / Linux All

Vote Count: 1

Now that we have ordered/sorted structs structNew("sorted/ordered") we need to also have literal syntax support.  This was discussed in the PR forums, but no consensus was made on what the best syntax would be.  However, I don't think that the feature should ship without it as it makes it very cumbersome to use the feature and is a step backwards in language modernization.

Consider the following possible options (and please propose your own)

Maybe optional types (which would have other benefits)

Add optional type system (see also https://bugbase.adobe.com/index.cfm?event=bug&id=3687548):

SortedStruct s = {};

or annotations:

@Ordered
o = {};

@Sorted({ type: "asc" })
s = {}


s = @Sorted({ type: "asc" }) {}

or 

s = {} AS sorted;

or 
s = {}::sorted

or
s = sorted{}


There are obviously many other ways one could express this, and I'm not sure any of the above (besides the optional type system) would make sense when looking at other language implementations, but it's a starting point.  One should not have to revert back to 2005 and do:

<cfset departments=StructNew(“Ordered”)>
<cfset val=StructInsert(departments, "John", "Sales")>
<cfset val=StructInsert(departments, "Tom", "Finance")>
<cfset val=StructInsert(departments, "Mike", "Education")>

when we could instead have:

Ordered departments = { 
   "John": "Sales", 
   "Tom": "Finance", 
   "Mike": "Education" 
}


(BTW, what a terrible code example)

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

Watson Bug ID:	4126544

External Customer Info:
External Company: CFXchange.com
External Customer Name: Abram Adams
External Customer Email: AADAMS@CFXCHANGE.COM
External Test Config:

Attachments:

Comments:

Adding BUG AUDIT TRAIL ********action: updated fieldName: Priority newValue: 2 oldValue: 0 oprid: vmannebo recordName: RQ_DEFECT timpestamp: 2016-02-16 15:15:15.0 action: updated fieldName: Closed By newValue: suchsing oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: Date Closed newValue: 2015-12-04 00:28:49.0 oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: Reason newValue: Blank oldValue: Fixed oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: Status newValue: Fixed oldValue: ToTest oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: State newValue: Closed oldValue: Open oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: Owner newValue: Blank oldValue: suchsing oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-04 08:28:49.0 action: updated fieldName: Status newValue: ToTest oldValue: ToFix oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Fix By Product Milestone newValue: Beta oldValue: Beta2 oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Date Fixed newValue: 2015-12-02 01:27:09.0 oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Fixed By newValue: suchsing oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Owner newValue: suchsing oldValue: mchandna oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Reason newValue: Fixed oldValue: HaveNewInfo oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Fix By Milestone newValue: Beta oldValue: Beta2 oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 09:27:09.0 action: updated fieldName: Fix By Milestone newValue: Beta2 oldValue: Beta oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-12-02 07:38:50.0 action: updated fieldName: Fix By Product Milestone newValue: Beta2 oldValue: Beta oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-12-02 07:38:50.0 action: updated fieldName: Date Fixed newValue: null oldValue: 28-OCT-15 10.00.08.000000000 PM oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 07:04:02.0 action: updated fieldName: Fixed By newValue: Blank oldValue: mchandna oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 07:04:02.0 action: updated fieldName: Status newValue: ToFix oldValue: ToTest oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 07:04:02.0 action: updated fieldName: Reason newValue: HaveNewInfo oldValue: Fixed oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 07:04:02.0 action: updated fieldName: Owner newValue: mchandna oldValue: suchsing oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-12-02 07:04:02.0 action: updated fieldName: Date Fixed newValue: 2015-10-28 22:00:08.0 oldValue: Blank oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Changelist newValue: 296022 oldValue: Blank oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Reason newValue: Fixed oldValue: BugVerified oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Status newValue: ToTest oldValue: ToFix oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Branch newValue: Blank oldValue: Blank oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Owner newValue: suchsing oldValue: mchandna oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: updated fieldName: Fixed By newValue: mchandna oldValue: Blank oprid: mchandna recordName: RQ_DEFECT timpestamp: 2015-10-29 05:00:08.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-10-24 07:50:41.0 action: updated fieldName: Status newValue: ToFix oldValue: Unverified oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: Fix By Product Milestone newValue: Beta oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: QE Assigned newValue: suchsing oldValue: inoel oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: Reason newValue: BugVerified oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: Dev Assigned newValue: mchandna oldValue: awdhesh oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: Fix By Milestone newValue: Beta oldValue: Blank oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0 action: updated fieldName: Owner newValue: mchandna oldValue: inoel oprid: suchsing recordName: RQ_DEFECT timpestamp: 2015-10-23 08:31:46.0
Comment by CFwatson U.
3791 | March 09, 2016 02:32:03 AM GMT
+1 - I like this idea: s = sorted{}
Vote by External U.
3793 | March 09, 2016 02:32:05 AM GMT
Added By:mchandna Note Added: Supported inline Ordered Struct. Normally inline struct is written as: {a:'a',b='b'} and array is written as ['a','b'] Added support for inline ordered struct: [a:'a',b='b'] note that both colon and assign operators are supported. And empty ordered struct can be created in this manner: [:] OR [=] For sorted struct there is no inline syntax but an additional method has been added to convert any struct to sorted struct. StructGetSorted(anyStruct) // will return a new Sorted Struct converted from anyStruct. By default sorting order will be ascending strings StructGetSorted(anyStruct) // sorted struct in ascending order StructGetSorted(anyStruct, "asc") // sorted struct in ascending order StructGetSorted(anyStruct, "desc") // sorted struct in descending order StructGetSorted(anyStruct, UDF) // sorted struct, sorting based on udf passed We also supported member function for StructGetSorted, anyStruct.getSorted() // sorted struct in ascending order similarly all combinations will work in member function too Date Added :2015-10-29 05:00:09.0 Added By: PreRelease User User Name:Abram Adams Note Added: Entered Feature. Date Added :2015-10-22 23:16:29.0
Comment by CFwatson U.
3792 | March 09, 2016 02:32:06 AM GMT