Blog

1May
2007
ColdFusion And JavaScript Like Operators

This one was met with a round of applause last night in Dallas. In Scorpio you can now use the following in CFML expressions:

view plain print about
1++ -- % += -= *= /= %= && || !

In addition, in <CFSCRIPT> you can use the following operators:

view plain print about
1== != < <= > >=

Related Blog Entries

Comments (19)



  • Steven Van Gemert

    I may have clapped the loudest for this, lol. Love the idea, finally a ++, and a % for CF!

    And bravo for figuring out the validation nightmare that must have been "if(a<b) || (a>c)". It sure looks like it should validate as a tag, but grats for figuring it out and including it! Well done!

    Do we call it CF++ now? :)

  • Thomas Rühl

    Yay, finally! Good one :)

    Ben, say are there by any chance plans to give developers the oppertunity to write cfc's *completely* on a script basis, too? Like defining a component with a class (~component) keyword rather than using the tag syntay? Also, will there be mechanisms like interfaces or abstract classes in CF++? ;)

    Cheers, Thomas

  • Ben Forta

    Give them an inch and they want a mile. ;-)

    Thomas, interfaces are in Scorpio, but no plans for for class creation in script. And, without starting a big debate on the subject, I would be very opposed to this idea myself. If you want components defined as classes, well, use Java, it does it really well. But, ya never know.

    --- Ben

    #3Posted by Ben Forta | May 1, 2007, 10:31 AM
  • KEVIN BENORE

    Great to have you in DFW! A question came to mind about the CFIMAGE tag. Currently we have an image server which we use some of the same functionality you talked about with CFIMAGE. Will there be any caching available of images (or is that me just dreaming to big)? Can you manipulate the DPI? We keep hi-res JPEGs (300 dpi) for print and then our image server renders them as 72 dpi for display.

    I am so very, very excited and can't wait for the release of CF8. Thanks for your wonderful presentation last night!

  • Kevin

    That is awesome, I'm very excited about the new operators. I have a question though. I've been told IIF is very slow. Is the following going to work?

    a = (b == true) ? c : d;

    #5Posted by Kevin | May 1, 2007, 10:51 AM
  • Steven Van Gemert

    Ben said:

    Give them an inch and they want a mile.

    True Ben, but please realize that we're REALLY grateful for the inch! :)

    Steven

  • Thomas Rühl

    Steven said:
    True Ben, but please realize that we're REALLY grateful for the inch! :)

    hell, we are :D
    Cheers, Thomas

  • Ben Nadel

    ++

    That is sweeeet! I feel like giving you my first born :D

    #8Posted by Ben Nadel | May 1, 2007, 12:34 PM
  • hibiscusroto

    that's pretty cool!

  • Joshua Curtiss

    This is AWESOME!!! It is so irritating not having the incremental operators. That will be awesome. It only makes sense, getting closer to ECMAScript.

    Now, to go for the mile.. ;-) I agree with Kevin that it would be awesome to have support for ? as in:
    a = (b == true) ? c : d;

  • Michael Dinowitz

    IIF() was slower than CFIF in earlier versions of ColdFusion but in MX they compile down to the exact same code.

  • Steven Ross

    a = (b == true) ? c : d; is called a ternary operator. ;)

  • Rick Root

    pretty awesome Ben!

    I hate doing

    <cfset foo = foo + 1>

    Now I can do

    <cfset foo++>

    Now if you can add a &= operator.

    <cfset foo = foo & "some string">

    becomes

    <cfset foo &= "some string">

    #13Posted by Rick Root | May 1, 2007, 03:19 PM
  • Matt Williams

    Rick,
    I'm willing to be that with CF being dynamic and all that this will work for you:
    <cfset foo += "some string" />

  • shuns

    Finnnnnnnnnnnally! This is a feature that has been missing for a long time. ;)

    #15Posted by shuns | May 2, 2007, 12:19 AM
  • Chris Phillips

    Rick,
    Not sure why, it's not in the list.
    But, you can do &= for string concatination.
    (The tour just came through PDX on Monday).
    Awsome stuff.
    I'm excited to be a CF developer.

  • Ben Forta

    >> Can you manipulate the DPI? We keep hi-res JPEGs (300 dpi)
    >>for print and then our image server renders them as 72 dpi for display.

    Kevin, no, this is not supported at this time.

    --- Ben

    #17Posted by Ben Forta | May 2, 2007, 06:19 PM
  • Dustin

    One thing I've missed is the ability to effectively loop a query in script. Something like this would be awesome:

    forin(query||struct[,item]){}

    #18Posted by Dustin | May 8, 2007, 01:51 PM
  • sal

    sooo! wicked! definitely past due

    #19Posted by sal | Jun 6, 2007, 12:06 AM