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. Bet this algorithm never occured to anyone...

Bet this algorithm never occured to anyone...

Scheduled Pinned Locked Moved The Weird and The Wonderful
algorithms
31 Posts 20 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.
  • T to_be_defined

    Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

    bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
    {
    if ( Entry.sty.GetValueAsLong() == 4L )
    {
    return(true);
    }
    else if ( Entry.sty.GetValueAsLong() == 5L )
    {
    return(true);
    }
    else
    return(true);
    }

    D Offline
    D Offline
    DavidNohejl
    wrote on last edited by
    #2

    Wow. I just really hope it's result of changes in sales type validity rather than that someone wrote it like this from scratch :~ Still its just wrong on so many levels. Nice.


    "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

    1 Reply Last reply
    0
    • T to_be_defined

      Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

      bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
      {
      if ( Entry.sty.GetValueAsLong() == 4L )
      {
      return(true);
      }
      else if ( Entry.sty.GetValueAsLong() == 5L )
      {
      return(true);
      }
      else
      return(true);
      }

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #3

      I saw (Visual Basic)

      IF a=1 AND a<>2 and a<>3 and a<>4 THEN ...

      :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      P 1 Reply Last reply
      0
      • T to_be_defined

        Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

        bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
        {
        if ( Entry.sty.GetValueAsLong() == 4L )
        {
        return(true);
        }
        else if ( Entry.sty.GetValueAsLong() == 5L )
        {
        return(true);
        }
        else
        return(true);
        }

        E Offline
        E Offline
        eugene genis
        wrote on last edited by
        #4

        surely it was coded that way to ensure extensibility?! :jig:

        1 Reply Last reply
        0
        • T to_be_defined

          Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

          bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
          {
          if ( Entry.sty.GetValueAsLong() == 4L )
          {
          return(true);
          }
          else if ( Entry.sty.GetValueAsLong() == 5L )
          {
          return(true);
          }
          else
          return(true);
          }

          N Offline
          N Offline
          NormDroid
          wrote on last edited by
          #5

          Everyones a winner, I wonder if the unit testing picked up on this.

          .net is a box of never ending treasures, every day I get find another gem.

          P T 2 Replies Last reply
          0
          • N NormDroid

            Everyones a winner, I wonder if the unit testing picked up on this.

            .net is a box of never ending treasures, every day I get find another gem.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #6

            Of course it did. Assert.IsTrue(...); Never fails.:laugh:

            Deja View - the feeling that you've seen this post before.

            1 Reply Last reply
            0
            • C CPallini

              I saw (Visual Basic)

              IF a=1 AND a<>2 and a<>3 and a<>4 THEN ...

              :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #7

              It's that case where another thread accesses a during the call..., oh wait - you said VB:laugh:

              Deja View - the feeling that you've seen this post before.

              C 1 Reply Last reply
              0
              • P Pete OHanlon

                It's that case where another thread accesses a during the call..., oh wait - you said VB:laugh:

                Deja View - the feeling that you've seen this post before.

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #8

                Even in a multithreaded application the code shown didn't make any sense (at least for me). :):-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                P 1 Reply Last reply
                0
                • C CPallini

                  Even in a multithreaded application the code shown didn't make any sense (at least for me). :):-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #9

                  True, but I really should have put a joke icon on the post.

                  Deja View - the feeling that you've seen this post before.

                  1 Reply Last reply
                  0
                  • N NormDroid

                    Everyones a winner, I wonder if the unit testing picked up on this.

                    .net is a box of never ending treasures, every day I get find another gem.

                    T Offline
                    T Offline
                    to_be_defined
                    wrote on last edited by
                    #10

                    Ah yes, the unit tests don't exist. :sigh: From the method comments, it seems like it should return true only for the two ifs and false for the else. I'm not even sure who to talk to about this; it was coded 3 years ago by a contractor in another country and not part of the packages we're working on. My prediction is that this baby's here to stay.

                    N 1 Reply Last reply
                    0
                    • T to_be_defined

                      Ah yes, the unit tests don't exist. :sigh: From the method comments, it seems like it should return true only for the two ifs and false for the else. I'm not even sure who to talk to about this; it was coded 3 years ago by a contractor in another country and not part of the packages we're working on. My prediction is that this baby's here to stay.

                      N Offline
                      N Offline
                      NormDroid
                      wrote on last edited by
                      #11

                      to_be_defined wrote:

                      it was coded 3 years ago by a contractor in another country

                      Yup, that explains all.

                      .net is a box of never ending treasures, every day I get find another gem.

                      1 Reply Last reply
                      0
                      • T to_be_defined

                        Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

                        bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
                        {
                        if ( Entry.sty.GetValueAsLong() == 4L )
                        {
                        return(true);
                        }
                        else if ( Entry.sty.GetValueAsLong() == 5L )
                        {
                        return(true);
                        }
                        else
                        return(true);
                        }

                        A Offline
                        A Offline
                        Anton Afanasyev
                        wrote on last edited by
                        #12

                        to_be_defined wrote:

                        Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

                        Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\


                        :badger:

                        D J J 3 Replies Last reply
                        0
                        • A Anton Afanasyev

                          to_be_defined wrote:

                          Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

                          Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\


                          :badger:

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #13

                          Of course not! I works doesn't it?! :laugh:

                          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                               2006, 2007

                          L 1 Reply Last reply
                          0
                          • A Anton Afanasyev

                            to_be_defined wrote:

                            Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

                            Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\


                            :badger:

                            J Offline
                            J Offline
                            Jasmine2501
                            wrote on last edited by
                            #14

                            -irregardless- :laugh: That's a good one for this discussion. I bet if you changed that to simply return true all the time, it would totally break the application...

                            "Quality Software since 1983!"
                            http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

                            J L 2 Replies Last reply
                            0
                            • J Jasmine2501

                              -irregardless- :laugh: That's a good one for this discussion. I bet if you changed that to simply return true all the time, it would totally break the application...

                              "Quality Software since 1983!"
                              http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

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

                              Ihave seen much strangers things happen! :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
                              • D Dave Kreskowiak

                                Of course not! I works doesn't it?! :laugh:

                                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                     2006, 2007

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #16

                                And, in many installations it would remain the way it is. In order to change code thee must be a request for an enhancement or to fix a problem. If you fix something that's 'working' and introduce a new bug you can be for the high-jump.

                                Paul

                                C A 2 Replies Last reply
                                0
                                • L Lost User

                                  And, in many installations it would remain the way it is. In order to change code thee must be a request for an enhancement or to fix a problem. If you fix something that's 'working' and introduce a new bug you can be for the high-jump.

                                  Paul

                                  C Offline
                                  C Offline
                                  Collin Parker
                                  wrote on last edited by
                                  #17

                                  It probably depends on where you work and if you're the one who has to support the code in the future. If I was the one who had the support the code, I'd change it. At least then if something breaks, I'm also the one who has to fix it.

                                  L 1 Reply Last reply
                                  0
                                  • L Lost User

                                    And, in many installations it would remain the way it is. In order to change code thee must be a request for an enhancement or to fix a problem. If you fix something that's 'working' and introduce a new bug you can be for the high-jump.

                                    Paul

                                    A Offline
                                    A Offline
                                    Anton Afanasyev
                                    wrote on last edited by
                                    #18

                                    yeah, but its a function that returns true no mater what the conditions are, and judging by the calls it makes, doesnt do anything else.so..


                                    :badger:

                                    C 1 Reply Last reply
                                    0
                                    • T to_be_defined

                                      Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...

                                      bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
                                      {
                                      if ( Entry.sty.GetValueAsLong() == 4L )
                                      {
                                      return(true);
                                      }
                                      else if ( Entry.sty.GetValueAsLong() == 5L )
                                      {
                                      return(true);
                                      }
                                      else
                                      return(true);
                                      }

                                      A Offline
                                      A Offline
                                      Andrea75
                                      wrote on last edited by
                                      #19

                                      this is 'cause it is necessary document methods with the name of the author, so will be always possible to give to the author 100 lashs :) ...i'm joking.....1000 lashs :)))

                                      1 Reply Last reply
                                      0
                                      • C Collin Parker

                                        It probably depends on where you work and if you're the one who has to support the code in the future. If I was the one who had the support the code, I'd change it. At least then if something breaks, I'm also the one who has to fix it.

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #20

                                        If it was my code, my responsibility etc, so would I. I have worked as a contractor for 25 years, and I can assure you it would NOT be changed at many places where I have worked without an RFC (request for change), cost benefit analysis, documentation, code review, test plan, version control, comment out old code and insert new, etc etc. However, if you are changing a part of the system which incorporates that particular bit of code then kill it, cus you have to do all of the above anyway. However, sometimes code you think does nothing, may do something. A slight change to the above algorithm, say that it becomes possible to drop through the code and exit without returning a return value. This throws an exception that is caught elsewhere. (That, for example, would happen with Powerbuilder 8+). Also, there may be a difference in behaviour between just returning true and looking at a passed invalid parameter (say a null pointer). For these sort of reasons, many sites will use an "if it ain't broke then don't fix it" approach. Chaning code withour permission is loose-cannon behaviour. I am not trying to support this position, all the fibres of my soul want to change code when I see it is badly written, designed or implemented. You just have to learn to sit on your coding hands.

                                        Paul

                                        A W 2 Replies Last reply
                                        0
                                        • J Jasmine2501

                                          -irregardless- :laugh: That's a good one for this discussion. I bet if you changed that to simply return true all the time, it would totally break the application...

                                          "Quality Software since 1983!"
                                          http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #21

                                          I can see you have been in the industry a while - I agree. I can think of at least 4 reasons why the code above may behave differently to "return true", depending on the language and hardware.

                                          Paul

                                          J 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