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. The Lounge
  3. Are programmers negative people

Are programmers negative people

Scheduled Pinned Locked Moved The Lounge
question
25 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.
  • H Offline
    H Offline
    Henry Minute
    wrote on last edited by
    #1

    I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

    Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

    V H K A J 12 Replies Last reply
    0
    • H Henry Minute

      I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

      Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Maybe this is because one is more likely to test for error conditions first. I generally write like this:

      if(someErrorCondition)
      {
      throw new Exception("message");
      }
      else if (someOtherErrorCondition)
      {
      throw new Exception("another message");
      }
      // normal processing here

      Cheers, Vıkram.


      "You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.

      1 Reply Last reply
      0
      • H Henry Minute

        I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

        Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

        K Offline
        K Offline
        keyboard warrior
        wrote on last edited by
        #3

        i think the real question is... is the stack half empty...or half full...

        ----------------------------------------------------------- "When I first saw it, I just thought that you really, really enjoyed programming in java." - Leslie Sanford

        D P 2 Replies Last reply
        0
        • H Henry Minute

          I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

          Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

          H Offline
          H Offline
          hairy_hats
          wrote on last edited by
          #4

          No.

          1 Reply Last reply
          0
          • H Henry Minute

            I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

            Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

            A Offline
            A Offline
            A Wong
            wrote on last edited by
            #5

            I try to use less negative conditional statements. They are 1 extra computation afterall...

            J 1 Reply Last reply
            0
            • K keyboard warrior

              i think the real question is... is the stack half empty...or half full...

              ----------------------------------------------------------- "When I first saw it, I just thought that you really, really enjoyed programming in java." - Leslie Sanford

              D Offline
              D Offline
              daniilzol
              wrote on last edited by
              #6

              This reminds me of a joke. An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

              P R B M 4 Replies Last reply
              0
              • H Henry Minute

                I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                J Offline
                J Offline
                John M Drescher
                wrote on last edited by
                #7

                For me it depends on if there is an else. If so what ever should be executed most goes in the block before the else so my conditional will be adjusted for that.

                John

                1 Reply Last reply
                0
                • A A Wong

                  I try to use less negative conditional statements. They are 1 extra computation afterall...

                  J Offline
                  J Offline
                  John M Drescher
                  wrote on last edited by
                  #8

                  When it gets down to x86 assembly language this is not the case as the processor has negation as part of the test instruction. I am not sure how .NET or java work on this respect.

                  John

                  1 Reply Last reply
                  0
                  • H Henry Minute

                    I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                    Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

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

                    Depends on the code. I prefer the first branch to be the expected one, such as:

                    if(FileIsOK())
                    {
                    }
                    else
                    {
                    }

                    but

                    if(!FileIsNotOK())
                    {
                    }
                    else
                    {
                    }

                    Of course I wouldn't write FileIsNotOK in the first place because it's not intuitive, but you get the idea with conditions. Normally you would expect file to be OK most of the time, so most commonly expected case should go first.

                    1 Reply Last reply
                    0
                    • H Henry Minute

                      I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                      Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                      T Offline
                      T Offline
                      Todd Smith
                      wrote on last edited by
                      #10

                      My coffee cup is always empty, never full.

                      Todd Smith

                      J 1 Reply Last reply
                      0
                      • T Todd Smith

                        My coffee cup is always empty, never full.

                        Todd Smith

                        J Offline
                        J Offline
                        Johan Pretorius
                        wrote on last edited by
                        #11

                        Then your coffee dispenser is to far away. :-D

                        Artificial Intelligence is no match for Natural Stupidity
                        No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
                        I can't always be wrong ... or can I?

                        1 Reply Last reply
                        0
                        • D daniilzol

                          This reminds me of a joke. An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

                          P Offline
                          P Offline
                          Paul Conrad
                          wrote on last edited by
                          #12

                          JazzJackRabbit wrote:

                          An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

                          Heard that one before. It's a good one :)

                          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                          1 Reply Last reply
                          0
                          • H Henry Minute

                            I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                            Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                            M Offline
                            M Offline
                            Member 96
                            wrote on last edited by
                            #13

                            That's just natural. In nature anything unique can be more quickly identified by what it isn't. You don't identify something unique by leaping to the right conclusion immediately... well, some try and are often wrong. Programming follows this same pattern because most conditionals are looking for an exception to an expectation of what will be a normal value because most are used to handle something unique.


                            "It's so simple to be wise. Just think of something stupid to say and then don't say it." -Sam Levenson

                            1 Reply Last reply
                            0
                            • D daniilzol

                              This reminds me of a joke. An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

                              R Offline
                              R Offline
                              realJSOP
                              wrote on last edited by
                              #14

                              Real men don't drink from a glass. They drink from a canteen, a broken bottle, a running stream, or a hubcap, all the while looking for a target of opportunity.

                              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                              -----
                              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                              P 1 Reply Last reply
                              0
                              • D daniilzol

                                This reminds me of a joke. An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

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

                                Hahahaha. Is that public domain, or do I credit you when I use it on my web site?

                                Q: What is the difference between a pigeon and a merchant banker? A: A pigeon can still put a deposit on a Ferrari.

                                D 1 Reply Last reply
                                0
                                • R realJSOP

                                  Real men don't drink from a glass. They drink from a canteen, a broken bottle, a running stream, or a hubcap, all the while looking for a target of opportunity.

                                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                                  -----
                                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                                  P Offline
                                  P Offline
                                  Paul Conrad
                                  wrote on last edited by
                                  #16

                                  John Simmons / outlaw programmer wrote:

                                  Real men don't drink from a glass.

                                  Yep. Only drink from a mug around here :rolleyes:

                                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                                  1 Reply Last reply
                                  0
                                  • H Henry Minute

                                    I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                                    Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                                    G Offline
                                    G Offline
                                    Graham Bradshaw
                                    wrote on last edited by
                                    #17

                                    I don't not find that non-positive logic tests are not less complex to understand.

                                    H 1 Reply Last reply
                                    0
                                    • H Henry Minute

                                      I was just reading through some code, looking for the cause of an undocumented feature, and it occurred to me that something like 70% of my conditional statements are in the negative. e.g. if (x != y), or while (!p). Is this the same for you guys/gals, and is it a bad thing?

                                      Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                                      S Offline
                                      S Offline
                                      Shog9 0
                                      wrote on last edited by
                                      #18

                                      I see this most often when working with code written by die-hard "only one return per function" coders. Tests for NULL / invalid values, right before the huge block containing all of the code in the function. It annoys me. A lot. I'm usually quite happy to re-write them in a less negative fashion...

                                      ----

                                      You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

                                      1 Reply Last reply
                                      0
                                      • B Brady Kelly

                                        Hahahaha. Is that public domain, or do I credit you when I use it on my web site?

                                        Q: What is the difference between a pigeon and a merchant banker? A: A pigeon can still put a deposit on a Ferrari.

                                        D Offline
                                        D Offline
                                        daniilzol
                                        wrote on last edited by
                                        #19

                                        No idea. I think I read the joke somewhere on the web.

                                        1 Reply Last reply
                                        0
                                        • D daniilzol

                                          This reminds me of a joke. An optimist says the glass is half full, pessimist says glass is half empty, programmer says the glass is twice as big as it needs to be.

                                          M Offline
                                          M Offline
                                          Miszou
                                          wrote on last edited by
                                          #20

                                          I seem to recall a Dilbert version of that joke where he says something like "I have a redundant backup over here" and points to another half empty/full glass.

                                          Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

                                          D 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