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. Beautiful code...

Beautiful code...

Scheduled Pinned Locked Moved The Weird and The Wonderful
13 Posts 10 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.
  • K Offline
    K Offline
    Kieryn Phipps
    wrote on last edited by
    #1

    ... discovered in a legacy app.

        public string GetCode(string ProjectCode, string id)
        {
    
            try
            {
    
                int len = ProjectCode.Length + id.Length;
                int rem = 10 - len;
                switch (rem)
                {
                    case 1:
                        ProjectCode = ProjectCode + "0" + id;
                        break;
                    case 2:
                        ProjectCode = ProjectCode + "00" + id;
                        break;
                    case 3:
                        ProjectCode = ProjectCode + "000" + id;
                        break;
                    case 4:
                        ProjectCode = ProjectCode + "0000" + id;
                        break;
                    case 5:
                        ProjectCode = ProjectCode + "00000" + id;
                        break;
                    case 6:
                        ProjectCode = ProjectCode + "000000" + id;
                        break;
                }
            }
            catch (Exception ex)
            {
    
            }
    
            return ProjectCode;
    
        }
    
    RaviBeeR Sander RosselS J J K 7 Replies Last reply
    0
    • K Kieryn Phipps

      ... discovered in a legacy app.

          public string GetCode(string ProjectCode, string id)
          {
      
              try
              {
      
                  int len = ProjectCode.Length + id.Length;
                  int rem = 10 - len;
                  switch (rem)
                  {
                      case 1:
                          ProjectCode = ProjectCode + "0" + id;
                          break;
                      case 2:
                          ProjectCode = ProjectCode + "00" + id;
                          break;
                      case 3:
                          ProjectCode = ProjectCode + "000" + id;
                          break;
                      case 4:
                          ProjectCode = ProjectCode + "0000" + id;
                          break;
                      case 5:
                          ProjectCode = ProjectCode + "00000" + id;
                          break;
                      case 6:
                          ProjectCode = ProjectCode + "000000" + id;
                          break;
                  }
              }
              catch (Exception ex)
              {
      
              }
      
              return ProjectCode;
      
          }
      
      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      I have to compliment the author on writing bulletproof code - the catch all is awesome! /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      W D 2 Replies Last reply
      0
      • K Kieryn Phipps

        ... discovered in a legacy app.

            public string GetCode(string ProjectCode, string id)
            {
        
                try
                {
        
                    int len = ProjectCode.Length + id.Length;
                    int rem = 10 - len;
                    switch (rem)
                    {
                        case 1:
                            ProjectCode = ProjectCode + "0" + id;
                            break;
                        case 2:
                            ProjectCode = ProjectCode + "00" + id;
                            break;
                        case 3:
                            ProjectCode = ProjectCode + "000" + id;
                            break;
                        case 4:
                            ProjectCode = ProjectCode + "0000" + id;
                            break;
                        case 5:
                            ProjectCode = ProjectCode + "00000" + id;
                            break;
                        case 6:
                            ProjectCode = ProjectCode + "000000" + id;
                            break;
                    }
                }
                catch (Exception ex)
                {
        
                }
        
                return ProjectCode;
        
            }
        
        Sander RosselS Offline
        Sander RosselS Offline
        Sander Rossel
        wrote on last edited by
        #3

        ProjectCode should be camelCased, other than that I don't see what's wrong with it ;p

        Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

        Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

        Regards, Sander

        W 1 Reply Last reply
        0
        • K Kieryn Phipps

          ... discovered in a legacy app.

              public string GetCode(string ProjectCode, string id)
              {
          
                  try
                  {
          
                      int len = ProjectCode.Length + id.Length;
                      int rem = 10 - len;
                      switch (rem)
                      {
                          case 1:
                              ProjectCode = ProjectCode + "0" + id;
                              break;
                          case 2:
                              ProjectCode = ProjectCode + "00" + id;
                              break;
                          case 3:
                              ProjectCode = ProjectCode + "000" + id;
                              break;
                          case 4:
                              ProjectCode = ProjectCode + "0000" + id;
                              break;
                          case 5:
                              ProjectCode = ProjectCode + "00000" + id;
                              break;
                          case 6:
                              ProjectCode = ProjectCode + "000000" + id;
                              break;
                      }
                  }
                  catch (Exception ex)
                  {
          
                  }
          
                  return ProjectCode;
          
              }
          
          J Offline
          J Offline
          jgakenhe
          wrote on last edited by
          #4

          Nothing like beautiful legacy code, very beautiful indeed.

          1 Reply Last reply
          0
          • K Kieryn Phipps

            ... discovered in a legacy app.

                public string GetCode(string ProjectCode, string id)
                {
            
                    try
                    {
            
                        int len = ProjectCode.Length + id.Length;
                        int rem = 10 - len;
                        switch (rem)
                        {
                            case 1:
                                ProjectCode = ProjectCode + "0" + id;
                                break;
                            case 2:
                                ProjectCode = ProjectCode + "00" + id;
                                break;
                            case 3:
                                ProjectCode = ProjectCode + "000" + id;
                                break;
                            case 4:
                                ProjectCode = ProjectCode + "0000" + id;
                                break;
                            case 5:
                                ProjectCode = ProjectCode + "00000" + id;
                                break;
                            case 6:
                                ProjectCode = ProjectCode + "000000" + id;
                                break;
                        }
                    }
                    catch (Exception ex)
                    {
            
                    }
            
                    return ProjectCode;
            
                }
            
            J Offline
            J Offline
            jeron1
            wrote on last edited by
            #5

            Is the original author still around? umm not that wou'd want to hunt him/her down and hurt them or anything.... :^)

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            K 1 Reply Last reply
            0
            • K Kieryn Phipps

              ... discovered in a legacy app.

                  public string GetCode(string ProjectCode, string id)
                  {
              
                      try
                      {
              
                          int len = ProjectCode.Length + id.Length;
                          int rem = 10 - len;
                          switch (rem)
                          {
                              case 1:
                                  ProjectCode = ProjectCode + "0" + id;
                                  break;
                              case 2:
                                  ProjectCode = ProjectCode + "00" + id;
                                  break;
                              case 3:
                                  ProjectCode = ProjectCode + "000" + id;
                                  break;
                              case 4:
                                  ProjectCode = ProjectCode + "0000" + id;
                                  break;
                              case 5:
                                  ProjectCode = ProjectCode + "00000" + id;
                                  break;
                              case 6:
                                  ProjectCode = ProjectCode + "000000" + id;
                                  break;
                          }
                      }
                      catch (Exception ex)
                      {
              
                      }
              
                      return ProjectCode;
              
                  }
              
              K Offline
              K Offline
              KarstenK
              wrote on last edited by
              #6

              The missing default handling and error handling (len >10) the mean exception handling shows me that some Visual Basic coder was on the loose. :~

              Press F1 for help or google it. Greetings from Germany

              Sander RosselS 1 Reply Last reply
              0
              • RaviBeeR RaviBee

                I have to compliment the author on writing bulletproof code - the catch all is awesome! /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                W Offline
                W Offline
                WiganLatics
                wrote on last edited by
                #7

                "What? It errored? Where? I don't see any errors? I'm sure I covered/hid all the errors..." ;P

                1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  ProjectCode should be camelCased, other than that I don't see what's wrong with it ;p

                  Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

                  Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

                  Regards, Sander

                  W Offline
                  W Offline
                  WiganLatics
                  wrote on last edited by
                  #8

                  Sander Rossel wrote:

                  I don't see what's wrong with it

                  The only bit that's wrong is the stuff between the first and last bracket... ;P

                  1 Reply Last reply
                  0
                  • J jeron1

                    Is the original author still around? umm not that wou'd want to hunt him/her down and hurt them or anything.... :^)

                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                    K Offline
                    K Offline
                    Kieryn Phipps
                    wrote on last edited by
                    #9

                    No, they left long ago. What confuses me the most is how you can know enough code to be able to write something like that, but not enough to know how to do it without the ridiculous switch statement. It's like a weird ignorance knife-edge.

                    1 Reply Last reply
                    0
                    • K KarstenK

                      The missing default handling and error handling (len >10) the mean exception handling shows me that some Visual Basic coder was on the loose. :~

                      Press F1 for help or google it. Greetings from Germany

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

                      It's friggin C# code and you STILL have to bash VB? Sounds to me like a C# dev who can't admit there are actually really very bad C# coders out there. C# coders who are, if I dare say so, even worse than a lot of VB programmers out there :) And that comes, of course, from an ex-VB coder, who has seen crap code in both VB and C# (and both make you want to spoon your eyes out) :)

                      Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

                      Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

                      Regards, Sander

                      1 Reply Last reply
                      0
                      • K Kieryn Phipps

                        ... discovered in a legacy app.

                            public string GetCode(string ProjectCode, string id)
                            {
                        
                                try
                                {
                        
                                    int len = ProjectCode.Length + id.Length;
                                    int rem = 10 - len;
                                    switch (rem)
                                    {
                                        case 1:
                                            ProjectCode = ProjectCode + "0" + id;
                                            break;
                                        case 2:
                                            ProjectCode = ProjectCode + "00" + id;
                                            break;
                                        case 3:
                                            ProjectCode = ProjectCode + "000" + id;
                                            break;
                                        case 4:
                                            ProjectCode = ProjectCode + "0000" + id;
                                            break;
                                        case 5:
                                            ProjectCode = ProjectCode + "00000" + id;
                                            break;
                                        case 6:
                                            ProjectCode = ProjectCode + "000000" + id;
                                            break;
                                    }
                                }
                                catch (Exception ex)
                                {
                        
                                }
                        
                                return ProjectCode;
                        
                            }
                        
                        P Offline
                        P Offline
                        PauloJuanShirt
                        wrote on last edited by
                        #11

                        I'd post a legacy code snippet but I'd be sharing all the production connection strings they hardcoded at every single db connection. :mad: I seriously wished I could build a terminator to go back in time and shoot the coder in questions parents. :laugh:

                        1 Reply Last reply
                        0
                        • K Kieryn Phipps

                          ... discovered in a legacy app.

                              public string GetCode(string ProjectCode, string id)
                              {
                          
                                  try
                                  {
                          
                                      int len = ProjectCode.Length + id.Length;
                                      int rem = 10 - len;
                                      switch (rem)
                                      {
                                          case 1:
                                              ProjectCode = ProjectCode + "0" + id;
                                              break;
                                          case 2:
                                              ProjectCode = ProjectCode + "00" + id;
                                              break;
                                          case 3:
                                              ProjectCode = ProjectCode + "000" + id;
                                              break;
                                          case 4:
                                              ProjectCode = ProjectCode + "0000" + id;
                                              break;
                                          case 5:
                                              ProjectCode = ProjectCode + "00000" + id;
                                              break;
                                          case 6:
                                              ProjectCode = ProjectCode + "000000" + id;
                                              break;
                                      }
                                  }
                                  catch (Exception ex)
                                  {
                          
                                  }
                          
                                  return ProjectCode;
                          
                              }
                          
                          K Online
                          K Online
                          kmoorevs
                          wrote on last edited by
                          #12

                          Woah! I saw 'rem' and started reading it as a comment! :laugh:

                          "Go forth into the source" - Neal Morse

                          1 Reply Last reply
                          0
                          • RaviBeeR RaviBee

                            I have to compliment the author on writing bulletproof code - the catch all is awesome! /ravi

                            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                            D Offline
                            D Offline
                            David A Gray
                            wrote on last edited by
                            #13

                            I had to go back and look. Yes, it's awesome, and about as enlightened as ignoring the return code of a method or function. Catch exception and throw it away. Why even bother with naming it?

                            David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                            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