Entries Tagged as 'Language enhancements'

Download the public beta of ColdFusion Splendor from here

I started a series of blog posts on language enhancements and covered "Script support for tags" last week. Continuing on this, today I am going to blog about "Member function" that I hope should interest most of you. Before I get into the details of member functions, here is the list of language features:   

  • Script support for tags
  • Member functions for CF data type/data structure
  • Improved JSON serialization
  • Easy to use CF functions for Query tag
  • Elvis operator (?:)
  • Promoting built-in CF function to first class 
  • Miscellaneous new functions: QueryGetRow, ListEach and others. 
ColdFusion predates object-oriented programming (OOPs) and hence did not have support for OOPs syntax. If you had to perform an action on an array, a struct or say on any other CF datatype, you had to call the headless functions like "ArrayAppend" or "StructFind" prior to Splendor. Now, with addition of "Member functions" support in Splendor, you can now enjoy writing your code in true object oriented-style and can call find() method on a struct object. For instance, empStruct.find("empID"). The code snippet shown below will help you visualize these two different coding styles:


Headless function

<cfscript>
     ArrayAppend(empArray, newObject);
     StructIsEmpty(empStruct);
</cfscript>

As member function of array/Struct

<cfscript> 
     empArray.append(newObject);
     empStruct.isEmpty();
</cfscript>

The Member function support in Splendor is quite exhaustive and covers most of the data types present in ColdFusion. The complete list of data types supported are:

  1. String
  2. List
  3. Array
  4. Struct
  5. Date
  6. Image
  7. Query
  8. SpreadSheet
  9. XML
Member function supported under each data type has been listed in ColdFusion Splender public beta documentation. Please see the documentation for more details.

Stay tuned for more on language enhancements in Splendor..  

Download the public beta of ColdFusion Splendor from here

Various enhancements have been added to the core CFML language to provide a better development experience. Script support for CF tags and member functions for CF data structure were long pending feature requests and we are happy to add these two along with a few more enhancements in ColdFusion Splendor (codename). The following list shows the enhancements made in the CFML language:

  • Script support for tags
  • Member functions for CF data type/data structure
  • Improved JSON serialization
  • Easy to use CF functions for Query tag
  • Elvis operator (?:)
  • Promoting built-in CF function to first class 
  • Miscellaneous new functions: QueryGetRow, ListEach and others. 
We will be doing a series of blog posts on language enhancements and this post will only be on the Script support for tags. 

Script support for tags
Traditionally, while coding in script syntax, you have to switch to tag-based syntax if you have to use CF tags. The reason being, the CF tags, barring few, were not available in the script syntax. ColdFusion Splendor onwards, most of the ColdFusion tags are made available to be used in the CFScript block. Now, you can  invoke most of the CF tags within the CFScript blocks. One more good thing about the current implementation is that it will automatically take care of any future tag being added to the CF language. 

Case 1: Simple tag with no child/body.

  <cfscript>
   cfpdf (action=”getInfo”,  name=”pdfVar”,  source=”CF10MigrationGuide.pdf”);
  </cfscript>  

Note: The tag attributes should be enclosed within the parenthesis and must be comma-separated.

Case 2: Tags with child tags/body.

  <cfscript>
    cfform (name='myForm', acton='')
    {
         cfgrid (name="myGrid", query='empQuery')
        {
             cfgridcolumn (name='firstName', id='firstName', type='string');
             cfgridcolumn (name='lastName', id='LastName', type='string');
        }  
    }
  </cfscript>  

Note: The child tag (and the body in general) should be enclosed in curly brackets, as a function block

Case 3: Custom tag

ColdFusion provides three different ways to write custom tags as shown in the following list:

  1. cfmodule based custom tags (supported in Splendor)
  2. cfm file based custom tags (supported in Splendor)
  3. Prefix based custom tags (not supported)
    // Tag based syntax
    <cf_happybirthday name="John" birthDate="December 5, 1987">
    
     //Script based syntax.
     <cfscript>     
         cf_happybirthday(name="John", birthDate="December 5, 1987");
     </cfscript>  

Stay tuned for more on the language enhancements. Please refer to the ColdFusion Splender public beta documentation for more details.