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. So, a colleague inherited a project to restructure a product..

So, a colleague inherited a project to restructure a product..

Scheduled Pinned Locked Moved The Weird and The Wonderful
help
13 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.
  • S Offline
    S Offline
    Sentenryu
    wrote on last edited by
    #1

    He called for my help when he couldn't understand a piece of code. After 2 hours digging, we finally understood what the code does. A convoluted piece of junk that just shows a string on a field on the page. But the most facepalming thing we found was this piece of "code":

    public string GetLimitMessage(int total, int limit){
    if(total > limit)
    try
    {
    return "The Limit has been reached!"
    }
    catch(Exception)
    {
    return "";
    }
    else
    return string.Empty;
    }

    Aside from translation (the original is on Portuguese), that's the exactly code we found. We are still facepalming.

    Kornfeld Eliyahu PeterK F 2 Replies Last reply
    0
    • S Sentenryu

      He called for my help when he couldn't understand a piece of code. After 2 hours digging, we finally understood what the code does. A convoluted piece of junk that just shows a string on a field on the page. But the most facepalming thing we found was this piece of "code":

      public string GetLimitMessage(int total, int limit){
      if(total > limit)
      try
      {
      return "The Limit has been reached!"
      }
      catch(Exception)
      {
      return "";
      }
      else
      return string.Empty;
      }

      Aside from translation (the original is on Portuguese), that's the exactly code we found. We are still facepalming.

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      Do you know the one wrote this? I want to hire him! My office is too dirty lately... :wtf:

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      S 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        Do you know the one wrote this? I want to hire him! My office is too dirty lately... :wtf:

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).

        S Offline
        S Offline
        Sentenryu
        wrote on last edited by
        #3

        He doesn't work here anymore (actually can be anyone of 4 people, but none of them work here now). The thing is that all of them bragged about how their code was better and how they were the best I don't want to see the worst. X|

        B 1 Reply Last reply
        0
        • S Sentenryu

          He doesn't work here anymore (actually can be anyone of 4 people, but none of them work here now). The thing is that all of them bragged about how their code was better and how they were the best I don't want to see the worst. X|

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

          Of course they bragged about their code. They used the advanced feature "try-catch" so it must be great code! Well, great in their minds, anyway. X|

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

          1 Reply Last reply
          0
          • S Sentenryu

            He called for my help when he couldn't understand a piece of code. After 2 hours digging, we finally understood what the code does. A convoluted piece of junk that just shows a string on a field on the page. But the most facepalming thing we found was this piece of "code":

            public string GetLimitMessage(int total, int limit){
            if(total > limit)
            try
            {
            return "The Limit has been reached!"
            }
            catch(Exception)
            {
            return "";
            }
            else
            return string.Empty;
            }

            Aside from translation (the original is on Portuguese), that's the exactly code we found. We are still facepalming.

            F Offline
            F Offline
            Freak30
            wrote on last edited by
            #5

            So I assume all over the codebae you have something like this?

            if (GetLimitMessage(a, b).Length > 0)
            MessageBox.Show(GetLimitMessaage(a, b));

            The good thing about pessimism is, that you are always either right or pleasently surprised.

            N S 2 Replies Last reply
            0
            • F Freak30

              So I assume all over the codebae you have something like this?

              if (GetLimitMessage(a, b).Length > 0)
              MessageBox.Show(GetLimitMessaage(a, b));

              The good thing about pessimism is, that you are always either right or pleasently surprised.

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #6

              Are you mad! That would be far too risky to write it like that, far better would be:

              if (!GetLimitMessage(a, b).equals(GetLimitMessage(1, -1)) {
              if (!String.IsNullOrEmpty(GetLimitMessage(a, b)) {
              MessageBox.Show(GetLimitMessaage(a, b));
              }
              else
              {
              MessageBox.Show("The monkey's dead!");
              }
              }

              speramus in juniperus

              S OriginalGriffO R 3 Replies Last reply
              0
              • F Freak30

                So I assume all over the codebae you have something like this?

                if (GetLimitMessage(a, b).Length > 0)
                MessageBox.Show(GetLimitMessaage(a, b));

                The good thing about pessimism is, that you are always either right or pleasently surprised.

                S Offline
                S Offline
                Sentenryu
                wrote on last edited by
                #7

                It's an APS.NET MVC 3 Application, so it's: Controller:

                if(Helper.GetLimitMessage(total, 100)) //Yep, 100 is harcoded on every line it's used...
                {
                    ViewBag.LimitMessage = Helper.GetLimitMessage(total, 100);
                    ViewData\["LimitMessage"\] = Helper.GetLimitMessage(total, 100);
                }
                

                View:

                @if(ViewBag.LimitMessage != "")
                {
                     @Helper.GetLimitMessage(total, 100)
                }
                else if (ViewData\["LimitMessage"\] != null)
                {
                     @ViewData\["LimitMessage"\]
                }
                

                Even my coworker who normally doesn't rant on code is cursing this one.

                B 0 B 3 Replies Last reply
                0
                • N Nagy Vilmos

                  Are you mad! That would be far too risky to write it like that, far better would be:

                  if (!GetLimitMessage(a, b).equals(GetLimitMessage(1, -1)) {
                  if (!String.IsNullOrEmpty(GetLimitMessage(a, b)) {
                  MessageBox.Show(GetLimitMessaage(a, b));
                  }
                  else
                  {
                  MessageBox.Show("The monkey's dead!");
                  }
                  }

                  speramus in juniperus

                  S Offline
                  S Offline
                  Sentenryu
                  wrote on last edited by
                  #8

                  Now I need some more mind bleach...

                  1 Reply Last reply
                  0
                  • N Nagy Vilmos

                    Are you mad! That would be far too risky to write it like that, far better would be:

                    if (!GetLimitMessage(a, b).equals(GetLimitMessage(1, -1)) {
                    if (!String.IsNullOrEmpty(GetLimitMessage(a, b)) {
                    MessageBox.Show(GetLimitMessaage(a, b));
                    }
                    else
                    {
                    MessageBox.Show("The monkey's dead!");
                    }
                    }

                    speramus in juniperus

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    Surely a MessageBox is rather "old hat"? How do you display a Fail Whale in a MessageBox?

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • S Sentenryu

                      It's an APS.NET MVC 3 Application, so it's: Controller:

                      if(Helper.GetLimitMessage(total, 100)) //Yep, 100 is harcoded on every line it's used...
                      {
                          ViewBag.LimitMessage = Helper.GetLimitMessage(total, 100);
                          ViewData\["LimitMessage"\] = Helper.GetLimitMessage(total, 100);
                      }
                      

                      View:

                      @if(ViewBag.LimitMessage != "")
                      {
                           @Helper.GetLimitMessage(total, 100)
                      }
                      else if (ViewData\["LimitMessage"\] != null)
                      {
                           @ViewData\["LimitMessage"\]
                      }
                      

                      Even my coworker who normally doesn't rant on code is cursing this one.

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

                      There isn't a :doh: large enough for this.

                      1 Reply Last reply
                      0
                      • N Nagy Vilmos

                        Are you mad! That would be far too risky to write it like that, far better would be:

                        if (!GetLimitMessage(a, b).equals(GetLimitMessage(1, -1)) {
                        if (!String.IsNullOrEmpty(GetLimitMessage(a, b)) {
                        MessageBox.Show(GetLimitMessaage(a, b));
                        }
                        else
                        {
                        MessageBox.Show("The monkey's dead!");
                        }
                        }

                        speramus in juniperus

                        R Offline
                        R Offline
                        Rob Grainger
                        wrote on last edited by
                        #11

                        Woah up there, you're missing a major source of defensive coding here...

                        try {
                        if (GetLimitMessage(a,b) != null && GetLimitMessage(a,b).Equals(GetLimitMessage(1, -1))) {
                        if (!string.IsNullOrEmpty(GetLimitMessage(a,b)) {
                        try {
                        MessageBox.Show(GetLimitMessage(a,b));
                        }
                        catch (Exception ex) {
                        throw;
                        }
                        }
                        }
                        }
                        catch (Exception ex) {
                        MessageBox.Show("The monkey's dead!");
                        }

                        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                        1 Reply Last reply
                        0
                        • S Sentenryu

                          It's an APS.NET MVC 3 Application, so it's: Controller:

                          if(Helper.GetLimitMessage(total, 100)) //Yep, 100 is harcoded on every line it's used...
                          {
                              ViewBag.LimitMessage = Helper.GetLimitMessage(total, 100);
                              ViewData\["LimitMessage"\] = Helper.GetLimitMessage(total, 100);
                          }
                          

                          View:

                          @if(ViewBag.LimitMessage != "")
                          {
                               @Helper.GetLimitMessage(total, 100)
                          }
                          else if (ViewData\["LimitMessage"\] != null)
                          {
                               @ViewData\["LimitMessage"\]
                          }
                          

                          Even my coworker who normally doesn't rant on code is cursing this one.

                          0 Offline
                          0 Offline
                          0bx
                          wrote on last edited by
                          #12

                          Is this the real life? Is this just fantasy? caught in a landslide no escape from reality open your eye's look up to the ceiling and stare I'm just a poor coder, I get no sympathy because I make simple things, make them work respect my deadlines, don't be a jerk Any way management blows, doesn't really matter to meeeee To meeeeeee MAMAAAAA I just killed my coworker put a gun against his head pulled my trigger, now he's dead... :thumbsup:

                          .

                          1 Reply Last reply
                          0
                          • S Sentenryu

                            It's an APS.NET MVC 3 Application, so it's: Controller:

                            if(Helper.GetLimitMessage(total, 100)) //Yep, 100 is harcoded on every line it's used...
                            {
                                ViewBag.LimitMessage = Helper.GetLimitMessage(total, 100);
                                ViewData\["LimitMessage"\] = Helper.GetLimitMessage(total, 100);
                            }
                            

                            View:

                            @if(ViewBag.LimitMessage != "")
                            {
                                 @Helper.GetLimitMessage(total, 100)
                            }
                            else if (ViewData\["LimitMessage"\] != null)
                            {
                                 @ViewData\["LimitMessage"\]
                            }
                            

                            Even my coworker who normally doesn't rant on code is cursing this one.

                            B Offline
                            B Offline
                            Brisingr Aerowing
                            wrote on last edited by
                            #13

                            :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh: :doh:

                            Getting information off the Internet is like taking a drink from a fire hydrant. - Mitchell Kapor

                            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