Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Bored of if..else?

Bored of if..else?

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpcollaborationquestion
10 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan_Martin
    wrote on last edited by
    #1

    A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

    //fancy to use switch case bored with if else
    bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
    switch (moreThanOneModelTypes)
    {
    case true:
    this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
    goto default;

    case false:
        goto default;
               
    default:
    
        foreach (VehicleType vehicleType in vehicle.PossibleTypes)
        {                   
                         this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
        }
        \_fullVehicleModelTypeReload = false;
        break;
    

    }

    So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

    K G L R V 6 Replies Last reply
    0
    • D Dan_Martin

      A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

      //fancy to use switch case bored with if else
      bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
      switch (moreThanOneModelTypes)
      {
      case true:
      this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
      goto default;

      case false:
          goto default;
                 
      default:
      
          foreach (VehicleType vehicleType in vehicle.PossibleTypes)
          {                   
                           this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
          }
          \_fullVehicleModelTypeReload = false;
          break;
      

      }

      So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      The default in this is surely a marsterwork par excellance. I must have been misinformed, boolean=true|false|maybe.

      ragnaroknrol The Internet is For Porn[^]
      Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

      J S 2 Replies Last reply
      0
      • K Keith Barrow

        The default in this is surely a marsterwork par excellance. I must have been misinformed, boolean=true|false|maybe.

        ragnaroknrol The Internet is For Porn[^]
        Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #3

        You should applaud the genius for holding into account quantum mechanics!

        Jeroen De Dauw
        Blog ; Wiki

        1 Reply Last reply
        0
        • K Keith Barrow

          The default in this is surely a marsterwork par excellance. I must have been misinformed, boolean=true|false|maybe.

          ragnaroknrol The Internet is For Porn[^]
          Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

          S Offline
          S Offline
          Samuel Cragg
          wrote on last edited by
          #4

          Keith Barrow wrote:

          boolean=true|false|maybe

          I thought a boolean was True, False or FileNotFound?

          1 Reply Last reply
          0
          • D Dan_Martin

            A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

            //fancy to use switch case bored with if else
            bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
            switch (moreThanOneModelTypes)
            {
            case true:
            this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
            goto default;

            case false:
                goto default;
                       
            default:
            
                foreach (VehicleType vehicleType in vehicle.PossibleTypes)
                {                   
                                 this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
                }
                \_fullVehicleModelTypeReload = false;
                break;
            

            }

            So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

            G Offline
            G Offline
            Gary R Wheeler
            wrote on last edited by
            #5

            Is this guy in his 50's, bald, close-set eyes? If it is, I used to work with him :shudder:.

            Software Zen: delete this;
            Fold With Us![^]

            1 Reply Last reply
            0
            • D Dan_Martin

              A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

              //fancy to use switch case bored with if else
              bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
              switch (moreThanOneModelTypes)
              {
              case true:
              this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
              goto default;

              case false:
                  goto default;
                         
              default:
              
                  foreach (VehicleType vehicleType in vehicle.PossibleTypes)
                  {                   
                                   this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
                  }
                  \_fullVehicleModelTypeReload = false;
                  break;
              

              }

              So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              one half of me is LMAO, the other half is straight faced and the rest is thinking if that can be incorporated in my own code.

              ...byte till it megahertz...

              H 1 Reply Last reply
              0
              • D Dan_Martin

                A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

                //fancy to use switch case bored with if else
                bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
                switch (moreThanOneModelTypes)
                {
                case true:
                this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
                goto default;

                case false:
                    goto default;
                           
                default:
                
                    foreach (VehicleType vehicleType in vehicle.PossibleTypes)
                    {                   
                                     this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
                    }
                    \_fullVehicleModelTypeReload = false;
                    break;
                

                }

                So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

                R Offline
                R Offline
                Roger Wright
                wrote on last edited by
                #7

                I have to ask - was there ever a case in which the default clause executed? Did the author honestly expect it to? Bear in mind that Boole's wife was also a mathematician, and in her algebra there were three states: "true", "false", and "it depends..."

                "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                1 Reply Last reply
                0
                • L Lost User

                  one half of me is LMAO, the other half is straight faced and the rest is thinking if that can be incorporated in my own code.

                  ...byte till it megahertz...

                  H Offline
                  H Offline
                  Hired Mind
                  wrote on last edited by
                  #8

                  LOL @ three halves :)

                  Before .NET 4.0, object Universe = NULL;

                  1 Reply Last reply
                  0
                  • D Dan_Martin

                    A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

                    //fancy to use switch case bored with if else
                    bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
                    switch (moreThanOneModelTypes)
                    {
                    case true:
                    this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
                    goto default;

                    case false:
                        goto default;
                               
                    default:
                    
                        foreach (VehicleType vehicleType in vehicle.PossibleTypes)
                        {                   
                                         this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
                        }
                        \_fullVehicleModelTypeReload = false;
                        break;
                    

                    }

                    So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

                    V Offline
                    V Offline
                    VaKa
                    wrote on last edited by
                    #9

                    Just found :thumbsup::thumbsup::thumbsup::thumbsup: Is it GPLed ? Can I use this portion of code? :laugh:

                    1 Reply Last reply
                    0
                    • D Dan_Martin

                      A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:

                      //fancy to use switch case bored with if else
                      bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
                      switch (moreThanOneModelTypes)
                      {
                      case true:
                      this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
                      goto default;

                      case false:
                          goto default;
                                 
                      default:
                      
                          foreach (VehicleType vehicleType in vehicle.PossibleTypes)
                          {                   
                                           this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
                          }
                          \_fullVehicleModelTypeReload = false;
                          break;
                      

                      }

                      So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.

                      B Offline
                      B Offline
                      BillW33
                      wrote on last edited by
                      #10

                      While that code snippet may indeed produce the desired effect it is one of the most convoluted ways I have seen of doing a simple task. See my sig. You should tell that guy about the International Obfuscated C Code Contest (IOCCC[^])

                      Just because the code works, it doesn't mean that it is good code.

                      modified on Wednesday, August 25, 2010 2:40 PM

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups