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. Code should be 5 or anything above 7 long...

Code should be 5 or anything above 7 long...

Scheduled Pinned Locked Moved The Weird and The Wonderful
cssquestion
30 Posts 17 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.
  • Sander RosselS Sander Rossel

    Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

    ' This code should always be 5 characters long.
    If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
    Throw New Exception("Code should be 5 characters long.")
    End If

    My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

    It's an OO world.

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

    J Offline
    J Offline
    Jochen Arndt
    wrote on last edited by
    #2

    At least the programmer added a comment stating what the code should do. :rolleyes:

    Sander RosselS 1 Reply Last reply
    0
    • J Jochen Arndt

      At least the programmer added a comment stating what the code should do. :rolleyes:

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

      If only the code did what was commented... Perhaps requirements changed and the comment is wrong? :rolleyes:

      It's an OO world.

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

      1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

        ' This code should always be 5 characters long.
        If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
        Throw New Exception("Code should be 5 characters long.")
        End If

        My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

        It's an OO world.

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

        C Offline
        C Offline
        ChrisNic
        wrote on last edited by
        #4

        Maybe the comment and the error message should have been ' This code should always be 5 characters or more than 7 characters.

        0 1 Reply Last reply
        0
        • Sander RosselS Sander Rossel

          Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

          ' This code should always be 5 characters long.
          If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
          Throw New Exception("Code should be 5 characters long.")
          End If

          My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

          It's an OO world.

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

          B Offline
          B Offline
          biagiop1986
          wrote on last edited by
          #5

          OMG ... I can't look at it. I'm feeling sick. Thank you for ruining my day! :-)

          1 Reply Last reply
          0
          • Sander RosselS Sander Rossel

            Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

            ' This code should always be 5 characters long.
            If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
            Throw New Exception("Code should be 5 characters long.")
            End If

            My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

            It's an OO world.

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

            R Offline
            R Offline
            reilly96
            wrote on last edited by
            #6

            or simply set the max lenght of the textbox = 5

            A 1 Reply Last reply
            0
            • Sander RosselS Sander Rossel

              Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

              ' This code should always be 5 characters long.
              If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
              Throw New Exception("Code should be 5 characters long.")
              End If

              My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

              It's an OO world.

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

              G Offline
              G Offline
              Gary Huck
              wrote on last edited by
              #7

              What? That's all you got!? I've seen this s**tstuff for years! ;)

              1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                ' This code should always be 5 characters long.
                If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                Throw New Exception("Code should be 5 characters long.")
                End If

                My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                It's an OO world.

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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                What's so bad about being explicit about what you don't accept as a valid value? :) Besides that, we also have a lot of literal values here. Checking the length against a constant or some configuration entry can be helpful, especially because the code's valid length may have changed over time. Throwing a plain vanilla exception with a literal message also is sloppy. It's not that hard to derive custom exeption classes for your application and would help in avoiding Pokemon exception handling.

                I'm invincible, I can't be vinced

                1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                  ' This code should always be 5 characters long.
                  If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                  Throw New Exception("Code should be 5 characters long.")
                  End If

                  My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                  It's an OO world.

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

                  Y Offline
                  Y Offline
                  YvesDaoust
                  wrote on last edited by
                  #9

                  My fix :-)

                  ' Code should be 5 or anything above 7 long
                  If IsPrime(90*code.Length+61) Then
                  Throw New Exception("Code should be 5 or anything above 7 characters long.")
                  End If

                  C 1 Reply Last reply
                  0
                  • Sander RosselS Sander Rossel

                    Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                    ' This code should always be 5 characters long.
                    If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                    Throw New Exception("Code should be 5 characters long.")
                    End If

                    My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                    It's an OO world.

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

                    Z Offline
                    Z Offline
                    ZurdoDev
                    wrote on last edited by
                    #10

                    Hey, VB is great. It is much easier than C#. I do everything in C# but don't hate on VB.

                    S 1 Reply Last reply
                    0
                    • Z ZurdoDev

                      Hey, VB is great. It is much easier than C#. I do everything in C# but don't hate on VB.

                      S Offline
                      S Offline
                      Saksida Bojan
                      wrote on last edited by
                      #11

                      Difference between VB or C# is a syntax, thanks to the .net framework. But if you ask what do I think is that C# is better. But ultimately it comes toward preference.

                      1 Reply Last reply
                      0
                      • Y YvesDaoust

                        My fix :-)

                        ' Code should be 5 or anything above 7 long
                        If IsPrime(90*code.Length+61) Then
                        Throw New Exception("Code should be 5 or anything above 7 characters long.")
                        End If

                        C Offline
                        C Offline
                        Chris Meech
                        wrote on last edited by
                        #12

                        Are you a member of Obfuscators Anonymous. :)

                        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                        Y 1 Reply Last reply
                        0
                        • Sander RosselS Sander Rossel

                          Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                          ' This code should always be 5 characters long.
                          If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                          Throw New Exception("Code should be 5 characters long.")
                          End If

                          My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                          It's an OO world.

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

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          Just goes to show that some programmers haven't got a clue! :doh:

                          A perpetual holiday is a good working definition of hell.

                          1 Reply Last reply
                          0
                          • Sander RosselS Sander Rossel

                            Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                            ' This code should always be 5 characters long.
                            If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                            Throw New Exception("Code should be 5 characters long.")
                            End If

                            My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                            It's an OO world.

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

                            B Offline
                            B Offline
                            bwallan
                            wrote on last edited by
                            #14

                            "code.Length <> 5" is far too easy!

                            Sander RosselS 1 Reply Last reply
                            0
                            • B bwallan

                              "code.Length <> 5" is far too easy!

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

                              Indeed...

                              Dim counter As Long ' This could be a REAL long code!
                              For Each c As Char In code
                              counter = counter + 1
                              End If
                              If counter < 5 Then
                              Throw New Exception("The code is to short!")
                              ElseIf counter = 6
                              Throw New Exception("The code is to long!")
                              ElseIf counter = 7
                              Throw New Exception("The code is to long!")
                              Else
                              ' Some code here :)
                              End If

                              It's an OO world.

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

                              B T 2 Replies Last reply
                              0
                              • Sander RosselS Sander Rossel

                                Indeed...

                                Dim counter As Long ' This could be a REAL long code!
                                For Each c As Char In code
                                counter = counter + 1
                                End If
                                If counter < 5 Then
                                Throw New Exception("The code is to short!")
                                ElseIf counter = 6
                                Throw New Exception("The code is to long!")
                                ElseIf counter = 7
                                Throw New Exception("The code is to long!")
                                Else
                                ' Some code here :)
                                End If

                                It's an OO world.

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

                                B Offline
                                B Offline
                                bwallan
                                wrote on last edited by
                                #16

                                Much better! LOL bwa P.S.: Does the happy face get output??

                                Sander RosselS 1 Reply Last reply
                                0
                                • B bwallan

                                  Much better! LOL bwa P.S.: Does the happy face get output??

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

                                  The happy face is a hidden VB feature in .NET 4 ;p

                                  It's an OO world.

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

                                  1 Reply Last reply
                                  0
                                  • C Chris Meech

                                    Are you a member of Obfuscators Anonymous. :)

                                    Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                                    Y Offline
                                    Y Offline
                                    YvesDaoust
                                    wrote on last edited by
                                    #18

                                    Yeah, at the Novice rank. I hope to go up to Apprentice this year.

                                    1 Reply Last reply
                                    0
                                    • C ChrisNic

                                      Maybe the comment and the error message should have been ' This code should always be 5 characters or more than 7 characters.

                                      0 Offline
                                      0 Offline
                                      0bx
                                      wrote on last edited by
                                      #19

                                      Then he should correct the exception too: "Code should be 5 characters long OR longer than 7."

                                      Giraffes are not real.

                                      1 Reply Last reply
                                      0
                                      • Sander RosselS Sander Rossel

                                        Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...

                                        ' This code should always be 5 characters long.
                                        If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
                                        Throw New Exception("Code should be 5 characters long.")
                                        End If

                                        My guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the Or code.length = 6 part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check if code.Length <> 5? :rolleyes:

                                        It's an OO world.

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

                                        M Offline
                                        M Offline
                                        MarvinMartian
                                        wrote on last edited by
                                        #20

                                        These instances of code changes were not done by a programmer. A developer maybe, but not a programmer.

                                        Sander RosselS 1 Reply Last reply
                                        0
                                        • M MarvinMartian

                                          These instances of code changes were not done by a programmer. A developer maybe, but not a programmer.

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

                                          Perhaps we could debate a bit on the difference between programmer and developer? :) Anyway, whoever made those changes had no clue what they were doing so it seems ;)

                                          It's an OO world.

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

                                          M 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