• Bob (unregistered) in reply to SR
    SR:
    Newb:
    Mandatory summarization: Got paid to port bad code, found bad code.

    Well done. I should stop reading the stories and just wait for some joyless wonk to summarise it.

    Hey, there's no need to be mean.

    Some people actually have nothing better to do with their lives than read every last story posted on this site and then explain that they would have done better, only this week they were too busy taking care of their bunions to register a URL and rent some web hosting space.

    But even though the universe has conspired to sabotage their efforts to create the wonderful literary masterpiece of tragedy that they want this site to be, at least they manage to find some time to remind us all that we're failing to maintain the proper level of entertainment that they desire in their life.

    We should be glad we can give them something to complain about, and thus feel like their opinion is appreciated.

  • Ph4g3 (unregistered) in reply to Anonymously Yours

    Looks like your a fan of redundancy. Probably could have taken a few lines out of your own comment and still gotten the same point across =P

  • chris (unregistered) in reply to isDigit
    isDigit:
    Maybe it is just me but "function isDigit(digit)" may be ok depending on the validation required. So for those suggesting isNaN() and !isNaN() try calling isNaN("0xff") and see what result you get.

    Yes!

    I would go even further than this, though. The purpose of isDigit seems to be to check if a character is a digit character (0 to 9). So it shouldn't accept hyphens, or decimal points, or indeed strings with multiple characters.

    All of which isNaN will treat as numbers.

    isDigit() is not a WTF. It's not how I would code it, but not a WTF.

  • wt (unregistered)

    I especially like the customization of an 'isNumeric()' like function

  • Indrora (unregistered)

    I wont happen to mention the horrible thing that I ran into at a client site. it was done by a 'professional' (of whoms name i will not disclose) and was as follows: (line breaks added so that its not all on ONE line...

    "/^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+
    (ad|ae|aero|af|ag|ai|al
    |am|an|ao|aq|ar|arpa|as|at|au|aw
    |az|ba|bb|bd|be|bf|bg|bh|bi|biz
    |bj|bm|bn|bo|br|bs|bt|bv|bw|by
    |bz|ca|cc|cd|cf|cg|ch|ci
    |ck|cl|cm|cn|co|com|coop|cr|cs
    |cu|cv|cx|cy|cz|de|dj|dk|dm|do
    |dz|ec|edu|ee|eg|eh|er|es
    |et|eu|fi|fj|fk|fm|fo|fr|ga
    |gb|gd|ge|gf|gh|gi|gl|gm|gn
    |gov|gp|gq|gr|gs|gt|gu|gw|gy|hk
    |hm|hn|hr|ht|hu|id|ie|il|in
    |info|int|io|iq|ir|is|it|jm
    |jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw
    |ky|kz|la|lb|lc|li|lk|lr|ls|lt
    |lu|lv|ly|ma|mc|md|mg|mh|mil|mk
    |ml|mm|mn|mo|mp|mq|mr|ms
    |mt|mu|museum|mv|mw|mx|my|mz|na
    |name|nc|ne|net|nf|ng|ni|nl|no
    |np|nr|nt|nu|nz|om|org|pa
    |pe|pf|pg|ph|pk|pl|pm|pn|pr|pro
    |ps|pt|pw|py|qa|re|ro|ru|rw|sa
    |sb|sc|sd|se|sg|sh|si|sj
    |sk|sl|sm|sn|so|sr|st|su|sv|sy
    |sz|tc|td|tf|tg|th|tj|tk|tm|tn
    |to|tp|tr|tt|tv|tw|tz|ua|ug
    |uk|um|us|uy|uz|va|vc|ve|vg
    |vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)
    |(([0-9][0-9]?|[0-1][0-9][0-9]
    |[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))"
    

    This was run using a custom regex framework written in javascript, as well as one on the backend written in PHP.

    ... Needless to say, I took out the javascript regex, made the custom regex engine run preg, and went along my business. I'm sure there's a more efficent way to do it but I was too rusty on my regex's to make it work.

  • Mister Mister (unregistered) in reply to Anonymously Yours

    Repetition is very good. Repetition is very good. Repetition is very, very, very, very, good, good, good. Very, very good. Usually, I...

    Second verse, same as the first!

  • Dave (unregistered) in reply to Anonymously Yours
    Anonymously Yours:
    I don't see an issue with this code. So what if there's a bit of redundancy and unusual customization specific to the task? It's easy to update without breaking anything.

    *snip

    Why feed this troll Alex ?

  • (cs) in reply to Indrora
    Indrora:
    I wont happen to mention the horrible thing that I ran into at a client site. it was done by a 'professional' (of whoms name i will not disclose) and was as follows:
    And the WTF is that you can't decipher regex longer than 10 characters? In fact, that regex was pretty short if you ignore the list of domains (IMHO absolutely OK). I don't see any problems with that.
    Indrora:
    This was run using a custom regex framework written in javascript, as well as one on the backend written in PHP. ... Needless to say, I took out the javascript regex, made the custom regex engine run preg, and went along my business.

    Although having custom regex engine sounds like a WTF, it's generally the only way to make sure the regex behaves the same in all cases (probably not important in this case).

    The fact that the validation is done both on the client and the server is absolutely correct: validation on client saves roundtrip to server in a case that the input field contains garbage and the validation on server is always needed, because you cannot trust data from the client. The fact that you are proud that you've removed validation on client is the biggest WTF here.

  • franz ferdinand (unregistered) in reply to Beldar the Phantom Replier
    Beldar the Phantom Replier:
    function isDigit(digit)
    {
        var charOk = "0123456789";
        return !(charOk.indexOf(digit) == -1)
    }
    

    function isAlphaNumeric(digit) { var charOk = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; return !(charOk.indexOf(digit) == -1) }

    What is so bad about these two functions? Are they really WTF worthy?

    I could understand if either of the soft-coded strings were missing some digits or letters (respectively), but I must just be missing the WTF moment here.

    As another commenter said, there is a function in the language that does this already.

    Now please allow me to explain why this is a WTF.

    By the time I had spent my first twenty hours programming, I had learned that you don't tell whether something is Alpha/Numeric by looking up every character in an array (or string - they're the same thing). That's retarded AND slow AND the performance varies depending on which character you are looking at at the time.

    If there wasn't a built-in function, you would do something like this (in VB):

    Function IsAlpha(str As String) as Boolean
         Dim x as Long, TempAsc as Long
    
         IsAlpha = True
    
         For x = 1 to Len(str)
              TempAsc = Asc(Mid$(str,x,1))
              Select Case TempAsc
                   Case < 48
                        IsAlpha = False
                        Exit For
                   Case > 122
                        IsAlpha = False
                        Exit For
                   Case Else
                        If TempAsc > 57 And TempAsc < 65 Then
                             IsAlpha = False
                             Exit For
                        End If
              End Select
         Next x
    End Function

    What you DON'T do is compare each byte in your string to a validation list, unless you're making something more complex than this project.

  • franz ferdinand (unregistered)

    To make it more clear why this is a WTF, they could have re-written the code like this to no ill effect:

    Function IsAlpha(str as String) as Boolean
         ReturnValue = True
         For x = 1 to Len(str)
              tempchar = Mid$(str,x,1)
              If tempchar <> "A" And tempchar <> "B".... Then
                   ReturnValue = False
              EndIf 
         Next x
    
         IsAlpha = ReturnValue
    End Function

    In other words, it is incredibly slow and stupid under the hood - that's why it's a WTF.

  • (cs) in reply to franz ferdinand
    franz ferdinand:
    Beldar the Phantom Replier:
    function isDigit(digit)
    {
        var charOk = "0123456789";
        return !(charOk.indexOf(digit) == -1)
    }
    

    function isAlphaNumeric(digit) { var charOk = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; return !(charOk.indexOf(digit) == -1) }

    What is so bad about these two functions? Are they really WTF worthy?

    I could understand if either of the soft-coded strings were missing some digits or letters (respectively), but I must just be missing the WTF moment here.

    As another commenter said, there is a function in the language that does this already.

    Now please allow me to explain why this is a WTF.

    By the time I had spent my first twenty hours programming, I had learned that you don't tell whether something is Alpha/Numeric by looking up every character in an array (or string - they're the same thing). That's retarded AND slow AND the performance varies depending on which character you are looking at at the time.

    If there wasn't a built-in function, you would do something like this (in VB):

    Function IsAlpha(str As String) as Boolean
         Dim x as Long, TempAsc as Long
    
         IsAlpha = True
    
         For x = 1 to Len(str)
              TempAsc = Asc(Mid$(str,x,1))
              Select Case TempAsc
                   Case < 48
                        IsAlpha = False
                        Exit For
                   Case > 122
                        IsAlpha = False
                        Exit For
                   Case Else
                        If TempAsc > 57 And TempAsc < 65 Then
                             IsAlpha = False
                             Exit For
                        End If
              End Select
         Next x
    End Function

    What you DON'T do is compare each byte in your string to a validation list, unless you're making something more complex than this project.

    a] One call to indexOf (written in C and already compiled into machine code) on ten characters will be probably much faster than interpreting several lines of script code (unless you have extremely advanced JIT compilation)

    b] Premature optimization is evil. The difference between the two will be something like 0.0000000000001 ms.

  • Nyquist (unregistered) in reply to Anonymously Yours

    Because there are better ways of doing things like character validation that a first year university student learns in the first semester.

    And that for loop really gives me the lolz.

  • (cs) in reply to Nyquist
    Nyquist:
    Because there are better ways of doing things like character validation that a first year university student learns in the first semester.

    And that for loop really gives me the lolz.

    Edit: this was supposed to be a reply to the featured comment. Whoops.

  • (cs) in reply to Nyquist
    Nyquist:
    Because there are better ways of doing things like character validation that a first year university student learns in the first semester.

    And that for loop really gives me the lolz.

    If you find that code in any way amusing then you haven't been in The Real World for very long.

    OK, it's certainly not great and there is plenty of room for improvement. But my reaction when I saw it was more of a <sigh> than a "WTF??!!1!?". It's mediocre, not catastrophic.

    Some redundancy, if/else instead of a switch, some magic numbers instead of constants, not using built in functions that would have been useful - bah! All very, very ordinary.

    And for the record, JavaScript is a great language, some of the most elegant code I've ever seen was written in JavaScript. Unfortunately it's fairly quick to get results in and the interweb is strewn with sites chock full of very poor examples that inexperienced developers can copy, so there is a lot of less than optimal code out there in the wild.

    But the same can be said about C# and Perl. And Ruby. And Java.

  • franz ferdinand (unregistered) in reply to mol1111
    mol1111a:
    a]One call to indexOf (written in C and already compiled into machine code) on ten characters will be probably much faster than interpreting several lines of script code (unless you have extremely advanced JIT compilation)

    b] Premature optimization is evil. The difference between the two will be something like 0.0000000000001 ms.

    a] I've expected high-performance JIT compilation since 2000. Also, just because it's a single call to compiled C code doesn't make it faster. Particularly since the C function doesn't terminate once it finds a non-matching character - it keeps working its way through the rest of the string, scanning an array for every byte.

    b] This is not optimized code. If it were optimized, I would have unrolled the loop significantly AND written separate versions for it depending on the expected input. Also, we can't know the performance difference without testing, but I am confident that the 0.1 picosecond difference is not the case.

    My TRUE beef with this is that it smells funny. The valid input is any member of a set of consecutive numerical values. So you validate the input by comparing each member of the mathematical set to each member of the input? WTF?! Why not just see if each member of the input is in the RANGE of numbers contained in the set? Makes WAY more sense to me.

  • unascribed (unregistered) in reply to Anonymously Yours

    I see what you did there. . . ;)

  • Kelso (unregistered) in reply to Anonymously Yours

    well we'll start with the first one:

    for(var i = 0; i < total; i++) {
    if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7) { continue; } if(i == 0)

    as you can see here, the variable i is incremented by 1 for each loop through, starting at 0 and working it's way up. the first if statement basically ignores loops 1 through 7 and only executes code on the very first loop (loop 0)

    moving on:

    function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight) { var windowProps = 'toolbar=no,status=no,resizable=no,scrollbars=no,menubar=no,width=' + popWinWidth + ',height=' + popWinHeight; msgWindow = window.open(popWinURL, popWinTitle, windowProps); }

    Nothing wrong with a bit of repitition as you said. most of those however differ by one or two changes. The easier way of doing this would be to have one function which took the variables. i.e.: function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight, toolbar, status, resizable, scrollbars, menu bar) however that again is redundent. everything your passing to it is now literally everything that is used to create the msgWindow

    if more validation is needed please ask. I hope this has been enlightening.

    captcha - esse

  • Your Name (unregistered)

    TRWTF is how the featured comment went whoosh over some people's heads.

  • (cs) in reply to woodle
    woodle:
    Nyquist:
    Because there are better ways of doing things like character validation that a first year university student learns in the first semester.

    And that for loop really gives me the lolz.

    If you find that code in any way amusing then you haven't been in The Real World for very long.

    Thanks for your sweeping generalisation on my professional experience. Most of my office found this pretty hilarious too, especially the hand written versions of built in functions. Sure its not in the league of some of the more sersiouly wtfy stuff here but don't deny the easily amused among us our laughs.

  • (cs) in reply to Nyquist
    Nyquist:
    woodle:
    If you find that code in any way amusing then you haven't been in The Real World for very long.
    Thanks for your sweeping generalisation on my professional experience.
    OK, maybe I should have said "then you have been very lucky in your professional life to have worked with above-average web developers, because this level of coding is about the median, in my experience".

    How was that?

  • Timo (unregistered)

    Did you write this? :)

  • Timo (unregistered) in reply to Timo

    I ment the "Anonymously Yours", didnt see the other comments somehow -.-

  • kalerab (unregistered) in reply to jasmine2501

    "isAlphaNumeric" is only good, when used in UK/US environment. Try to validate some french or german specific "digit" ;)

  • IHasYourCheezburger (unregistered)

    TL;DR

    I only come here for the captchas. This time I got a suffix used in the name of a cloud which develops when more or less pronounced extensions, whether attached to the mother cloud or not, become clouds of a genus different from that of the mother cloud.

  • (cs) in reply to kalerab
    kalerab:
    "isAlphaNumeric" is only good, when used in UK/US environment. Try to validate some french or german specific "digit" ;)
    I can assure you that the French and the Germans use exactly the same characters as us for digits; it's the Asian languages that have oddities here. (Alpha chars and formatted numbers are something else, but that's another story. Plus in fact English does use some accented alphas – “naïve”, “Zoë” – though they're fairly rare.)
  • firecall (unregistered) in reply to Anonymously Yours

    LOL at the above

  • Rabiator (unregistered) in reply to Anonymously Yours
    Anonymously Yours:
    Where the issue? I don't see it. Repetitious code isn't cluttered and making uncommented code specific to the task at hand has the upside of not breaking the other 80 places you put copies of it. Updates are easy and safe, you just have to read more.
    Since the others only made fun of you, here goes:

    First, the duplication is a problem by itself because it makes it easy to overlook something if you need to update things. If you have to update the same code in 80 places you will probably miss one or two, leaving you with bugs for the overlooked functions.

    Second,

    if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7) { continue; }
    is retarded for spelling out all numbers from 1 to 7 in a big OR statement. At least, make it something like if(i >= 1) || i <= 2). Better yet, redesign this to avoid the seven "continue" operations entirely.

  • Rabiator (unregistered) in reply to dkf
    dkf:
    kalerab:
    "isAlphaNumeric" is only good, when used in UK/US environment. Try to validate some french or german specific "digit" ;)
    I can assure you that the French and the Germans use exactly the same characters as us for digits; it's the Asian languages that have oddities here. (Alpha chars and formatted numbers are something else, but that's another story. Plus in fact English does use some accented alphas – “naïve”, “Zoë” – though they're fairly rare.)
    Don't forget German umlauts, as in ä, ö, and ü. Accents in French may be a problem too. For the accented alphas in Englisch, you can probably get away with making the user type the "plain" versions - “naive”, “Zoe”.
  • Thomas (unregistered) in reply to Rabiator

    You should never assume you can make the user type anything in the format you want. Ask anyone who has had to parse a date or phone number entered in a text field ...

    Captcha: quis (are we running out of unique ones?)

  • (cs) in reply to woodle
    woodle:
    Nyquist:
    woodle:
    If you find that code in any way amusing then you haven't been in The Real World for very long.
    Thanks for your sweeping generalisation on my professional experience.
    OK, maybe I should have said "then you have been very lucky in your professional life to have worked with above-average web developers, because this level of coding is about the median, in my experience".

    How was that?

    o.0 Taking a look at some of the other comments, I think you might actually be right... or I've lived in some sorta sheltered existence where in most of the places I've worked, you're not allowed to touch ANYTHING unless you know wtf you're doing...

    OTOH I havent posted yet about some of the legacy monstrosities at my current place that we've had to patch up and keep running... and they are truly WTF-worthy.

  • Adam Jorgensen (unregistered) in reply to Anonymously Yours

    Haha, cute comment.

  • Mazzachre (unregistered) in reply to Anonymously Yours

    The validation loop is really bad, the redundancy is not that bad, but the fact that changing the order of the fields on the page would break this method in unpredictable ways. Filter input fields by their name, not their order in the page... That is a WTF...

    The windowing functions are quite alright by me, as you say, you can change the way some windows are show without destroying the rest of them... Only WTF is that someone actually bothered to do all this work for that :)

    Then the "Utility" functions... Uhm, there are already build in (and thus faster) functions to test if a string is numeric, alphanumeric, in a certain range, whatever...

  • laoreet (unregistered) in reply to Nyquist
    Nyquist:
    woodle:
    Nyquist:
    woodle:
    If you find that code in any way amusing then you haven't been in The Real World for very long.
    Thanks for your sweeping generalisation on my professional experience.
    OK, maybe I should have said "then you have been very lucky in your professional life to have worked with above-average web developers, because this level of coding is about the median, in my experience".

    How was that?

    o.0 Taking a look at some of the other comments, I think you might actually be right... or I've lived in some sorta sheltered existence where in most of the places I've worked, you're not allowed to touch ANYTHING unless you know wtf you're doing...

    OTOH I havent posted yet about some of the legacy monstrosities at my current place that we've had to patch up and keep running... and they are truly WTF-worthy.

    Your name looks scandinavian. :) Working in scandinavia might help. :)

  • ClaudeSuck.de (unregistered) in reply to Anonymously Yours
    Anonymously Yours:
    I don't see an issue with this code. So what if there's a bit of redundancy and unusual customization specific to the task? It's easy to update without breaking anything.

    This code doesn't have any issues I can see. Okay, there's some function and procedure copying, but that makes tweaking it to the task easier. Plus updates won't break anything.

    Where the issue? I don't see it. Repetitious code isn't cluttered and making uncommented code specific to the task at hand has the upside of not breaking the other 80 places you put copies of it. Updates are easy and safe, you just have to read more.

    I don't see a WTF with this code. Who cares if there's a bit of redundancy and unusual customization specific to the job? It's simple to update without breaking anything.

    This script doesn't have any WTFs I can perceive. Yes, there's some code copying, but that makes tweaking it to the task easier. Plus changes won't break anything.

    Where the WTF? I can't find it. Repetitive work isn't cluttered, and making uncommented code specific to what you're working on has the upside of not breaking the other /* 80 */ 83 places you put copies of it. Updates are easy and safe, you just have more to read.

    I don't have a problem with this content. So when if there's a bit of redundancy and unusual customizing unique to the task? It's easy to break without updatinging anything.

    This source code doesn't have any visible probles. OK, there's some copying and pasting and pasting but that makes working it to task easier. Plus updates won't crash anything.

    Where your boggle? I don't see it. see it. Repetitious code isn't cluttered and making nd has the upside of not breaking the other /* 80 */ 23 places you put copies of it. Updates are easy and safe, you

    The RWTF is in the comments

  • Anonymous (unregistered) in reply to Anonymously Yours

    you made me lol :D

  • a little slow today (unregistered) in reply to Anonymously Yours

    lol it took me until the 7th paragraph to get your joke ;) Well played!

  • comment (unregistered) in reply to Anonymously Yours

    I don't see an issue with this code. So what if there's a bit of redundancy and unusual customization specific to the task? It's easy to update without breaking anything.

    This code doesn't have any issues I can see. Okay, there's some function and procedure copying, but that makes tweaking it to the task easier. Plus updates won't break anything.

    Where the issue? I don't see it. Repetitious code isn't cluttered and making uncommented code specific to the task at hand has the upside of not breaking the other 80 places you put copies of it. Updates are easy and safe, you just have to read more.

    I don't see a WTF with this code. Who cares if there's a bit of redundancy and unusual customization specific to the job? It's simple to update without breaking anything.

    This script doesn't have any WTFs I can perceive. Yes, there's some code copying, but that makes tweaking it to the task easier. Plus changes won't break anything.

    Where the WTF? I can't find it. Repetitive work isn't cluttered, and making uncommented code specific to what you're working on has the upside of not breaking the other /* 80 */ 83 places you put copies of it. Updates are easy and safe, you just have more to read.

    I don't have a problem with this content. So when if there's a bit of redundancy and unusual customizing unique to the task? It's easy to break without updatinging anything.

    This source code doesn't have any visible probles. OK, there's some copying and pasting and pasting but that makes working it to task easier. Plus updates won't crash anything.

    Where your boggle? I don't see it. see it. Repetitious code isn't cluttered and making nd has the upside of not breaking the other /* 80 */ 23 places you put copies of it. Updates are easy and safe, you

  • (cs)

    No real surprise here- the programmer, or the contract, was obviously paid by the LOC.

  • SR (unregistered) in reply to kmarsh
    kmarsh:
    No real surprise here- the programmer, or the contract, was obviously paid by the LOC.

    That would explain about half the WTFs on this site. I wonder where I could get a job like that...

  • C (unregistered) in reply to chris
    chris:
    I would go even further than this, though. The purpose of isDigit seems to be to check if a character is a digit character (0 to 9). So it shouldn't accept hyphens, or decimal points, or indeed strings with multiple characters.
    But it does! All strings similar to "123", "56", "345678", etc, are seen as valid by the "isDigit" function above...
  • Bim Job (unregistered) in reply to MRAB
    MRAB:
    Mike Caron:
    If you learned anything about for loops by looking at that code, you're doing it wrong.

    Captcha: quis (yes, I am feeling a bit quisy)

    <smug_mode> FYI, "quis" is Latin for "who", "what" or "which", as in "Who, what or which one of you wrote this?". </smug_mode>

    Except that the nominative part of the declension of quis is (singular) quis, quis, quid and (plural; less applicable in this context) qui, qui, quae.

    I wish I had a quid for everybody who misattributed a captcha on this site...

  • Calculator ftvb (unregistered) in reply to Anonymously Yours

    I agree. In fact, I have occasionally written code like that. :-)

  • Amtep (unregistered) in reply to Rabiator
    Rabiator:
    Second,
    if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7) { continue; }
    is retarded for spelling out all numbers from 1 to 7 in a big OR statement. At least, make it something like if(i >= 1) || i <= 2). Better yet, redesign this to avoid the seven "continue" operations entirely.
    Your form is shorter, but it is semantically more complex. That makes it harder to get right. Enumerating all possibilities is inherently easier to understand than dealing with unions and intersections of number ranges. A mistake as small as using a union where you need an intersection could introduce a hard-to-spot bug in your validation routine and perhaps open your site to intrusion. I'm sure you would never make such a mistake, but keep in mind that other people modifying your code (perhaps less competent, perhaps inattentive) will have an easier time getting it right if you keep it simple.

    As an exercise for the reader, imagine that your least intelligent coworker is assigned the task of excluding i == 3 from the condition. Which form of the code is easier to maintain and thus more robust?

  • Slicerwizard (unregistered) in reply to franz ferdinand

    WTF? I've never had to write VB (yay), but it looks to me like you wrote a function called "ISAlpha" that returns true for (among other things, 0-9, [ \ ] ^ _ and ` ??

    Simple non-reversed-logic tests like >= 'a' && <= 'z' etc. just aren't obfuscated enough for you?

    franz ferdinand:
    If there wasn't a built-in function, you would do something like this (in VB):
    Function IsAlpha(str As String) as Boolean
         Dim x as Long, TempAsc as Long
    
         IsAlpha = True
    
         For x = 1 to Len(str)
              TempAsc = Asc(Mid$(str,x,1))
              Select Case TempAsc
                   Case < 48
                        IsAlpha = False
                        Exit For
                   Case > 122
                        IsAlpha = False
                        Exit For
                   Case Else
                        If TempAsc > 57 And TempAsc < 65 Then
                             IsAlpha = False
                             Exit For
                        End If
              End Select
         Next x
    End Function
  • Coder (unregistered) in reply to Anonymously Yours

    You should have saved your "breath" as you just made yourself look like a total douche. I would fire someone for writing code like this.

  • Bob (unregistered) in reply to Anonymously Yours

    Are you the author of this code?

    Are you the author of this code?

    Are you the author of this code?

  • JV (unregistered) in reply to DrJDX
    DrJDX:
    I think I forgot to mention something important about this file when I submitted it: you are looking at a disturbingly small fraction of it. The file was just shy of 1,900 lines and weighs in at just under 50kb.

    Each of these popup functions is only called once, and never on the same page. Most validation functions we called by middleman functions that were called by helper functions bound to the actual events (that's three calls deep, for those of you keeping score at home). By the time I trimmed and abstracted the file completely was down to about 250 lines and still powered the whole site.

    Thankfully, shortly after I submitted this story they suspended the contract with these people and moved me to something else. If I didn't think it'd break the Anonymity rules I would post a link to where they still have the original version in production, for all to see.

    I wish Google could search JavaScript and HTML (including the comments)...

  • darkYuris (unregistered) in reply to Anonymously Yours

    did you code it? :D

  • pbean (unregistered)

    He could have implemented isDigit like this:

    function isDigit(digit)
    {
      var isZero, isOne, isTwo, isThree, isFour, isFive, isSix, isSeven, isEight, isNine, isDigit;
      isOne = digit == "1";
      isTwo = digit == "2";
      isThree = digit == "3";
      isFour = digit == "4";
      isFive = digit == "5";
      isSix = digit == "6";
      isSeven = digit == "7";
      isEight = digit == "8";
      isNine = digit == "9";
    
      isDigit = isZero || isOne || isTwo || isThree || isFour || isFive || isSix || isSeven || isEight || isNine;
    
      return isDigit;
    }

    I once worked on a school project which was finished about a month before the deadline. The last month we spent writing a static "Utility" class with functions like these, and replacing all built-in function calls to these functions. We fooled the examinator with that code first, before we pulled out another SVN revision with the correct code. :D He was like "WTF" at first.

  • franz ferdinand (unregistered) in reply to Slicerwizard
    Slicerwizard:
    WTF? I've never had to write VB (yay), but it looks to me like you wrote a function called "ISAlpha" that returns true for (among other things, 0-9, [ \ ] ^ _ and ` ??

    Simple non-reversed-logic tests like >= 'a' && <= 'z' etc. just aren't obfuscated enough for you?

    Yeah, I was too lazy to write out the whole name of the function, which was "IsAlphaNumeric". And the function specifically excludes "" and such with the Case Else block.

    The reason I used the ASCII code instead of the characters themselves is because I wasn't thinking of them as characters at the time, but as integers. So, it was obfuscated already in my head...

Leave a comment on “Loopy Validation”

Log In or post as a guest

Replying to comment #:

« Return to Article