[thelist] CFswitch doesn't.

Jeff Howden jeff at jeffhowden.com
Fri Aug 12 20:01:57 CDT 2005


Frank,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Frank [mailto:lists at frankmarion.com] 
> 
> > Cases in a <cfswitch> block have an implicit break,
> > making them exclusive whereas cases within a switch
> > in a <cfscript> block must have an explicit break
> > added.
> 
> Well isn't that a frustrating inconsistency within cf.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Perhaps, but based on the evolution of the language, I suspect that little
detail was much less of a frustration than the alternative.

The <cfswitch>/<cfcase>/<cfdefaultcase> tags were added to the language as
of version 4.  There wasn't a <cfscript> block at that time, let alone a
switch() statement supported in cfscript.  Since one of the primary missions
of ColdFusion is to be as easy as possible for people to pick up, it made
sense to make <cfcase> blocks break implicitly.  Combined with the ability
to pass a list in the "value" attribute of the <cfcase> tag, it was a
small-footprint weapon against the <cfif>/<cfelseif>/<cfelse> combination
with no "gotchas" (like having to explicitly break) for new developers.

Then, along came the addition of the switch() statement to cfscript.  As
cfscript is generally used by more experienced developers, there's no way to
specify list delimiters in a case statement in a cfscript block, and for
other reasons we'll probably never know, they probably decided to follow the
standards other languages employ when it comes to multiple case statements
and explicit breaks, rather than passing a list of values.  For example, the
following:

<cfswitch expression="#foo#">
<cfcase value="boo,bar">
  do something
</cfcase>
</cfswitch>

Would become:

<cfscript>
  switch(foo)
  {
    case 'boo':
    case 'bar':
    {
      // do something
      break;
    }
  }
</cfscript>

Instead of:

<cfscript>
  switch(foo)
  {
    case 'boo,bar':
    {
      // do something
      break;
    }
  }
</cfscript>

Is it all starting to make alittle more sense?

 [>] Jeff Howden
     jeff at jeffhowden.com
     http://jeffhowden.com/



More information about the thelist mailing list