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. Exceptional coding

Exceptional coding

Scheduled Pinned Locked Moved The Weird and The Wonderful
comregex
19 Posts 17 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.
  • 0 0x3c0

    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

    G Offline
    G Offline
    GibbleCH
    wrote on last edited by
    #8

    I've seen far worse.

    1 Reply Last reply
    0
    • 0 0x3c0

      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

      D Offline
      D Offline
      Dan_Martin
      wrote on last edited by
      #9

      Oh they would. And the worst thing is it (almost) works, so unless someone reviews the code they'll never learn.

      1 Reply Last reply
      0
      • J Judah Gabriel 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

        M Offline
        M Offline
        molesworth
        wrote on last edited by
        #10

        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...

        M 1 Reply Last reply
        0
        • J Judah Gabriel 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

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #11

          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:

          1 Reply Last reply
          0
          • M molesworth

            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...

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #12

            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

            J 1 Reply Last reply
            0
            • P Paulo Zemek

              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

              M Offline
              M Offline
              Moim Hossain
              wrote on last edited by
              #13

              Well...that's the beauty of that Snippet.

              Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

              1 Reply Last reply
              0
              • J Judah Gabriel 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

                B Offline
                B Offline
                Brady Kelly
                wrote on last edited by
                #14

                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.

                J 2 Replies Last reply
                0
                • B Brady Kelly

                  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.

                  J Offline
                  J Offline
                  Judah Gabriel Himango
                  wrote on last edited by
                  #15

                  Exception-driven development, my dear Brady! :-D

                  Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

                  1 Reply Last reply
                  0
                  • B Brady Kelly

                    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.

                    J Offline
                    J Offline
                    Judah Gabriel Himango
                    wrote on last edited by
                    #16

                    Exception-driving development, my dear Brady! :-D

                    Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

                    1 Reply Last reply
                    0
                    • M Mycroft Holmes

                      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

                      J Offline
                      J Offline
                      John R Shaw
                      wrote on last edited by
                      #17

                      :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

                      1 Reply Last reply
                      0
                      • J Judah Gabriel 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

                        S Offline
                        S Offline
                        ssiegel
                        wrote on last edited by
                        #18

                        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

                        1 Reply Last reply
                        0
                        • S Single Step Debugger

                          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.

                          J Offline
                          J Offline
                          jan larsen
                          wrote on last edited by
                          #19

                          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

                          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