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(); }
    }

    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
                            • Sander RosselS Sander Rossel

                              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 Offline
                              M Offline
                              MarvinMartian
                              wrote on last edited by
                              #22

                              I certainly agree that the coder was inept. On the subject of developer vs programmer. Even though my title is,"Sr Developer Architect" I consider myself a programmer. I'm as comfortable using VI and make as I am Eclipse or Visual Studio. Therein lies the difference to me. I feel the word developer connotes one who requires the modern IDE with all it's pop-up hints, which 95% of the time just get in my way. Then there is VI where one never has to take their hands of the keyboard to do virtually everything possible when it comes to the programming process. I live in both worlds in my efforts. Now all of that is entirely subjective observation so it's really not debatable. But I would be interested in your thoughts. I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

                              Sander RosselS 1 Reply Last reply
                              0
                              • M MarvinMartian

                                I certainly agree that the coder was inept. On the subject of developer vs programmer. Even though my title is,"Sr Developer Architect" I consider myself a programmer. I'm as comfortable using VI and make as I am Eclipse or Visual Studio. Therein lies the difference to me. I feel the word developer connotes one who requires the modern IDE with all it's pop-up hints, which 95% of the time just get in my way. Then there is VI where one never has to take their hands of the keyboard to do virtually everything possible when it comes to the programming process. I live in both worlds in my efforts. Now all of that is entirely subjective observation so it's really not debatable. But I would be interested in your thoughts. I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

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

                                MarvinMartian wrote:

                                I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

                                Ehhh... What's up doc? ;p I always felt a programmer to be more like someone who writes code that he is told to write while a developer thinks of how the code should be written and can write it too (somewhere between a programmer and an architect maybe?). I think my contract says I'm a software developer just like all my colleagues, but when it comes to coding new libraries and thinking about architecture I am a lot better than my colleagues who couldn't name a single Design Pattern or SOLID principle. And when it comes to that you are, judging from your title, far more skilled and knowledged than me even though you consider yourself a programmer. I think everyone who writes code should have a basic, but solid understanding of architecture no matter their title. I think programmers and developers work at a small part of software while architects overlook the entire project. But then again, I work at a small company that doesn't have architects :)

                                It's an OO world.

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

                                M 1 Reply Last reply
                                0
                                • Sander RosselS Sander Rossel

                                  MarvinMartian wrote:

                                  I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

                                  Ehhh... What's up doc? ;p I always felt a programmer to be more like someone who writes code that he is told to write while a developer thinks of how the code should be written and can write it too (somewhere between a programmer and an architect maybe?). I think my contract says I'm a software developer just like all my colleagues, but when it comes to coding new libraries and thinking about architecture I am a lot better than my colleagues who couldn't name a single Design Pattern or SOLID principle. And when it comes to that you are, judging from your title, far more skilled and knowledged than me even though you consider yourself a programmer. I think everyone who writes code should have a basic, but solid understanding of architecture no matter their title. I think programmers and developers work at a small part of software while architects overlook the entire project. But then again, I work at a small company that doesn't have architects :)

                                  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
                                  #24

                                  It's interesting that we have the exact opposite view of what it is we think we are. LOL It may be that when I started, there were no developers, only programmers. While in high school in the late 60's I wrote my first FORTRAN programs. They did nothing but they did spark an interest. I became a mechanical engineer, primarily for the $$, however I continued programming my stress analysis in FORTRAN and gradually began to like that more than building amazing things out of steel etc. I now occasionally do electronic design, embedded coding, real time data collection from operating room instrumentation all while "architecting" financial solutions using SOA at a large life insurance company. I'm not boasting by any means. There is much I don't know. That's why I'm about to take a crash (8 week) course "Advanced Java Programming". Just so I can put it on my resume. (And take the official certification. You gotta know all the buzz words and acronyms.) In fact I learn something from every project I work on. I'm currently discovering Android development having just installed everything I need. No iOS for me, I've seen "objective C", it ain't C! Also there is that $100 here and there and you can only develop on a Mac. (You can run iOS in VMWare but it crashes if the app you're running wants to identify the Mac you're running on!) I am also proud of the fact that at age 63 I still have the urge to do this and learn more. Now that is the boast! LOL I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

                                  Sander RosselS 1 Reply Last reply
                                  0
                                  • M MarvinMartian

                                    It's interesting that we have the exact opposite view of what it is we think we are. LOL It may be that when I started, there were no developers, only programmers. While in high school in the late 60's I wrote my first FORTRAN programs. They did nothing but they did spark an interest. I became a mechanical engineer, primarily for the $$, however I continued programming my stress analysis in FORTRAN and gradually began to like that more than building amazing things out of steel etc. I now occasionally do electronic design, embedded coding, real time data collection from operating room instrumentation all while "architecting" financial solutions using SOA at a large life insurance company. I'm not boasting by any means. There is much I don't know. That's why I'm about to take a crash (8 week) course "Advanced Java Programming". Just so I can put it on my resume. (And take the official certification. You gotta know all the buzz words and acronyms.) In fact I learn something from every project I work on. I'm currently discovering Android development having just installed everything I need. No iOS for me, I've seen "objective C", it ain't C! Also there is that $100 here and there and you can only develop on a Mac. (You can run iOS in VMWare but it crashes if the app you're running wants to identify the Mac you're running on!) I am also proud of the fact that at age 63 I still have the urge to do this and learn more. Now that is the boast! LOL I'm going to destroy the Earth with my Illudium Q-36 Explosive Space Modulator! - Marvin Martian

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

                                    I started programming... about one and a half year ago :) Started at a small company where SOLID and Design Patterns were unheard of and where Interface was a curse word! On CP I learned about these things and I could convince my employers to work more Object Oriented (which led to quite some fights between me and my employers who probably felt attacked that someone who just started told them what to do). So we had the junior (me) telling the big senior (my boss) what to do. Since then I don't care much for titles anymore. If my boss is a senior (even self-proclaimed) then I must be the über-senior... After a year :) I guess it all depends on where you work and who you work with. If I moved to a big company now I'd be the junior again with no education or certification whatsoever. In the end it's not about your title or education, it's about what you know and what you can do that counts. Unfortunately it sometimes seems title and education are more important in this society... Luckily I do still hold an MA title in Media and Journalism, although that doesn't get me very far in programming :)

                                    MarvinMartian wrote:

                                    I am also proud of the fact that at age 63 I still have the urge to do this and learn more.   Now that is the boast!   LOL

                                    And rightfully so! :) Many people of that age await their retirement and shun all kinds of change because it's easier for them to stick to what they know (I know a few)...

                                    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(); }
                                      }

                                      D Offline
                                      D Offline
                                      dawmail333
                                      wrote on last edited by
                                      #26

                                      Can see this happening in Python:

                                      if code.length in [0,1,2,3,4,6,7]:
                                      ....

                                      Don't forget to rate my post if it helped! ;) "He has no enemies, but is intensely disliked by his friends." "His mother should have thrown him away, and kept the stork." "There's nothing wrong with you that reincarnation won't cure." "He loves nature, in spite of what it did to him."

                                      1 Reply Last reply
                                      0
                                      • R reilly96

                                        or simply set the max lenght of the textbox = 5

                                        A Offline
                                        A Offline
                                        Ameen AboDabash
                                        wrote on last edited by
                                        #27

                                        In order to write secure code... whatever how important is your input, do Not trust the client, validate input data even @ back-end think about client Validation just like good interface, to ease user life, to reduce hits on the server... no more :)

                                        Last Egyptian Physicist www.ameen.rr.nu

                                        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
                                          #28

                                          Naerling wrote:

                                          Throw New Exception("Code should be 5 characters long.")

                                          Well, shouldn't error change accordingly?

                                          Throw New Exception("Code should be 5 characters long or should exactly not be 6 characters or oh wait, not exactly 7 characters too, anything other than that.")

                                          - Just that something can be done, doesn't mean it should be done. Respect developers and their efforts! Jk

                                          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