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. I wonder what the programmer was going to do..

I wonder what the programmer was going to do..

Scheduled Pinned Locked Moved The Weird and The Wonderful
12 Posts 11 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.
  • I Offline
    I Offline
    inch
    wrote on last edited by
    #1

    I just found this in some ancient C code:

    if (number_of_records > 0)
    {}
    else
    {}

    I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

    S S OriginalGriffO T M 8 Replies Last reply
    0
    • I inch

      I just found this in some ancient C code:

      if (number_of_records > 0)
      {}
      else
      {}

      I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

      S Offline
      S Offline
      Sandeep Singh Shekhawat
      wrote on last edited by
      #2

      He was just explaining syntax of if...else to his/her co-programmer. The co-programmer was free to cook anything between these {}.

      1 Reply Last reply
      0
      • I inch

        I just found this in some ancient C code:

        if (number_of_records > 0)
        {}
        else
        {}

        I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

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

        There is the code I was looking for! Could you please tell me what file its in now :-D

        I 1 Reply Last reply
        0
        • I inch

          I just found this in some ancient C code:

          if (number_of_records > 0)
          {}
          else
          {}

          I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

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

          It's a long standing game of Code Tennis. You fill in the "if" part, and send it back for his move on the "else".

          Never underestimate the power of stupid things in large numbers --- Serious Sam

          "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 snorkie

            There is the code I was looking for! Could you please tell me what file its in now :-D

            I Offline
            I Offline
            inch
            wrote on last edited by
            #5

            Yes, its in a function called read_the_mi_file() in MINSERT.C If you'd like to take ownership of the whole pile of BS I'll ZIP it up for you..

            1 Reply Last reply
            0
            • I inch

              I just found this in some ancient C code:

              if (number_of_records > 0)
              {}
              else
              {}

              I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

              T Offline
              T Offline
              tgrt
              wrote on last edited by
              #6

              He had that variable number_of_records sitting around and had to do something with it.

              1 Reply Last reply
              0
              • I inch

                I just found this in some ancient C code:

                if (number_of_records > 0)
                {}
                else
                {}

                I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

                M Offline
                M Offline
                MarkTJohnson
                wrote on last edited by
                #7

                Look at the bright side. There's nothing to undo with this code.

                1 Reply Last reply
                0
                • I inch

                  I just found this in some ancient C code:

                  if (number_of_records > 0)
                  {}
                  else
                  {}

                  I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

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

                  The real question isn't what the original programmer was intending to do, but what do you need to do if number_of_records > 0 ? ;)

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

                  1 Reply Last reply
                  0
                  • I inch

                    I just found this in some ancient C code:

                    if (number_of_records > 0)
                    {}
                    else
                    {}

                    I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

                    P Offline
                    P Offline
                    phil o
                    wrote on last edited by
                    #9

                    OP may just have built this piece of code to prevent a warning saying that variable 'number_of_records' has been declared but is never used. Quite brilliant, actually.

                    Women are composed of carbon, hydrogen, oxygen and nitrogen; men are also composed of carbon, hydrogen, oxygen and nitrogen, but in such proportions that force respect.

                    1 Reply Last reply
                    0
                    • I inch

                      I just found this in some ancient C code:

                      if (number_of_records > 0)
                      {}
                      else
                      {}

                      I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|

                      L Offline
                      L Offline
                      Lutoslaw
                      wrote on last edited by
                      #10

                      Looks like an incomplete sanity check. It should be:

                      if (number_of_records > 0)
                      {}
                      else if (number_of_records <= 0)
                      {}
                      else
                      {
                      // I segfault myself.
                      printf("%d", *(int*)666);
                      }

                      Greetings - Jacek

                      P 1 Reply Last reply
                      0
                      • L Lutoslaw

                        Looks like an incomplete sanity check. It should be:

                        if (number_of_records > 0)
                        {}
                        else if (number_of_records <= 0)
                        {}
                        else
                        {
                        // I segfault myself.
                        printf("%d", *(int*)666);
                        }

                        Greetings - Jacek

                        P Offline
                        P Offline
                        Prabhu S M
                        wrote on last edited by
                        #11

                        It's always good to check whether a particular record is existing or not before accessing that record. Specially in collections, sometimes it maybe empty or less than the number of required records that you want to access. The following code will execute based on the records available

                                DataTable table = new System.Data.DataTable();
                                table.Columns.Add("ID");
                                table.Rows.Add("1");
                                string test = string.Empty;
                        
                                int num\_of\_records = table.Rows.Count;
                                if (num\_of\_records > 0)
                                {
                                    test = table.Rows\[0\]\[0\].ToString();
                                }
                                else
                                {
                                    return;
                                }
                        

                        The following code is directly trying to access a record which may or may not be existing though the code is syntactically correct it may throw error in the event of unavailablity of records.

                                DataTable table = new System.Data.DataTable();
                                table.Columns.Add("ID");            
                                string test = string.Empty;
                                test = table.Rows\[0\]\[0\].ToString();
                        

                        IndexOutOfRangeException - There is no row at position 0.

                        P 1 Reply Last reply
                        0
                        • P Prabhu S M

                          It's always good to check whether a particular record is existing or not before accessing that record. Specially in collections, sometimes it maybe empty or less than the number of required records that you want to access. The following code will execute based on the records available

                                  DataTable table = new System.Data.DataTable();
                                  table.Columns.Add("ID");
                                  table.Rows.Add("1");
                                  string test = string.Empty;
                          
                                  int num\_of\_records = table.Rows.Count;
                                  if (num\_of\_records > 0)
                                  {
                                      test = table.Rows\[0\]\[0\].ToString();
                                  }
                                  else
                                  {
                                      return;
                                  }
                          

                          The following code is directly trying to access a record which may or may not be existing though the code is syntactically correct it may throw error in the event of unavailablity of records.

                                  DataTable table = new System.Data.DataTable();
                                  table.Columns.Add("ID");            
                                  string test = string.Empty;
                                  test = table.Rows\[0\]\[0\].ToString();
                          

                          IndexOutOfRangeException - There is no row at position 0.

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

                          I agree, and the original post was probably more of a question of what the developer intended to do inside the {} in both the if part and the else part; which of course could be anything. If anything it's just dead code the compiler would likely cut out.

                          "I've seen more information on a frickin' sticky note!" - Dave Kreskowiak

                          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