- 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 same way it happens anywhere: one misstep at a time.
Admin
Performance is obviously not a thing, because they're calling
value_.split( ',' )three times, and usingvalue_.split( ',' )[1] twice. They're also potentially callingparseInt( value_.split( ',' )[ 1 ], 10 )twice. (They also could have used the result ofvalue_.indexOf( ',' )` instead of splitting...)And
parsedCommaValueis a number if it's < 9, otherwise it's a string.Admin
Performance is obviously not a thing given that they are using javascript.
Admin
There's the language being slow, and then there's writing a slow algorithm in that language. This is the latter, it would be slow in any language, if you could write it at all without triggering a type error. That "string or int" thing can't be helping performance either, subsequent code cannot use fast paths that rely on knowing the real type.
Admin
Sorry, that was as far as I got before I bailed.
Addendum 2026-02-03 09:07:
Admin
In addition to all the other sins,
handleInputis a really vague name for a number-parsing function.Admin
My favourite part is the parseInt on the decimal part getting rid of leading zeroes, so e.g. '2,04' turns into 2.4.
Admin
Performance is not an issue because they're dealing with user input, typed one character at a time, into a textbox with no more than, say, 20 characters. N is so small that they could have an 2^n algorithm and almost be fast enough to not be noticed by the user.
Admin
Actually, if there is more than a single fractional digit, the fractional part will be still a string, limited to two characters. So it's
2 + "04"(number + string), resulting in the string"204", which will then be processed byparseInt(…, 10) / 100into the real value2.04. So this actually works.Admin
Agree w @PotatoEngineer & @516052.
As long as the code you are writing runs on their client, you do NOT care how performant it is or isn't. Any brain bytes spent on performance there are 100% wasted. Total opposite for code that runs on your server; performance back here is almost always a strong consideration.
But the performance we all should be caring about is the gain that comes from using an adequate language and adequate libraries by devs of adequate knowledge so this kind of trash code never has to be written, debugged, or maintained.
Admin
I hope this comment - "As long as the code you are writing runs on their client, you do NOT care how performant it is or isn't. Any brain bytes spent on performance there are 100% wasted." - is you being sarcastic.
Otherwise, you've just absolutely demonstrated what's wrong with modern (last 30 years) development. This attitude of 'I can write crap code, it doesn't matter, we'll just tell the customer to get more RAM / CPU / storage' is a cancer on the industry.
Admin
Agreed. We don't have control over the user's device, so Postel's Law (https://lawsofux.com/postels-law/) is very apt. There are a lot of folks out there who for various reasons don't have the option of simply upgrading to the latest and greatest software, hardware, and network connectivity.
Admin
No, you read the code wrong. The check isn't if the fractional part is more than a single digit, the check is if the fractional part, parsed as int, is less than 10 or not. parseInt( '2,04'.split( ',' )[ 1 ], 10 ) < 10 returns true.
Try it if you don't believe me.
Admin
You're right!
(All those
value_.split( ',' )[ 1 ], 10 )must have confused me. No sense in spli()-ting hairs on that…)Admin
Things like handInput() fit nicely into a world where things like doTheThing(), doOtherThing(), performOperation(), calculeResult() or decideAboutOption() already might exist.
Admin
Oh, now I get it. I'm sorry for my "wise" comment recently. I guess when a function is calculating percision, one should not expect precision exactly.