Bored of if..else?
-
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.
-
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.
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. -
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. -
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.Keith Barrow wrote:
boolean=true|false|maybe
I thought a boolean was True, False or FileNotFound?
-
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.
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![^] -
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.
-
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.
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"
-
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...
LOL @ three halves :)
Before .NET 4.0, object Universe = NULL;
-
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.
-
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.
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