The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

yes no enums and goto's

Last post 02-15-2007 6:13 PM by Kyanar. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 02-13-2007 1:16 PM

    yes no enums and goto's

    I love working with Yes No enums...then tie that in with goto's and life is good.  Did I mention this is from a top 30 internet site.  I guess bool's just wouldn't work.

     switch(searchResultsAvailable)
    {
        case SearchResultsAvailable.yes:
           title = "Featured Products";
           break;
        
    case SearchResultsAvailable.no:
           title = "Top Sellers";
           
    break;
        
    default:
           
    goto case SearchResultsAvailable.no;
    }

     

    itsyourcoworker.com - the place to call out the idiots in the workplace
  • 02-13-2007 1:32 PM In reply to

    Re: yes no enums and goto's

    dumbphux:

    I love working with Yes No enums...then tie that in with goto's and life is good.  Did I mention this is from a top 30 internet site.  I guess bool's just wouldn't work.

     switch(searchResultsAvailable)
    {
        case SearchResultsAvailable.yes:
           title = "Featured Products";
           break;
        
    case SearchResultsAvailable.no:
           title = "Top Sellers";
           
    break;
        
    default:
           
    goto case SearchResultsAvailable.no;
    }

    Hmmm, that worked well....

    For when:

    switch (theEnum) {
      case theEnum.yes: { ...; break; }
      case theEnum.no:
      case default: { 
           ...; 
           break; 
      }
    }
    

    ... simply won't do!

    If you must burn our flag, please wrap yourself in it first!
  • 02-13-2007 3:25 PM In reply to

    Re: yes no enums and goto's

    snoofle:
    dumbphux:

    I love working with Yes No enums...then tie that in with goto's and life is good.  Did I mention this is from a top 30 internet site.  I guess bool's just wouldn't work.

     switch(searchResultsAvailable)
    {
        case SearchResultsAvailable.yes:
           title = "Featured Products";
           break;
        
    case SearchResultsAvailable.no:
           title = "Top Sellers";
           
    break;
        
    default:
           
    goto case SearchResultsAvailable.no;
    }

    Hmmm, that worked well....

    For when:

    switch (theEnum) {
    case theEnum.yes: { ...; break; }
    case theEnum.no:
    case default: {
    ...;
    break;
    }
    }

    ... simply won't do!

    Assuming this is C#, that syntax would cause a compile error. 

  • 02-13-2007 4:44 PM In reply to

    Re: yes no enums and goto's

    Kyanar:

    Assuming this is C#, that syntax would cause a compile error. 

    Why? Is C# the real WTF here? :P
    :(){ :|:& };:
  • 02-13-2007 6:37 PM In reply to

    Re: yes no enums and goto's

    fennec:
    Kyanar:

    Assuming this is C#, that syntax would cause a compile error. 

    Why? Is C# the real WTF here? :P

     switch (theEnum) {
      case theEnum.yes: { ...; break; }
      case theEnum.no:
      case default: {
           ...;
           break;
      }
    }

    the brackets shouldn't be there. It should actually be:
    switch (theEnum) {
      case theEnum.yes:  ...; break; 
      case theEnum.no:
      case default:  
           ...;
           break;
      }
    }

    itsyourcoworker.com - the place to call out the idiots in the workplace
  • 02-13-2007 6:55 PM In reply to

    Re: yes no enums and goto's

    I hate to state the obvious but... 

    if (searchResultsAvailable == SearchResultsAvailable.yes)
          title = "Featured Products";
    else
           title = "Top Sellers";

    ... or just use the ternary operator.

    The only reason I can see for that other code not working in C# is "case default" instead of just "default".

     

     

  • 02-13-2007 7:06 PM In reply to

    Re: yes no enums and goto's

    Doh, you are right...it is the case default that would blow it up. 
    itsyourcoworker.com - the place to call out the idiots in the workplace
  • 02-14-2007 1:59 PM In reply to

    Re: yes no enums and goto's

    Kyanar:
    snoofle:
    dumbphux:

    I love working with Yes No enums...then tie that in with goto's and life is good.  Did I mention this is from a top 30 internet site.  I guess bool's just wouldn't work.

     switch(searchResultsAvailable)
    {
        case SearchResultsAvailable.yes:
           title = "Featured Products";
           break;
        
    case SearchResultsAvailable.no:
           title = "Top Sellers";
           
    break;
        
    default:
           
    gotocase SearchResultsAvailable.no;
    }

    Hmmm, that worked well....

    For when:

    switch (theEnum) {
    case theEnum.yes: { ...; break; }
    case theEnum.no:
    case default: {
    ...;
    break;
    }
    }

    ... simply won't do!

    Assuming this is C#, that syntax would cause a compile error. 

    Actually, C# should accept that IIRC. You can have case X: case Y: code. It only requires a jump if there's code in between.

    I don't know if that's true with case X: default: - but that's a pointless construct anyway, when you can just say default: . And a switch with 1 case and a default should just be an if/else.

  • 02-14-2007 2:02 PM In reply to

    Re: yes no enums and goto's

    Kyanar:
    snoofle:
    dumbphux:

    I love working with Yes No enums...then tie that in with goto's and life is good.  Did I mention this is from a top 30 internet site.  I guess bool's just wouldn't work.

     switch(searchResultsAvailable)
    {
        case SearchResultsAvailable.yes:
           title = "Featured Products";
           break;
        
    case SearchResultsAvailable.no:
           title = "Top Sellers";
           
    break;
        
    default:
           
    goto case SearchResultsAvailable.no;
    }

    Hmmm, that worked well....

    For when:

    switch (theEnum) {
    case theEnum.yes: { ...; break; }
    case theEnum.no:
    case default: {
    ...;
    break;
    }
    }

    ... simply won't do!

    Assuming this is C#, that syntax would cause a compile error. 

     switch (theEnum)
    {

        case theEnum.yes: { stuff(); break;}
        case theEnum.no:
        default: {    stuff(); break; } 

    }

    is perfectly fine in C#.NET 1.1. Curly braces work just fine around blocks. No and Default can point to the same block. You just can't have any sort of fall-through.
     

  • 02-15-2007 6:13 PM In reply to

    Re: yes no enums and goto's

    Benanov:

     switch (theEnum)
    {

        case theEnum.yes: { stuff(); break;}
        case theEnum.no:
        default: {    stuff(); break; } 

    }

    is perfectly fine in C#.NET 1.1. Curly braces work just fine around blocks. No and Default can point to the same block. You just can't have any sort of fall-through.
     

    Indeed.  I was confusing it with another type of fall-through construct ("case something: case somethingelse:") which did NOT work in an earlier version of the framework.  Trying it in .NET 2.0 (pleasantly) compiles as expected.
Page 1 of 1 (10 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems