- 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
Edit Admin
it's not got noticed because:
Also FRIST
Admin
If it's anything like my work:
a.) The report was set up 20 years ago "for audit purposes";
b.) Nobody has read it since then, but the word "audit" makes everyone too scared to get rid of it.
Admin
I know, I know, hating on JS is overdone ... but how in the name of all that is holy is half the planet running on a language that gets a bool where an int should be and says "Sure, this is fine"? Software isn't eating the world, it's covering it in vomit.
Admin
So much of this. At my place we have reports that go out by email - sometimes several times a day - that the recipients just move into a folder in their mailbox. They never look at them, they're just keeping them around 'just in case'.
We even have people receiving these reports even when they've changed jobs and no longer require the reports - they've just become so used to getting the email, marking as read and moving into a folder that they no longer realise what it is they're actually doing, it's entirely autonomic at this point.
Edit Admin
Possibly the report is output to a PDF which gets emailed and no one bothered to notice (or simply ignored) there were more pages after the end of the first report. Or alternatively, they were all good bureaucrats who expect things to be done in duplicate or triplicate because that's how they roll.
Edit Admin
The really organized ones have an email client incoming mail rule to do it for them.
A fun thing about "duplicate" reports is that depending on the report design and the time interval between repeats, they may not be identical. A week-to-date sales report run twice 3 minutes apart may have different numbers. Such fun when other people or their Excel-based "systems" start using those divergent numbers unaware
Admin
Even aside from the transposition, shouldn't that also be a == comparison anyway?
Edit Admin
I got a feeling with the rise of GenAI code generators we will see A LOT more of those in the future. Hope everyone is prepared to become a constant CodeReview slave until the bubble bursts :-)
Edit Admin
If anything, it would be != in this case.
Edit Admin
It's not getting a bool where an int should be. It's getting a bool where any object should be. It is looking for the index of true (presumably the result of newStatus > -1) in the array, not finding it, and returning -1 to signal it was not found in the array. The if looks at -1 and considers that as truthy. There's no JS weirdness here.
Edit Admin
JS is hardly the only language that automatically converts bools to integers. C and C++ don't even have a distinct boolean type. In Python,
boolis a subtype ofint. PHP automatically converts between bool and int in many contexts.Edit Admin
because pretty much all languages do that sadly. there were generations of developers who thought fortran was evil because it wouldn't let you do that, and c/c++/...(long list of languages) were awesome because they would.
Admin
Ehm, C++ always had separate bool (it is even considered fundamental type!).
Edit Admin
Errors like this are easy to make in dynamically typed languages. Personally, I prefer TypeScript to plain JavaScript for Node.js development.
Edit Admin
a) 'bool' wasn't a standard type until c++98
b) int to bool conversion, or vice versa, is implicit, so it's not really a lot of help in avoiding that particular type of problem. 'int a = b < 5;' will compile, setting a to 1 if b < 5 and 0 otherwise. And with most peoples compiler flags, it will compile without a warning.
Admin
Overassumption on my part - I read reportStatuses as a collection of enum values which (dangerously, I know) my brain still treats as ints. I think that's missing the point, however. Allowing differing types into the same collection is a grade A footgun, and I'm very much pro footgun control. JS, though, seems to made entirely of footguns that you have to carefully reposition. And is at the same time described as beginner-friendly because all those footguns don't care where you point them, so the fledgling dev doesn't have to, either. ( And yes, I know Python will let you do that as well. Doesn't mean I have to like it. IEnumerable<T> for me, please.)
Edit Admin
And before that, Perl. Happy to now have moved on to Dart, which has real types and can be compiled to JS to use browser-side and server side (node.js).
Edit Admin
That's because there weren't C++ standards until C++98, but
boolwas a type in C++, with all its current behaviour, almost right from the beginning.And it was first included as a standard type (with a different name, but the same behaviour as in C++) for C in C99, so we can regard it as pretty much settled as a standard type in both C and C++, for more than a quarter of a century.
Admin
You say that as if it was a long time. Kids these days...
Edit Admin
At least we've mostly managed to migrate away from K&R C these days.