|
Looks like code intended for debugging.
|
|
|
|
|
agreed
I do not fear of failure. I fear of giving up out of frustration.
|
|
|
|
|
I would ask why first? Perhaps there used to be a condition they were checking for and then at some point found out they didn't need it. It's easier to modify this one function then stop calling it from everywhere it could be used.
I would have expected a comment in it though, if that were the case.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
"What kind of debugging technique it is?" That's my first thought.
During debugging I would routinely put code like this to make debugging easier:
if(i == 4)
i = 4;
or
if(n == nullptr)
i = i;
|
|
|
|
|
Exactly.
Good and Bad code are created one line at a time.
This happens to be a chunk of forgotten code.
To know and not do, is not yet to know
|
|
|
|
|
Mladen Janković wrote: if(i == 4)
i = 4;
Was "4" chosen by a fair dice roll[^]?
Greetings - Jacek
|
|
|
|
|
Well, to take a point from a previous thread, it has one too many return statements.
Ducks and runs for cover.
At least I stay consistent.
Mark "So old school, Socrates was in his first year teaching." Johnson
Don't like the shot clock, the three point shot, or the designated hitter either.
|
|
|
|
|
MarkTJohnson wrote: one too many
It's much worse than that; it has fully twice as many as required!
|
|
|
|
|
Yes, it does have twice as many as needed.
He gets paid by the code line.
Then, when time comes to refactor and he gets paid by reducing the number of code lines, it's a double-paycheck score.
|
|
|
|
|
Bingo!!! Where is such company that pays that way... Can I have address and name of HR and name of the bar she frequents after work?
|
|
|
|
|
What the heck were you drinking that day mate?!
|
|
|
|
|
This look like obfuscators's poop... Obfuscator creates this kind of code all over the place ...
|
|
|
|
|
private void Frobinate()
{
string result = CreateRecord();
if (result == "")
{
}
else
{
if (MessageBox.Show("Record already exists. Do you want to update it?", MessageBoxButtons.YesNo) == DialogResults.Yes)
{
UpdateExistingRecord();
}
}
}
private string CreateRecord()
{
try
{
return "";
}
catch (Exception e)
{
return e.Message;
}
}
This pattern is absolutely brillant because nothing else could ever cause a problem. Authentication can never be incorrect. The server can never be down. Bob can never be taking a break to oil the hamster wheels.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Give the guy a break. At least he did try.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You caught that then?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Well sure. I couldn't just throw it away.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You could have made an exception in this case!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Never knew it was a pattern and had a name!
I can start using it now...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
If you're looking for other interesting desings, might I suggest the thousand plus line OnClick() method with at least ten levels of indentation pattern. Remember methodcalls have a performance overhead, so inline everything no matter how many copies you end up with.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
An appropriate design pattern should be applied indeed. 10 levels of indentation is not good, even if they were hidden in methods. A loop over a list of conditions or strategies maybe.
Besides, if we have a framework object Exception, then why return a part of it (Message) instead of a reference to the object itself (or null if no error)? Makes no sense to me. We should either return an error code or make it OO, depending on what is better in a given context. Mixing those two approaches is a bit... unusual. I am no expert, please correct if I'm wrong.
Greetings - Jacek
|
|
|
|
|
Sadly, I know programmers who love to use that pattern.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
It wasn't a hypothetical for me either.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
My head hurts from banging it on my desk. Just came across this beauty in the 'else' statement of some code I'm debugging (not mine, of course):
MessageBox.Show("Should never get this message.");
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
That's awesome. It's what happens when you feel you need a try but have no clue what to do in the event it ever does fail.
Also, it could be that if the developers ever saw it then they knew some approach was not working and could fix it but assumed their approach was right and therefore should never see it.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have gotten some of those before. Had a look at the code and can't see how it could possibly get there. Normally it is an indication that something has gone awry. Possibly stack corruption or something like that. The thing is they don't normally print the if or case bits so you haven't a clue how it got there.
|
|
|
|