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. Care for belt, suspenders, and a spare rope?

Care for belt, suspenders, and a spare rope?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
12 Posts 8 Posters 3 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.
  • K Offline
    K Offline
    KP Lee
    wrote on last edited by
    #1

    if (wttResultsDataTable.Rows.Count == 1000)
    {
    if (wttResultsDataTable != null)
    {
    if (wttResultsDataTable.Rows.Count > 0 && DCTReportRoot.errorFlagRaised == false)
    {

    Besides the fact, the code would blow up before this point if wttResultsDataTable was null, wouldn't the first if blow up if it was null?

    M B OriginalGriffO 3 Replies Last reply
    0
    • K KP Lee

      if (wttResultsDataTable.Rows.Count == 1000)
      {
      if (wttResultsDataTable != null)
      {
      if (wttResultsDataTable.Rows.Count > 0 && DCTReportRoot.errorFlagRaised == false)
      {

      Besides the fact, the code would blow up before this point if wttResultsDataTable was null, wouldn't the first if blow up if it was null?

      M Offline
      M Offline
      Mohibur Rashid
      wrote on last edited by
      #2

      Nice piece of work, if wttResultsDataTable is really null application will fail in the first place :laugh: :laugh: :laugh: :laugh: :laugh:

      1 Reply Last reply
      0
      • K KP Lee

        if (wttResultsDataTable.Rows.Count == 1000)
        {
        if (wttResultsDataTable != null)
        {
        if (wttResultsDataTable.Rows.Count > 0 && DCTReportRoot.errorFlagRaised == false)
        {

        Besides the fact, the code would blow up before this point if wttResultsDataTable was null, wouldn't the first if blow up if it was null?

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        You cannot be sure... In a multi-threading environment, something bad might happen to the wttResultsDataTable during the calls. Better safe than sorry! :)

        B 1 Reply Last reply
        0
        • B Bernhard Hiller

          You cannot be sure... In a multi-threading environment, something bad might happen to the wttResultsDataTable during the calls. Better safe than sorry! :)

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

          You are quite right. The code should be

          lock(global_lock_object){
          if (wttResultsDataTable.Rows.Count == 1000)
          {
          if (wttResultsDataTable != null)
          {
          if (wttResultsDataTable.Rows.Count > 0 && DCTReportRoot.errorFlagRaised == false)
          {

          1 Reply Last reply
          0
          • K KP Lee

            if (wttResultsDataTable.Rows.Count == 1000)
            {
            if (wttResultsDataTable != null)
            {
            if (wttResultsDataTable.Rows.Count > 0 && DCTReportRoot.errorFlagRaised == false)
            {

            Besides the fact, the code would blow up before this point if wttResultsDataTable was null, wouldn't the first if blow up if it was null?

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

            I'm not sure he is being quite cautious enough. Surely he should add a test to ensure that 1000 is a positive number?

            if (!(1000 < 0))
            {
            ...

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "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

            Sander RosselS 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I'm not sure he is being quite cautious enough. Surely he should add a test to ensure that 1000 is a positive number?

              if (!(1000 < 0))
              {
              ...

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              Sander RosselS Offline
              Sander RosselS Offline
              Sander Rossel
              wrote on last edited by
              #6

              You're still taking way to many risks there... Before checking that you should check if false is not true!

              if (false != true) { ...

              The Mayan calendar ends soon, so you'll never know what might happen... At least THIS software won't break ;p

              It's an OO world.

              public class Naerling : Lazy<Person>{
              public void DoWork(){ throw new NotImplementedException(); }
              }

              OriginalGriffO K 2 Replies Last reply
              0
              • Sander RosselS Sander Rossel

                You're still taking way to many risks there... Before checking that you should check if false is not true!

                if (false != true) { ...

                The Mayan calendar ends soon, so you'll never know what might happen... At least THIS software won't break ;p

                It's an OO world.

                public class Naerling : Lazy<Person>{
                public void DoWork(){ throw new NotImplementedException(); }
                }

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

                I remember one FORTRAN compiler (GEC 4070 IIRC) where you could write the equivilent of this:

                if (1==1)
                statement 1
                else if (1!=1)
                statement 2
                else
                statement 3

                with pretty good confidence that each of the three statements would be executed at some point... :sigh:

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                "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

                K 1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  You're still taking way to many risks there... Before checking that you should check if false is not true!

                  if (false != true) { ...

                  The Mayan calendar ends soon, so you'll never know what might happen... At least THIS software won't break ;p

                  It's an OO world.

                  public class Naerling : Lazy<Person>{
                  public void DoWork(){ throw new NotImplementedException(); }
                  }

                  K Offline
                  K Offline
                  Kostya Kovalskyy
                  wrote on last edited by
                  #8

                  #define true false Never trust those booleans!

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    I remember one FORTRAN compiler (GEC 4070 IIRC) where you could write the equivilent of this:

                    if (1==1)
                    statement 1
                    else if (1!=1)
                    statement 2
                    else
                    statement 3

                    with pretty good confidence that each of the three statements would be executed at some point... :sigh:

                    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                    K Offline
                    K Offline
                    KP Lee
                    wrote on last edited by
                    #9

                    OriginalGriff wrote:

                    with pretty good confidence that each of the three statements would be executed at some point

                    I'd love to argue that with you, but I've worked with FORTRAN before. I've seen code I'd swear was dead and refused to remove it just because I've seen things that can't happen, proceed to do so in that language.

                    OriginalGriffO 1 Reply Last reply
                    0
                    • K KP Lee

                      OriginalGriff wrote:

                      with pretty good confidence that each of the three statements would be executed at some point

                      I'd love to argue that with you, but I've worked with FORTRAN before. I've seen code I'd swear was dead and refused to remove it just because I've seen things that can't happen, proceed to do so in that language.

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

                      Yeah - COMMON was a good source of "oddities". I have seen COMMON used to declare a variable as a single integer, and use it as a multidimensional array of floats... We used to say "Don't like the OS? Use FORTRAN, and change it!"

                      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                      "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

                      P K 2 Replies Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Yeah - COMMON was a good source of "oddities". I have seen COMMON used to declare a variable as a single integer, and use it as a multidimensional array of floats... We used to say "Don't like the OS? Use FORTRAN, and change it!"

                        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                        P Offline
                        P Offline
                        Peter_in_2780
                        wrote on last edited by
                        #11

                        OriginalGriff wrote:

                        "Don't like the OS? Use FORTRAN, and change it!"

                        You've just reminded me of my first ever hack. Back in 1964 or thereabouts at Monash Uni, they had a "state of the art" CDC 3200 to which we were allowed to send decks of punched cards. A day or so later, the deck reappeared, hopefully wrapped in a couple of pages of printout. We mere undergrads were limited to IIRC 30 secs run time, which became a bit of a limit on some of our "foreign orders". So, based on a knowledge of the constant absolute address of blank common and a bit of spelunking (find locations in the OS that changed more or less linearly with time...), I wrote an innocent looking FORTRAN subroutine that reset the job timer if it was close to running out. Oh, the joys of unchecked negative array indexes! Cheers, Peter

                        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          Yeah - COMMON was a good source of "oddities". I have seen COMMON used to declare a variable as a single integer, and use it as a multidimensional array of floats... We used to say "Don't like the OS? Use FORTRAN, and change it!"

                          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                          K Offline
                          K Offline
                          KP Lee
                          wrote on last edited by
                          #12

                          I remember investigating one application that tried to jump to an invalid location. That app was innocent. Some other code used COMMON to reach what happened to be that program's current memory location, re-wrote the computer instructions including the said jump statement. The app was just running it's instructions when all of a sudden it wasn't their instruction set anymore.

                          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