• Industrial Automation Engineer (unregistered)

    the only reason I can think of is someone confused the length of a string vs. the number of bytes it takes to store them. They remembered something vague about ASCII vs. Unicode perhaps? Otherwise, it's a long shot in the dark, blindfolded.

  • Industrial Automation Engineer (unregistered)

    Just came up with another one: look at the function name: TextCounter In the spec. it was written down: count the number of characters, and since it's a goverment agency, that's what the software is required to do...

  • dpm (unregistered)

    Being 5' 10", I was able to survive the height pandemic with minimal problems.

  • (nodebb)

    theCharCounter is a read-only input field, where we store the output

    Parsing this was ... fraught ... until I realised that the words "read-only" mean "not modifiable by the person using the web page" rather than "not modifiable by the code"...

  • (nodebb) in reply to Industrial Automation Engineer

    But if they were supposed to be counting, they're still wrong. They should've just incremented some counter variable (such as 'i', but that would be too obvious) and subtracted that.

  • Allexxann (github)

    Payment per line of code come to mind first...

  • Sauron (unregistered)

    The entire 11-line function could have been replaced with a one-liner like:

    theCharCounter.value = maxChars - theField.length;

    So the code has +1000% size than what it should have.

    Maybe major European govs pay by the number of code lines?

  • (nodebb)

    Conspiracy theory: did hardware manufacturers like Intel and Apple etc. join forces and bribe these developers to maximize CPU and memory consumption, in order to sell more powerful computers/CPU/RAM/etc.?

  • (nodebb) in reply to Industrial Automation Engineer

    Just came up with another one: look at the function name: TextCounter In the spec. it was written down: count the number of characters

    Except it doesn't.

  • Deeseearr (unregistered)

    Originally, the "for" loop iterated up to the maximum size of the text field and relied on the "substring" method to tell it when it had reached the end of the available text.

    During code review, the programmer was told to just use the "length" property instead of all that messing around.

    So they did. And here we are.

  • Barry Margolin (github)

    I suspect they copied a function that also filters the characters in the loop. But since they only needed the count, they removed the if statement around the copy to strTemp.

    BTW, it never actually compares the length against the limit.

  • WTFGuy (unregistered)

    Perhaps somebody was confused about the difference between the length of the field's contents and the max capacity of the field. Various object models have used the .Length property for each.

    One of the irritations of modern development in general and web in particular is the vast number of overlapping OMs you end up needing to use, plus all the obsolete ones you half-remember.

    Even if the dev thought he had to count the chars to find the length rather than just consult a property, building a new string while doing the counting is just nuts. Can you say "I program by asking badly-formed newbie questions on stackexchange then misunderstanding the uniformly bad answers I get"? I knew you could.

    Sheesh.

  • markm (unregistered)

    It copies the string to a temp to get the length of the temp, then discards the temp. But the length of the temp is sure to be the same as the length of the original string.

    It copies the string one character at a time. I assume Java has a string-copy function?

    But first, it gets the length of the original string to control the copy loop. So it starts by getting the same number that is the single goal of all this code.

    Was there something I missed?

  • markm (unregistered)

    I no longer want to know what the author of that code was thinking. I want to know what hot mess he copy-pasted from, and what that person was thinking.

    I'd think the author was trying to increase his lines-of-code and maximize the memory and CPU usage, but he did even that poorly. If I wanted to do that, I'd add an inner loop that duplicated 'substring' by stepping through the string until it reached character 'i'. Then I'd unroll the outer with a case statement, selecting a block of code according to 'theField.value.length', with blocks to copy 0, 1, 2, ... characters up to an assumed maximum.

    Finally, I'd have a choice of whether to leave that assumed maximum as an undocumented limit so the program would crash mysteriously when it was exceeded, or to crash-proof the program by putting the outer for loop back in as the default for the case statement.

  • (nodebb)

    I do think it's probably copied code. However, I wonder how this behaves against Unicode? Could it possibly return the total bytes used rather than the total characters? Or could it have been copied from something that did this?

  • dpm (unregistered) in reply to Mr. TA

    Just my luck that none of them have ever tried to bribe me . . .

  • (nodebb) in reply to LorenPechtel

    JavaScript's strings are UTF-16

  • r.orrison (unregistered)

    "During the height pandemic" - how on earth did I miss that one?

  • (nodebb)

    I'm thinking "all of the above":

    • copied code, simplified and keeping a now pointless loop.
    • remnant thinking of an ex Win32 mbcs programmer who used to do "stuff like that".
    • contractors tendency to give complex code for any problem, so that the client feels like they have their money worth.
    • write only project due yesterday. If it works, ship it and don't look back.
  • Gearhead (unregistered) in reply to dpm

    Being 5' 10", I was able to survive the height pandemic with minimal problems.

    The height pandemic has exposed many weaknesses in our medical response. Most of us know of people, almost all children, who grew many inches (cm) during the pandemic. Let's think of the children!

  • (nodebb)

    TRWTF is comment fields with fixed, invariably ridiculously tiny, size limits. "Please describe in full detail the problem you're having, providing make, model number, location, time, date, a full description of what you did, and the complete error message, in this field of 40 characters which is all that will fit on our punched cards".

  • Nick (unregistered)

    This is clearly a slow-down loop. As the amount of user input increases, the responsiveness of the form decreases… thereby gently encouraging the user to be concise in her message.

    This is very effective against the type of user who likes to go off on long-winded rants about the decline of customer service, and how in his day things were better, don’t you know, and… bah, this is getting annoying to type, it’s going so slow… I’ll just end it here.

  • Jeremy (unregistered)

    But this is exactly replicating the business process: First the clerk makes a copy of the paper form. Then the clerk validates the copy is correctly filled in. ...

    There may also be a validation check that checks if the text color is not something that is hard to copy, like yellow

  • Labasta (unregistered)

    The height pandemic resulted in a shortage of dwarves.

  • (nodebb)
    Comment held for moderation.

Leave a comment on “Characters Remaining”

Log In or post as a guest

Replying to comment #:

« Return to Article