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. someone who does not trust arithmetic

someone who does not trust arithmetic

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

    bool foo(int n)
    {
    if (n > 16)
    return true;
    else if (n <= 16)
    return false;
    else
    return false;
    }

    i love this one!

    N R C V C 7 Replies Last reply
    0
    • S shadayim

      bool foo(int n)
      {
      if (n > 16)
      return true;
      else if (n <= 16)
      return false;
      else
      return false;
      }

      i love this one!

      N Offline
      N Offline
      negretrucci
      wrote on last edited by
      #2

      3 in 1 :laugh: :laugh: :laugh:

      1 Reply Last reply
      0
      • S shadayim

        bool foo(int n)
        {
        if (n > 16)
        return true;
        else if (n <= 16)
        return false;
        else
        return false;
        }

        i love this one!

        R Offline
        R Offline
        Russell Jones
        wrote on last edited by
        #3

        this sort of thing can happen if you blindly follow the compiler checking messages if (n > 16) return true; else if (n <= 16) return false; would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. Russell

        T J 2 Replies Last reply
        0
        • R Russell Jones

          this sort of thing can happen if you blindly follow the compiler checking messages if (n > 16) return true; else if (n <= 16) return false; would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. Russell

          T Offline
          T Offline
          Thomas Weller 0
          wrote on last edited by
          #4

          Oh c'mon: Use return (n > 16); and don't even consider thinking... :zzz: Regards Thomas

          R C 2 Replies Last reply
          0
          • T Thomas Weller 0

            Oh c'mon: Use return (n > 16); and don't even consider thinking... :zzz: Regards Thomas

            R Offline
            R Offline
            Russell Jones
            wrote on last edited by
            #5

            bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; } Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.

            T A 2 Replies Last reply
            0
            • S shadayim

              bool foo(int n)
              {
              if (n > 16)
              return true;
              else if (n <= 16)
              return false;
              else
              return false;
              }

              i love this one!

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

              shadayim wrote:

              i love this one!

              Me too: 5. :)

              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.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              1 Reply Last reply
              0
              • R Russell Jones

                bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; } Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.

                T Offline
                T Offline
                Thomas Weller 0
                wrote on last edited by
                #7

                Very good point - I fully agree. You gave a good example on how things like that can (and all too often will) happen in real word. But nevertheless the result is kind of 'coding horror' and urgently needs refactoring after deadline day. Regards Thomas

                1 Reply Last reply
                0
                • R Russell Jones

                  this sort of thing can happen if you blindly follow the compiler checking messages if (n > 16) return true; else if (n <= 16) return false; would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. Russell

                  J Offline
                  J Offline
                  Jason Lepack LeppyR64
                  wrote on last edited by
                  #8

                  Ummm.... if (n > 16) return true; else //if (n <= 16) return false;

                  1 Reply Last reply
                  0
                  • S shadayim

                    bool foo(int n)
                    {
                    if (n > 16)
                    return true;
                    else if (n <= 16)
                    return false;
                    else
                    return false;
                    }

                    i love this one!

                    V Offline
                    V Offline
                    Vincenzo Rossi
                    wrote on last edited by
                    #9

                    I've processed that code with WinZip. The result is:

                    bool foo(int n) { return (n > 16); }

                    modified on Tuesday, November 4, 2008 4:34 PM

                    L 1 Reply Last reply
                    0
                    • S shadayim

                      bool foo(int n)
                      {
                      if (n > 16)
                      return true;
                      else if (n <= 16)
                      return false;
                      else
                      return false;
                      }

                      i love this one!

                      C Offline
                      C Offline
                      Chris Maunder
                      wrote on last edited by
                      #10

                      That is called "Defensive Programming" :rolleyes:

                      cheers, Chris Maunder

                      CodeProject.com : C++ MVP

                      C C 2 Replies Last reply
                      0
                      • C Chris Maunder

                        That is called "Defensive Programming" :rolleyes:

                        cheers, Chris Maunder

                        CodeProject.com : C++ MVP

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

                        Chris Maunder wrote:

                        That is called "Defensive Programming" Roll eyes

                        Is that because many, many, many military developers use such paradigms? :rolleyes:

                        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.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        P 1 Reply Last reply
                        0
                        • R Russell Jones

                          bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; } Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.

                          A Offline
                          A Offline
                          Andrew Rissing
                          wrote on last edited by
                          #12

                          Russell Jones wrote:

                          bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; }

                          But it too would be better though as:

                          bool foo(int n)
                          {
                          return ((n > 16) || (n <= 4));
                          }

                          1 Reply Last reply
                          0
                          • C CPallini

                            Chris Maunder wrote:

                            That is called "Defensive Programming" Roll eyes

                            Is that because many, many, many military developers use such paradigms? :rolleyes:

                            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.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            P Offline
                            P Offline
                            PIEBALDconsult
                            wrote on last edited by
                            #13

                            Because the developer says, "I was told to do it that way."

                            C T 2 Replies Last reply
                            0
                            • P PIEBALDconsult

                              Because the developer says, "I was told to do it that way."

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

                              Indeed. :-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.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                              [My articles]

                              1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                Because the developer says, "I was told to do it that way."

                                T Offline
                                T Offline
                                Thomas Weller 0
                                wrote on last edited by
                                #15

                                PIEBALDconsult wrote:

                                Because the developer says, "I was told to do it that way."

                                If this is defensive programming, there must also be offensive programming and I'd kill them all - programming - because there are a lot of people out there (they call themselves also programmers, so be careful.. :-D) who give a damn on what someone else is saying, even if it might be their boss. They stick to their bad coding habits regardless of what's happening around them... Regards Thomas

                                _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

                                Programmer - an organism that turns coffee into software._

                                D 1 Reply Last reply
                                0
                                • T Thomas Weller 0

                                  PIEBALDconsult wrote:

                                  Because the developer says, "I was told to do it that way."

                                  If this is defensive programming, there must also be offensive programming and I'd kill them all - programming - because there are a lot of people out there (they call themselves also programmers, so be careful.. :-D) who give a damn on what someone else is saying, even if it might be their boss. They stick to their bad coding habits regardless of what's happening around them... Regards Thomas

                                  _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

                                  Programmer - an organism that turns coffee into software._

                                  D Offline
                                  D Offline
                                  Dan Neely
                                  wrote on last edited by
                                  #16

                                  http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]

                                  Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                  T C R 3 Replies Last reply
                                  0
                                  • D Dan Neely

                                    http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]

                                    Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                    T Offline
                                    T Offline
                                    Thomas Weller 0
                                    wrote on last edited by
                                    #17

                                    :laugh: :laugh: :laugh: Great stuff!! Regards Thomas

                                    _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

                                    Programmer - an organism that turns coffee into software._

                                    1 Reply Last reply
                                    0
                                    • D Dan Neely

                                      http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]

                                      Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

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

                                      Too good. :laugh:

                                      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.
                                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                      [My articles]

                                      1 Reply Last reply
                                      0
                                      • V Vincenzo Rossi

                                        I've processed that code with WinZip. The result is:

                                        bool foo(int n) { return (n > 16); }

                                        modified on Tuesday, November 4, 2008 4:34 PM

                                        L Offline
                                        L Offline
                                        leppie
                                        wrote on last edited by
                                        #19

                                        Vincenzo Rossi wrote:

                                        I've processed that code with WinZip.

                                        I used my brain and got:

                                        n > 16

                                        :)

                                        xacc.ide - now with TabsToSpaces support
                                        IronScheme - 1.0 beta 1 - out now!
                                        ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

                                        V 1 Reply Last reply
                                        0
                                        • D Dan Neely

                                          http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]

                                          Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

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

                                          dan neely wrote:

                                          http://gradha.sdf-eu.org/textos/klingon\_programmer.en.html\[^\]

                                          One of those sounds too familiar - on our team comments are generally frowned on - especially those that may document the parameters of a function. The boss' logic? Comments frequently aren't maintained so end up out-of-date. I'm not sure about this one - I get his point, but I'd rather see a slightly off-topic comment (and correct it when I realised) than have to work out everything's purpose from scratch the first time its encountered (or when sufficient time has passed since you last looked). Then again, there seem to be no concerns about line length either. I've encountered lines of code over 1000 characters wide, so not only are there no comments, but I have to keep scrolling sideways to see the code itself. Often, the most important work is done by a function call hidden away a few screens beyond my screen estate.

                                          K C 2 Replies 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