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. Tales from J.S. Crypt, Day 3

Tales from J.S. Crypt, Day 3

Scheduled Pinned Locked Moved The Weird and The Wonderful
pythoncomlearning
14 Posts 10 Posters 1 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.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

    // Function to genearte the Transaction Type Code
    public string getTransactionType(string TransactionType)
    {
    if (TransactionType == ("A"))
    {
    TransactionType = "1";
    }
    else if (TransactionType == ("B") || TransactionType == ("C"))
    {
    TransactionType = "3";
    }
    else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
    {
    TransactionType = "4";
    }
    else if (TransactionType == ("G"))
    {
    TransactionType = "5";
    }
    else if (TransactionType == ("H"))
    {
    TransactionType = "6";
    }
    return TransactionType;
    }

    Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

    W N J B H 7 Replies Last reply
    0
    • M Marc Clifton

      A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

      // Function to genearte the Transaction Type Code
      public string getTransactionType(string TransactionType)
      {
      if (TransactionType == ("A"))
      {
      TransactionType = "1";
      }
      else if (TransactionType == ("B") || TransactionType == ("C"))
      {
      TransactionType = "3";
      }
      else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
      {
      TransactionType = "4";
      }
      else if (TransactionType == ("G"))
      {
      TransactionType = "5";
      }
      else if (TransactionType == ("H"))
      {
      TransactionType = "6";
      }
      return TransactionType;
      }

      Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      W Offline
      W Offline
      Wastedtalent
      wrote on last edited by
      #2

      What happened to 2 :confused:

      M 1 Reply Last reply
      0
      • W Wastedtalent

        What happened to 2 :confused:

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        Wastedtalent wrote:

        What happened to 2

        That was yesterday - see previous post. I just didn't put "day 2" in the subject line. Marc

        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

        W 1 Reply Last reply
        0
        • M Marc Clifton

          Wastedtalent wrote:

          What happened to 2

          That was yesterday - see previous post. I just didn't put "day 2" in the subject line. Marc

          V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

          W Offline
          W Offline
          Wastedtalent
          wrote on last edited by
          #4

          I meant transaction type

          OriginalGriffO M 2 Replies Last reply
          0
          • M Marc Clifton

            A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

            // Function to genearte the Transaction Type Code
            public string getTransactionType(string TransactionType)
            {
            if (TransactionType == ("A"))
            {
            TransactionType = "1";
            }
            else if (TransactionType == ("B") || TransactionType == ("C"))
            {
            TransactionType = "3";
            }
            else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
            {
            TransactionType = "4";
            }
            else if (TransactionType == ("G"))
            {
            TransactionType = "5";
            }
            else if (TransactionType == ("H"))
            {
            TransactionType = "6";
            }
            return TransactionType;
            }

            Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

            V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

            N Offline
            N Offline
            Nagy Vilmos
            wrote on last edited by
            #5

            I hope you're on a good day rate plus cleaning bills. I can see a lot of coffee getting spilt.

            veni bibi saltavi

            1 Reply Last reply
            0
            • W Wastedtalent

              I meant transaction type

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

              The first rule of Transaction Type 2 Club is: ...

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              "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
              • W Wastedtalent

                I meant transaction type

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #7

                Wastedtalent wrote:

                I meant transaction type

                :laugh: Oops. Don't know. I'll have to see if it's every used in the code! Marc

                V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                1 Reply Last reply
                0
                • M Marc Clifton

                  A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

                  // Function to genearte the Transaction Type Code
                  public string getTransactionType(string TransactionType)
                  {
                  if (TransactionType == ("A"))
                  {
                  TransactionType = "1";
                  }
                  else if (TransactionType == ("B") || TransactionType == ("C"))
                  {
                  TransactionType = "3";
                  }
                  else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
                  {
                  TransactionType = "4";
                  }
                  else if (TransactionType == ("G"))
                  {
                  TransactionType = "5";
                  }
                  else if (TransactionType == ("H"))
                  {
                  TransactionType = "6";
                  }
                  return TransactionType;
                  }

                  Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

                  V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                  J Offline
                  J Offline
                  Jon McKee
                  wrote on last edited by
                  #8

                  "genearte" - Typo on the first line. This is gonna be a good one. string getTransactionType(string TransactionType) - So it's just a return statement? ..... Oh how wrong I was :((

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

                    // Function to genearte the Transaction Type Code
                    public string getTransactionType(string TransactionType)
                    {
                    if (TransactionType == ("A"))
                    {
                    TransactionType = "1";
                    }
                    else if (TransactionType == ("B") || TransactionType == ("C"))
                    {
                    TransactionType = "3";
                    }
                    else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
                    {
                    TransactionType = "4";
                    }
                    else if (TransactionType == ("G"))
                    {
                    TransactionType = "5";
                    }
                    else if (TransactionType == ("H"))
                    {
                    TransactionType = "6";
                    }
                    return TransactionType;
                    }

                    Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

                    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                    Find a positive way of looking at such code: there is no need to waste money for an obfuscator! :-D

                    1 Reply Last reply
                    0
                    • M Marc Clifton

                      A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

                      // Function to genearte the Transaction Type Code
                      public string getTransactionType(string TransactionType)
                      {
                      if (TransactionType == ("A"))
                      {
                      TransactionType = "1";
                      }
                      else if (TransactionType == ("B") || TransactionType == ("C"))
                      {
                      TransactionType = "3";
                      }
                      else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
                      {
                      TransactionType = "4";
                      }
                      else if (TransactionType == ("G"))
                      {
                      TransactionType = "5";
                      }
                      else if (TransactionType == ("H"))
                      {
                      TransactionType = "6";
                      }
                      return TransactionType;
                      }

                      Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

                      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                      H Offline
                      H Offline
                      Harrison Pratt
                      wrote on last edited by
                      #10

                      Good lord ... below is how this might be worked out in Visual Prolog. This sure looks easier to understand, debug and maintain (extend).

                      class predicates
                      getTransInt : ( string ) -> integer determ.
                      clauses
                      getTransInt( S ) = I :-
                      I = transStrInt(S), !.
                      getTransInt( S ) = _ :-
                      stdio::write( "\nUnknown transaction string: ", S ),
                      fail.

                      class predicates
                          transStrInt : ( string ) -> integer determ.
                      clauses
                          transStrInt( "A" ) = 1.
                          transStrInt( "B" ) = 2.
                          transStrInt( "C" ) = 2.
                          transStrInt( "D" ) = 4.
                          transStrInt( "E" ) = 4.
                          transStrInt( "F" ) = 4.
                          transStrInt( "G" ) = 5.
                          transStrInt( "H" ) = 6.
                      
                      G 1 Reply Last reply
                      0
                      • H Harrison Pratt

                        Good lord ... below is how this might be worked out in Visual Prolog. This sure looks easier to understand, debug and maintain (extend).

                        class predicates
                        getTransInt : ( string ) -> integer determ.
                        clauses
                        getTransInt( S ) = I :-
                        I = transStrInt(S), !.
                        getTransInt( S ) = _ :-
                        stdio::write( "\nUnknown transaction string: ", S ),
                        fail.

                        class predicates
                            transStrInt : ( string ) -> integer determ.
                        clauses
                            transStrInt( "A" ) = 1.
                            transStrInt( "B" ) = 2.
                            transStrInt( "C" ) = 2.
                            transStrInt( "D" ) = 4.
                            transStrInt( "E" ) = 4.
                            transStrInt( "F" ) = 4.
                            transStrInt( "G" ) = 5.
                            transStrInt( "H" ) = 6.
                        
                        G Offline
                        G Offline
                        Greg Lovekamp
                        wrote on last edited by
                        #11

                        I trust there is sarcasm in there. I can read this and get that it is similar though wrong if based upon the original code snippet - nothing in the original maps with 2. The original code snippet is certainly not the most elegant; however, it would be clear to anyone looking at it what is being done: my dog would be able to figure out that code (and quite possibly have written it). Prolog is much more of an "acquired" taste. Personally, while I try to make code look a little better than the original author did, the important concept (over efficiency and elegance) is that the next poor schmuck who needs to maintain that code can determine what it is doing very quickly. Usually, the time code needs modified is when something has broken and the results were already needed but were prevented by such failure. At such times, while trying to determine what the various pieces of code do, elegance has NO value; efficiency has NO value. Only being able to determine what the code is trying to do is of ANY importance, so CLARITY is paramount.

                        H 1 Reply Last reply
                        0
                        • G Greg Lovekamp

                          I trust there is sarcasm in there. I can read this and get that it is similar though wrong if based upon the original code snippet - nothing in the original maps with 2. The original code snippet is certainly not the most elegant; however, it would be clear to anyone looking at it what is being done: my dog would be able to figure out that code (and quite possibly have written it). Prolog is much more of an "acquired" taste. Personally, while I try to make code look a little better than the original author did, the important concept (over efficiency and elegance) is that the next poor schmuck who needs to maintain that code can determine what it is doing very quickly. Usually, the time code needs modified is when something has broken and the results were already needed but were prevented by such failure. At such times, while trying to determine what the various pieces of code do, elegance has NO value; efficiency has NO value. Only being able to determine what the code is trying to do is of ANY importance, so CLARITY is paramount.

                          H Offline
                          H Offline
                          Harrison Pratt
                          wrote on last edited by
                          #12

                          See how easy it is to spot errors when you use table-lookup code! :-D

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

                            // Function to genearte the Transaction Type Code
                            public string getTransactionType(string TransactionType)
                            {
                            if (TransactionType == ("A"))
                            {
                            TransactionType = "1";
                            }
                            else if (TransactionType == ("B") || TransactionType == ("C"))
                            {
                            TransactionType = "3";
                            }
                            else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
                            {
                            TransactionType = "4";
                            }
                            else if (TransactionType == ("G"))
                            {
                            TransactionType = "5";
                            }
                            else if (TransactionType == ("H"))
                            {
                            TransactionType = "6";
                            }
                            return TransactionType;
                            }

                            Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

                            V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                            Unfortunately, such code is still being written. I came across something like that last year (written just weeks earlier). This one is actually pretty clean compared to that one. It had about 10 types and each type could results in 3 actions, so that was an 10x3 if else branch :sigh: Why don't these programmers ever stop to think "just because I can does it mean I should?" X| Or maybe they do, but their lack of knowledge prevents them from coming up with anything better and their lack of knowledge about their lack of knowledge prevents them from asking someone else for help... Ignorance is bliss and crappy code I guess.

                            Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

                            1 Reply Last reply
                            0
                            • M Marc Clifton

                              A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.

                              // Function to genearte the Transaction Type Code
                              public string getTransactionType(string TransactionType)
                              {
                              if (TransactionType == ("A"))
                              {
                              TransactionType = "1";
                              }
                              else if (TransactionType == ("B") || TransactionType == ("C"))
                              {
                              TransactionType = "3";
                              }
                              else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
                              {
                              TransactionType = "4";
                              }
                              else if (TransactionType == ("G"))
                              {
                              TransactionType = "5";
                              }
                              else if (TransactionType == ("H"))
                              {
                              TransactionType = "6";
                              }
                              return TransactionType;
                              }

                              Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map. And putting strings in parenthesis definitely improves the confidence of the equality test! Marc

                              V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                              J Offline
                              J Offline
                              Jorgen Andersson
                              wrote on last edited by
                              #14

                              Maybe a bit masochistic, but I'm waiting for the next one. :-\

                              Wrong is evil and must be defeated. - Jeff Ello

                              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