• (cs) in reply to Grovesy
    Grovesy:
    sign:
    I wonder what would happen if you entered some exotic characters like é, ü or å. But then, who needs applicants with French, German or -- God forbid -- Swedish names :)

    It still puzzles me that in this day and age of unicode é is seen as exotic a character as Jack Sparrow..

    Yeah, use really weird characters like ð or å or the eternally fun æ

  • zoips (unregistered) in reply to A. Cube
    A. Cube:
    An interesting alternative would be to pretend that you're programming in a functional language

    JavaScript/ECMAScript IS a functional programming language, with support for first class functions and closures. Due to its C-like syntax and the fact that most people only use it to do a bit of DOM and maybe some asynchronous callbacks, most remain blissfully unaware what the LANGUAGE is capable of (most of the LIBRARIES on the other hand, are hideous trash).

    I think most people also realize that tail-calls are not required by the ECMA-262 spec (they are for ECMAScript4) and no interpreter actually implements them anyway (most can handle ~1000 or so recursive calls before stack-overflow, I think).

    Javascript is the epitome of half-assed. There is so much potential in there, completely mired by idiocy. Sadly, Javascript 2.0 throws out all the possibilities and goes back to the sad-old class based inheritance system, basically ignoring the prototype system inherited from SELF (that it never quite got right anyway...).

  • Edward Royce (unregistered)

    Hmmm.

    Maybe I'm missing something but what precisely is the point of this javascript function? To turn everything uppercase?

    Why on earth would anybody want to turn all text into uppercase?

  • wtf (unregistered) in reply to Edward Royce
    Edward Royce:
    Hmmm. MAYBE I'M MISSING SOMETHING BUT WHAT PRECISELY IS THE POINT OF THIS JAVASCRIPT FUNCTION? TO TURN EVERYTHING UPPERCASE?

    WHY ON EARTH WOULD ANYBODY WANT TO TURN ALL TEXT INTO UPPERCASE?

    JUST BECAUSE.

  • (cs) in reply to dkf
    dkf:
    real_aardvark:
    I think we need to delve more deeply into the problem here.
    It just occurred to me that maybe the problem is that every field is being "validated" each time. If that form's a long one (and the JS implementation a piece of rubbish) then that could lead to a proper WTF?! moment...
    I'm obviously no expert on Javascript, which is obviously an excellently well-thought-out functional language, but I think you're on to something here.

    I see something hideous like an 'onfocus="mega_validate()"' on every field, just to make sure that (say) any Swedish characters in the name enforce Swedish rules on the ZIP code, the sex, etc etc. Function mega_validate() would then call validate() in some weird recursive way, possibly with added Ajaxy yumminess, and that would explain the hideous delays.

    I think Jake was right to stop the code where he did. (And I think it was wrong to reinstate it, but that's a matter of taste.) There is clearly a lot more WTFery behind the scenes here.

  • safsdf (unregistered) in reply to zoips

    Really? They took out prototyping? That SUCKS. If anything, other languages should be implementing prototyping.

  • (cs) in reply to Nazca
    Nazca:
    Grovesy:
    sign:
    I wonder what would happen if you entered some exotic characters like é, ü or å. But then, who needs applicants with French, German or -- God forbid -- Swedish names :)

    It still puzzles me that in this day and age of unicode é is seen as exotic a character as Jack Sparrow..

    Yeah, use really weird characters like ð or å or the eternally fun æ

    What's so fun about that? Let's go runic, man ... time for the Thorn.

    What I particularly like about the fuþorc alphabet is that the name itself sounds like a WTF.

  • (cs) in reply to real_aardvark
    real_aardvark:
    Well, it obviously doesn't use regexps -- that would be too simple.
    Well, you know what they say about regexps. "Now you have two problems" and all that.

    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.

  • (cs) in reply to rbonvall
    rbonvall:
    real_aardvark:
    Well, it obviously doesn't use regexps -- that would be too simple.
    Well, you know what they say about regexps. "Now you have two problems" and all that.

    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.

    Well, I mentioned O(f(n)) once, but I think I got away with it.

    Isn't that the Javascript/functional language way of saying W(t(f))?

  • (cs) in reply to WhiskeyJack
  • wpp (unregistered) in reply to rbonvall
    rbonvall:
    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.
  • (cs) in reply to wpp
    wpp:
    rbonvall:
    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.
    Whoosh!

    But at least he can write the symbols down, even if he's not a mathematician ...

    I mean, that should qualify at least for a Senior Web Designer post, with special responsibility for escaping angle brackets in Javascript.

  • (cs) in reply to wpp
    wpp:
    rbonvall:
    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.

    If you can't look at joke like this and figure out why it's funny, you definitely shouldn't be posting here.

  • Anonymous (unregistered) in reply to wpp
    wpp:
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.
    Well, actually we looked at it and couldn't figure out why it's so damn slow, because apart from the string concatenation this algorithm has a runtime complexity of O(n), and even O(n^2) shouldn't be noticable for n ~ 100. ;-)
  • (cs)

    So stupid. Obviously this needs more ifs.

    function toUpper(value)
    {
        var newval = "";
        for(var i = 0; i < value.length; i++)
        {
            if(value[i] == "a")
            {
                newval = newval + "A";
            }else
            {
                if(value[i] == "b")
                {
                    newval = newval + "B";
                }else
                {
                    [.....]
                }
            }
        }
    }
    
  • florib (unregistered) in reply to dtech
    dtech:
    So stupid. Obviously this needs more ifs.
    function toUpper(value)
    {
        var newval = "";
        for(var i = 0; i < value.length; i++)
        {
            if(value[i] == "a")
            {
                newval = newval + "A";
            }else
            {
                if(value[i] == "b")
                {
                    newval = newval + "B";
                }else
                {
                    [.....]
                }
            }
        }
    }
    

    What's with all the "else" thingies? Cut them out and your sources will be way smaller! You may laugh, but after you implemented proper uppercasing for all currently known uppercaseable unicode characters, you will notice the difference.

  • (cs) in reply to Anonymous
    Anonymous:
    wpp:
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.
    Well, actually we looked at it and couldn't figure out why it's so damn slow, because apart from the string concatenation this algorithm has a runtime complexity of O(n), and even O(n^2) shouldn't be noticable for n ~ 100. ;-)
    I still think it's n ~ 50 (see above).

    "This machine is a piece of GAGH! I need dual Pentium IV processors if I am to do battle with this code!"

    That says it all, really.

  • (cs) in reply to Someone You Know
    Someone You Know:
    If you can't look at joke like this and figure out why it's funny, you definitely shouldn't be posting here.
    Can't figure out why they're so damn slow...
  • (cs) in reply to FredSaw
    FredSaw:
    Someone You Know:
    If you can't look at joke like this and figure out why it's funny, you definitely shouldn't be posting here.
    Can't figure out why they're so damn slow...
    Do I really have to do this?

    "You question the worthiness of my Comment?! I should kill you where you stand!"

  • (cs)

    And anyone named François is just plain out of luck, no matter how he capitalizes his name...

  • Joe (unregistered)

    Whilst it's not perfect, it's not the worst possible solution. I think his machine was at least partly to blame for the speed issue...

  • (cs) in reply to Joe
    Joe:
    Whilst it's not perfect, it's not the *worst* possible solution. I think his machine was at least partly to blame for the speed issue...
    Well, that sort of wastes the combined efforts of the umpteen comments above on exactly this issue.

    Care to go back to Reading Comprehension School?

    Or don't they have one in Podunk?

    btw, can you spell O(n^2)?

  • Mr'; Drop Database -- (unregistered)

    This can be done without Javascript at all. Use text-transform: uppercase on the client side and convert the form data to uppercase on the server side.

  • Gitsnik (unregistered) in reply to WhiskeyJack
    WhiskeyJack:
    cloudberry:
    Why insist on uppercasing everything in the first place?

    I WAS JUST GOING TO SAY. THAT IS THE REAL WTF, IN MY OPINION.

    Architect's type and work completely in upper case. I don't know why but that's just what they do.

    It still dumbfounds me that these people don't think "there could be an easier way" and google to find the .toUpperCase() function. The mind boggles.

  • haoest (unregistered)

    I don't see how it can be slow as described. Assuming the input is 100 characters, it only takes ... ~300... 2^30...

    oh shit.

  • Counterlock (unregistered) in reply to Studley
    Studley:
    This could've led to some brilliant support calls.

    "Christopher Konstantopoulos says the site's running very slowly? But I just checked with Bob Jones and he says it's fine!"

    A missed opportunity, sir. You shoulda said Alexander Papadimoulis.

  • eric76 (unregistered) in reply to Kiss me I'm Polish

    What drives me nuts is web pages used to submit an e-mail address that cannot recognize a valid e-mail address.

    I used to get so much spam at my usual e-mail address that it was unusable. In response, I finally started accepting e-mail only if it satisifed one of the following criteria:

    1. The sender's e-mail address is whitelisted.

    2. The e-mail is encrypted with my PGP key.

    3. The e-mail is digitally signed with their PGP key.

    This worked pretty well. It pretty much cut out all the spam. But there were times when I couldn't get e-mail from some people who were unfamiliary with PGP.

    So I set up a bunch of whitelisted to adddresses. For example, if my e-mail address is [email protected], it also accepts e-mail addresses of the form [email protected], [email protected], [email protected]. I selected a specific list of words, none of which have anything in common with any other word in the list, and whitelisted e-mail addresses using them after the +. Then I would give out each e-mail address of this form, e.g. [email protected], to one organization or person.

    Thus, [email protected] may be refused unless it satisifes one of the other three criteria, but [email protected] would be whitelisted. If I should start to receive spam or other unwanted e-mail at [email protected], I can blacklist that e-mail address and leave the same alone.

    Unfortunately, it seems that many web pages that ask for e-mail addresses don't recognize e-mail addresses containing a '+'.

  • kyle huff (unregistered)

    I would think that almost any polynomial-time algorithm would be more than sufficient for such a small data set.

    Javascript must suck even more than I thought it did.

  • Alex (unregistered) in reply to kyle huff

    I don't see the problem either =S. I would expect even a few thousand characters to be quick. I mean, how slow can a memcpy be?

  • Tom_fan_63 (unregistered) in reply to real_aardvark
    real_aardvark:
    Jay:
    sign:
    I wonder what would happen if you entered some exotic characters like é, ü or å. But then, who needs applicants with French, German or -- God forbid -- Swedish names :)

    Hey, sounds like a clever way to weed out the Swedes from your job applicants without having to admit to discrimination. When they try to submit the resume, just reject it with "Invalid character in name".

    (Need I explain that I'm of Norwegian descent?)

    Nå...
    Øøøø...

  • Tom_fan_63 (unregistered) in reply to real_aardvark
    real_aardvark:
    Jay:
    sign:
    I wonder what would happen if you entered some exotic characters like é, ü or å. But then, who needs applicants with French, German or -- God forbid -- Swedish names :)

    Hey, sounds like a clever way to weed out the Swedes from your job applicants without having to admit to discrimination. When they try to submit the resume, just reject it with "Invalid character in name".

    (Need I explain that I'm of Norwegian descent?)

    Nå...
    Øøøø...

  • jethr0 (unregistered)

    I expected something like

    char *ins  = "abcde...";
    char *outs = "ABCDE...";
    
    for (int i = 0; i < input.length; i++)
    {
      for (int j = 0; j < ins.length; j++)
      {
        if (input[i] == ins[j])
        {
          output[i] = outs[j];
          break;
        }
      }
    }
    

    Captcha: genitus

  • Paolo G (unregistered) in reply to DOA
    DOA:
    "In response to your interview question on how I feel I could contribute to the company I'd like to point out that I could start by updating, sorry, rewriting your online résumé form. I realize that this isn't saying much seeing as a 3 year old child with severe down syndrome could make a better form than this; it is however necessary to start with the basics if you'll have any hope of lifting yourself out of this pile of rancid manure you call code. If I may offer you some advice, I'd also propose to stop hiring high school kids to build forms. I understand that you can pay them in coke cans, but their "code" tends to suffer."
    Dear Applicant,

    Thank you for your interest in this post. Unfortunately we are unable to offer you a position as our pile of rancid manure^W^W^W^Wcode tried to capitalize your application but hung before it got as far as "down" and "coke". :P

  • ClaudeSuck.de (unregistered) in reply to Warren
    Warren:
    This comment goes something like this:

    The real WTF is

    ...and yet, it is not TRWTF. TRWTF is in the comments, of course.

  • ClaudeSuck.de (unregistered) in reply to Gustavo S.
    Gustavo S.:
    Heey, the post wasn't like this!

    Here is the code as I posted it.

    function validate(field) { var A = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.:!?@#$%¨&*()_+=[]^Çç{}^<>\/|"; var B = " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.:_____________________________";

    var oldval = field.value; var newval = "";

    for (var i=0; i<oldval.length; i++) { var char = A.indexOf(oldval.substr(i, 1)); newval = newval + B.substr(char, 1); } field.value = newval; }

    o.O

    Sorry for a WTF inside a WTF =P

    TRWTF is tu write

    var char = A.indexOf(oldval.substr(i, 1));

    where char is, in fact, an integer!!!

  • (cs) in reply to kyle huff
    kyle huff:
    I would think that almost any polynomial-time algorithm would be more than sufficient for such a small data set.

    Javascript must suck even more than I thought it did.

    You're quite right - about the algorithm, at any rate. I just tried the code out and even with a lot of data in a textarea the timelag for conversion wasn't noticeable. Whatever other WTFs exist on the website, and regardless of the actually WTFery of this code (like only coping with certain characters, replacing cedillaed Cs with _, and ignoring built in functions like toUpperCase), the time delays were not caused by this bit of code...

    As far as javascript goes, it's like all the other "Hey, let's bash a particular language just because I don't like it" rubbish that happens on here. Javascipt has a massively bad reputation because absolutely any halfwit with a webbrowser can try to write some kind of app in javascript, so there's a huge amount of rubbish out there. If you're sensible and follow good programming techniques, there's absolutely nothing wrong with Javascript.

  • ClaudeSuck.de (unregistered) in reply to real_aardvark
    real_aardvark:
    wpp:
    rbonvall:
    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.
    Algorithmic analysis is one of the most basic skills you should have as a programmer. If you can't look at some code like this and figure out why it's so damn slow, you definitely shouldn't be writing it.
    Whoosh!

    But at least he can write the symbols down, even if he's not a mathematician ...

    I mean, that should qualify at least for a Senior Web Designer post, with special responsibility for escaping angle brackets in Javascript.

    You don't need to study maths to see why it's slow. Some common sense should be enough. Never made algorithmic analysis. I rather measured the time it takes to do an action. Gives you better insight than a given theory. And for n = 50 to 100 it should still not be sooo slow. Since "Echtes Erdferkel" likes to critisize people (though in most cases he is right) I'll throw in my critics, too. The guy said "When I got to the multiline, free text fields to describe past experiences". This can be far more than just 50 chars. OTH if it uppercases after every key stroke (i.e. OnChange) than it might still be annoying.

  • ClaudeSuck.de (unregistered) in reply to eric76
    eric76:
    What drives me nuts is web pages used to submit an e-mail address that cannot recognize a valid e-mail address.

    I used to get so much spam at my usual e-mail address that it was unusable. In response, I finally started accepting e-mail only if it satisifed one of the following criteria:

    1. The sender's e-mail address is whitelisted.

    2. The e-mail is encrypted with my PGP key.

    3. The e-mail is digitally signed with their PGP key.

    This worked pretty well. It pretty much cut out all the spam. But there were times when I couldn't get e-mail from some people who were unfamiliary with PGP.

    So I set up a bunch of whitelisted to adddresses. For example, if my e-mail address is [email protected], it also accepts e-mail addresses of the form [email protected], [email protected], [email protected]. I selected a specific list of words, none of which have anything in common with any other word in the list, and whitelisted e-mail addresses using them after the +. Then I would give out each e-mail address of this form, e.g. [email protected], to one organization or person.

    Thus, [email protected] may be refused unless it satisifes one of the other three criteria, but [email protected] would be whitelisted. If I should start to receive spam or other unwanted e-mail at [email protected], I can blacklist that e-mail address and leave the same alone.

    Unfortunately, it seems that many web pages that ask for e-mail addresses don't recognize e-mail addresses containing a '+'.

    Thx for your help and for proofing that TRWTF is in the comments.

  • ClaudeSuck.de (unregistered) in reply to Tom_fan_63
    Tom_fan_63:
    Øøøø...

    ____...

    Uppercased that for you

  • Wouter (unregistered)

    The real WTF is that string B is shorter than string A.

  • NiceWTF (unregistered)

    So, unless this "validation" function gets called after every keypress, I still cannot really see how this would take over a second on any modern computer?

    It's still an O(N) solution, so its performance can hardly be that terrible; the time it takes to run increases linearly with the length of the string it validates, and I cannot imagine that it takes, say, 0.05 seconds per indexOf call on a string of some 70 characters. Not even in Javascript.

    (clearly not using whatever the built-in 'uppercase' function is called in Javascript is still a nice WTF, but oh hey..)

  • NiceWTF (unregistered) in reply to Pink
    Pink:
    O(n) vs O(n^2)

    I'm pretty sure it's 0(n). [..]

    The indexof is being done on a constant string, not the input string so is O(1). Substr is o(1). It seems to me that this algorithm is a perfect example of O(n). Can one of you O(n^2) advocates go into a little more detail please?

    You are entirely correct. If anything, it would be O(M*N) where M is the length of the constant string; hence is a constant; hence reducing this to O(N), as you stated.

    It may still be O(N^2) for the reason posted by someone else: if string concatenation is actually O(N) rather than O(1). This may apparently be the case for some sucky javascript interpreters.

    Even so, N^2 is still not that terrible and I don't think it would explain a second of delay on converting a 10-20 character string.

  • Anonymous Coward (unregistered) in reply to WhiskeyJack
    WhiskeyJack:
    cloudberry:
    Why insist on uppercasing everything in the first place?

    I WAS JUST GOING TO SAY. THAT IS THE REAL WTF, IN MY OPINION.

    Are you serious? Isn't it obvious? Uppercasing is very resource intensive. Best done on the client machine, and store the result as early as possible so you don't have to waste time ahem re-inventing the wheel.

    Duh.

  • Anonymous (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    WhiskeyJack:
    I WAS JUST GOING TO SAY. THAT IS THE REAL WTF, IN MY OPINION.
    Are you serious? Isn't it obvious? Uppercasing is very resource intensive. Best done on the client machine, and store the result as early as possible so you don't have to waste time *ahem* re-inventing the wheel.
    Also, uppercase saves electricity by requiring less "1" bits.
  • soru (unregistered)

    See

    http://blogs.msdn.com/jscript/archive/2007/10/17/performance-issues-with-string-concatenation-in-jscript.aspx

    for the performance of early implementations of javascript string concatenation. 11.2 seconds for 30 thousand short string appends on a 2007-vintage PC is really kind of amazingly bad.

    That plus the wtf-code isn't quite enough to generate a multi-seconeds lag by itself, but multiply it by some comparable idiocy elsewhere in the code and you'd get there.

  • Incen (unregistered) in reply to kyle huff
    kyle huff:
    I would think that almost any polynomial-time algorithm would be more than sufficient for such a small data set.

    Javascript must suck even more than I thought it did.

    It most definitely does suck occasionally.

    There was this textarea I once encountered that would update a counter of the space you had left to bleed your heart in as you typed. It was kind of slow at doing this, though - so much so that after writing a few paragraphs, I had to wait for several minutes for the it to type them out.

    I immediately thought there must be some inane O(n) implementation in either the event listener, the character counter or the counter updater. Nope - they were all done using proper language functions, like .length.

    Nevertheless, it was very slow, and this was firefox 2 (which does have a crummy interpreter). I pretty much gave up on interactive javascript then and there.

  • Loren Pechtel (unregistered) in reply to rbonvall
    rbonvall:
    real_aardvark:
    Well, it obviously doesn't use regexps -- that would be too simple.
    Well, you know what they say about regexps. "Now you have two problems" and all that.

    And what is this O(f(n)) thing you guys keep talking about? We're programmers, not mathematicians! No need to worry about that.

    If you can't figure out the runtime of an algorithm, good luck when you get into anything complex. You just might implement something that's O(2^n) and then have to throw it all in the trash when it can't handle real-world data.

    The problem I have in mind doesn't need any math beyond addition but it's still O(2^n) with n approaching 100. Obviously out of the question, some approximation of the right answer is going to have to be implemented in the real world.

  • Anon (unregistered) in reply to WhiskeyJack

    To make string comparisons faster of course. ;)

  • Anon (unregistered) in reply to Anon
    WhiskeyJack:
    cloudberry:
    Why insist on uppercasing everything in the first place?

    I WAS JUST GOING TO SAY. THAT IS THE REAL WTF, IN MY OPINION.

    To make string comparisons faster of course. ;)
  • ><<< (unregistered) in reply to Kiss me I'm Polish

    ok how you du her?

Leave a comment on “The Long Road to Uppercase”

Log In or post as a guest

Replying to comment #:

« Return to Article