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 think my WTF per minute counter just overflowed...

I think my WTF per minute counter just overflowed...

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdatabaseagentic-aiquestion
14 Posts 12 Posters 25 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.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    if (count == 1) {
    var charge = list.FirstOrDefault();
    netAmount = charge.NetAmount ?? 0;
    isSingleCharge = true;
    }
    else if (count == 2) // added on 15/03/2016 because some single charges
    // were adjusted by query and didn't remove the declaration
    {
    var fcharge = list.FirstOrDefault();
    var scharge = list.LastOrDefault();
    var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

    bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
        || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
    
    bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
    
    isSingleCharge = raisedon25th && sameAgent;
    

    }

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    P Greg UtasG M K B 8 Replies Last reply
    0
    • R Rob Grainger

      if (count == 1) {
      var charge = list.FirstOrDefault();
      netAmount = charge.NetAmount ?? 0;
      isSingleCharge = true;
      }
      else if (count == 2) // added on 15/03/2016 because some single charges
      // were adjusted by query and didn't remove the declaration
      {
      var fcharge = list.FirstOrDefault();
      var scharge = list.LastOrDefault();
      var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

      bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
          || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
      
      bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
      
      isSingleCharge = raisedon25th && sameAgent;
      

      }

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      P Offline
      P Offline
      PeejayAdams
      wrote on last edited by
      #2

      Wow! I honestly think that's as bad as anything I've ever seen in far more years than I'd care to mention.

      Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain

      R 1 Reply Last reply
      0
      • R Rob Grainger

        if (count == 1) {
        var charge = list.FirstOrDefault();
        netAmount = charge.NetAmount ?? 0;
        isSingleCharge = true;
        }
        else if (count == 2) // added on 15/03/2016 because some single charges
        // were adjusted by query and didn't remove the declaration
        {
        var fcharge = list.FirstOrDefault();
        var scharge = list.LastOrDefault();
        var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

        bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
            || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
        
        bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
        
        isSingleCharge = raisedon25th && sameAgent;
        

        }

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        Greg UtasG Offline
        Greg UtasG Offline
        Greg Utas
        wrote on last edited by
        #3

        If I understand the code fragment correctly, this sort of thing always rankled me too. Instead of finding and fixing the root cause of something, sometimes you'd see this:

        if(the conditions under which bug report #n occur are true)
        {
        fix things up and carry on;
        }

        <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
        <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

        R 1 Reply Last reply
        0
        • R Rob Grainger

          if (count == 1) {
          var charge = list.FirstOrDefault();
          netAmount = charge.NetAmount ?? 0;
          isSingleCharge = true;
          }
          else if (count == 2) // added on 15/03/2016 because some single charges
          // were adjusted by query and didn't remove the declaration
          {
          var fcharge = list.FirstOrDefault();
          var scharge = list.LastOrDefault();
          var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

          bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
              || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
          
          bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
          
          isSingleCharge = raisedon25th && sameAgent;
          

          }

          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

          And they completely forget about the netAmount in the second case.

          L 1 Reply Last reply
          0
          • R Rob Grainger

            if (count == 1) {
            var charge = list.FirstOrDefault();
            netAmount = charge.NetAmount ?? 0;
            isSingleCharge = true;
            }
            else if (count == 2) // added on 15/03/2016 because some single charges
            // were adjusted by query and didn't remove the declaration
            {
            var fcharge = list.FirstOrDefault();
            var scharge = list.LastOrDefault();
            var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

            bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
                || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
            
            bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
            
            isSingleCharge = raisedon25th && sameAgent;
            

            }

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            K Offline
            K Offline
            kmoorevs
            wrote on last edited by
            #5

            That must have been a trick instead of a treat! :laugh: at least it's documented as a special case. :)

            "Go forth into the source" - Neal Morse

            1 Reply Last reply
            0
            • P PeejayAdams

              Wow! I honestly think that's as bad as anything I've ever seen in far more years than I'd care to mention.

              Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain

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

              Yes, I sat there dumbfounded for a good few minutes after encountering this gem. I still have no idea why it exists.

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

              1 Reply Last reply
              0
              • Greg UtasG Greg Utas

                If I understand the code fragment correctly, this sort of thing always rankled me too. Instead of finding and fixing the root cause of something, sometimes you'd see this:

                if(the conditions under which bug report #n occur are true)
                {
                fix things up and carry on;
                }

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

                Is it humanly possible to truly understand code like this? Believe me, it makes no more sense given the context.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                1 Reply Last reply
                0
                • R Rob Grainger

                  if (count == 1) {
                  var charge = list.FirstOrDefault();
                  netAmount = charge.NetAmount ?? 0;
                  isSingleCharge = true;
                  }
                  else if (count == 2) // added on 15/03/2016 because some single charges
                  // were adjusted by query and didn't remove the declaration
                  {
                  var fcharge = list.FirstOrDefault();
                  var scharge = list.LastOrDefault();
                  var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

                  bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
                      || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
                  
                  bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
                  
                  isSingleCharge = raisedon25th && sameAgent;
                  

                  }

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                  I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (count == 3 etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine: Convert.ToDateTime("31 OCT 2015") and ((DateTime)fcharge.DateRaised).Date. At least, they did not invent their own Date.Equals function (or did they?). And then followed by the very clear naming of a variable raisedon25th - yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:

                  Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                  F P 2 Replies Last reply
                  0
                  • B Bernhard Hiller

                    I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (count == 3 etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine: Convert.ToDateTime("31 OCT 2015") and ((DateTime)fcharge.DateRaised).Date. At least, they did not invent their own Date.Equals function (or did they?). And then followed by the very clear naming of a variable raisedon25th - yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:

                    Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                    F Offline
                    F Offline
                    Fueled By Decaff
                    wrote on last edited by
                    #9

                    It is in the number base. OCT 31 = DEC 25 That is why programmers never know whether it is Christmas or Halloween.

                    1 Reply Last reply
                    0
                    • R Rob Grainger

                      if (count == 1) {
                      var charge = list.FirstOrDefault();
                      netAmount = charge.NetAmount ?? 0;
                      isSingleCharge = true;
                      }
                      else if (count == 2) // added on 15/03/2016 because some single charges
                      // were adjusted by query and didn't remove the declaration
                      {
                      var fcharge = list.FirstOrDefault();
                      var scharge = list.LastOrDefault();
                      var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

                      bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
                          || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
                      
                      bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
                      
                      isSingleCharge = raisedon25th && sameAgent;
                      

                      }

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #10

                      Wow. Since most of our business logic is in the database, we hope to fix problems there, because that means we can slip a db correction into production without having to do an app deployment. 99.99% of the time, it works out that way.

                      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                      -----
                      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                      -----
                      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                      1 Reply Last reply
                      0
                      • M MarkTJohnson

                        And they completely forget about the netAmount in the second case.

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

                        The worst thing is that it is probably a global variable (disguised as a non-static "field" shared by public methods) which is just set somewhere else and possibly at some different point of time.

                        1 Reply Last reply
                        0
                        • R Rob Grainger

                          if (count == 1) {
                          var charge = list.FirstOrDefault();
                          netAmount = charge.NetAmount ?? 0;
                          isSingleCharge = true;
                          }
                          else if (count == 2) // added on 15/03/2016 because some single charges
                          // were adjusted by query and didn't remove the declaration
                          {
                          var fcharge = list.FirstOrDefault();
                          var scharge = list.LastOrDefault();
                          var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

                          bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
                              || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
                          
                          bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
                          
                          isSingleCharge = raisedon25th && sameAgent;
                          

                          }

                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                          K Offline
                          K Offline
                          Keith Barrow
                          wrote on last edited by
                          #12

                          I've been using JS for the last 2-3 years. This is par for the course ;P

                          KeithBarrow.net[^] - It might not be very good, but at least it is free!

                          1 Reply Last reply
                          0
                          • R Rob Grainger

                            if (count == 1) {
                            var charge = list.FirstOrDefault();
                            netAmount = charge.NetAmount ?? 0;
                            isSingleCharge = true;
                            }
                            else if (count == 2) // added on 15/03/2016 because some single charges
                            // were adjusted by query and didn't remove the declaration
                            {
                            var fcharge = list.FirstOrDefault();
                            var scharge = list.LastOrDefault();
                            var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that date

                            bool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) 
                                || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date));
                            
                            bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id;
                            
                            isSingleCharge = raisedon25th && sameAgent;
                            

                            }

                            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                            B Offline
                            B Offline
                            Bajaja
                            wrote on last edited by
                            #13

                            This code is like a surgery made by Frank Barnes in Mash 4077

                            1 Reply Last reply
                            0
                            • B Bernhard Hiller

                              I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (count == 3 etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine: Convert.ToDateTime("31 OCT 2015") and ((DateTime)fcharge.DateRaised).Date. At least, they did not invent their own Date.Equals function (or did they?). And then followed by the very clear naming of a variable raisedon25th - yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:

                              Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                              P Offline
                              P Offline
                              Private Dobbs
                              wrote on last edited by
                              #14

                              How about this gem then, hot from some inherited code:

                              CREATE VIEW [dbo].[vwSomething]
                              AS
                              SELECT dbo.AA_SomeTable.some_table_id AS parent_id,
                              ...
                              CASE WHEN SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 9, 2)
                              + '/' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 6, 2) + '/'
                              + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 0, 5)
                              + ' ' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 12, 2) + ':'
                              + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 15, 2) IS NULL
                              THEN 'None'
                              ELSE SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 9, 2) + '/'
                              + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 6, 2)
                              + '/' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 0, 5) + ' '
                              + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 12, 2)
                              + ':' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 15, 2) END AS
                              date_details
                              FROM dbo.AA_SomeTable INNER JOIN
                              dbo.AA_Other ON dbo.AA_SomeTable.SomeTable_user_id_FK = dbo.AA_Other.user_id

                              Ummmmmmm? (Table & Column names changed to protect the guilty)

                              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