- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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...
Admin
Being 5' 10", I was able to survive the height pandemic with minimal problems.
Admin
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"...
Admin
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.
Admin
Payment per line of code come to mind first...
Admin
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?
Admin
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.?
Admin
Except it doesn't.
Admin
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.
Admin
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 tostrTemp
.BTW, it never actually compares the length against the limit.
Admin
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.
Admin
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?
Admin
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.
Admin
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?
Admin
Just my luck that none of them have ever tried to bribe me . . .
Admin
JavaScript's strings are UTF-16
Admin
"During the height pandemic" - how on earth did I miss that one?
Admin
I'm thinking "all of the above":
Admin
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!
Admin
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".
Admin
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.
Admin
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
Admin
The height pandemic resulted in a shortage of dwarves.