Exceptional coding
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
I can bet that this gem is created from a former Java programmer.
The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
Can't you see the really GOOD think this solution is? If the string is not a number you will also get the right message. It can't be simple, can it? Hahahahaha
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
Finally, a usage of exceptions that I whole-heartedly support!
--Mike--
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
Wow, that really rockz!
• My personal 24/7 webcam • Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now! • Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
:laugh: This is too unreal, you must have posted it in DotNetKick yourself to get a good line here.
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
People wouldn't really write code which is that bad in a production environment would they?
Between the idea And the reality Between the motion And the act Falls the Shadow
-
People wouldn't really write code which is that bad in a production environment would they?
Between the idea And the reality Between the motion And the act Falls the Shadow
Oh they would. And the worst thing is it (almost) works, so unless someone reviews the code they'll never learn.
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
That is probably the most insane piece of coding I've seen in all my years of programming. I might print it out and make a poster of it, to serve as a warning to our junior programmers :)
There are three kinds of people in the world - those who can count and those who can't...
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
I had to work with a state machine library that was somewhat similar. Worker threads would change states by throwing an exception. It was the most ridiculous stuff I have ever had to deal with but, of course, customers are always right and they wrote it. :rolleyes:
-
That is probably the most insane piece of coding I've seen in all my years of programming. I might print it out and make a poster of it, to serve as a warning to our junior programmers :)
There are three kinds of people in the world - those who can count and those who can't...
Next interview question, if the candidate does not fall off the chair laughing don't hire him/her
Never underestimate the power of human stupidity RAH
-
Can't you see the really GOOD think this solution is? If the string is not a number you will also get the right message. It can't be simple, can it? Hahahahaha
Well...that's the beauty of that Snippet.
Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
Just WTF is that supposed to achieve?
You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.
-
Just WTF is that supposed to achieve?
You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.
Exception-driven development, my dear Brady! :-D
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
Just WTF is that supposed to achieve?
You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.
Exception-driving development, my dear Brady! :-D
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
-
Next interview question, if the candidate does not fall off the chair laughing don't hire him/her
Never underestimate the power of human stupidity RAH
:laugh: :laugh: :laugh: :laugh: :laugh:
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Saw this one yesterday via DotNetKicks[^]:
public static class NumberHelpers
{
public static ApplicationException EvenOrOdd(int integer)
{
if (integer % 2 == 0)
{
return new ApplicationException(“The integer is even.”);
}
else
{
return new ApplicationException(“The integer is odd.”);
}
}
}Usage:
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
throw NumberHelpers.EvenOrOdd(Convert.ToInt32(txtIntToTest.Text));
}
catch (ApplicationException ex)
{
litResult.Text = ex.Message;
}
}Brilliant! I'm going to utilize this beautiful exception-based development pattern into our code base immediately!
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango
It is just a JIT compiler test. A "good" compiler would deduce the intent and eliminate all of the excess excpetion handling and place optimized code inline on the first pass. This eliminates the need for the programmer to think because the compiler has implemented the new DWIM (Do what I mean) facility. Seriously in MVS Assembler it would be XR R0,R0 L R1,VALUE D R0,=A(2) JZ EVEN process odd number J M_010 EVEN DS 0H process even number M_010 DS 0H . . .
Sam
-
I can bet that this gem is created from a former Java programmer.
The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.
Why would you assume that?
"God doesn't play dice" - Albert Einstein "God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr