- 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
that's racist
Admin
Annnnnnnd... after several day of decent WTFs we're back to the most mundane, boring kind of WTFs again.
You could replace "senior developer" to "self-taught crack coder" or "third-rate student" and it wouldn't make any difference. That's how you know the WTF is bad.
Admin
Last time I was this early, people still used compiled, static typed, unmanaged languages for high performance.
Admin
Where's the eval(...) of some long string expression constructed in O(m^2 * n^2) time with several intermediate variables round-tripping between Object, underlying int or bool, and stringly form?
Kids these days. What a weak effort.
But it does clearly demonstrate what happens when we get lots of people who think solely in terms like "first draft of simplest syntax = ideal code."
Admin
High performance and javascript is certainly "interesting". So is the view from falling off of a cliff.
Admin
Titles are meaningless, and should either be abandoned of more fully qualified. Someone might be good (i.e., "senior-level") at SQL development, for example, but suck in OO land.
Good management (rare) will understand people's strengths and find appropriate projects to take advantage of those strengths (or let them grow o non-critical projects in an area they're weaker). Poorer management will throw people at projects (you're a computer guy, right?) and hope it all works out.
Admin
Can't you just use destructuring?
const {field, ...output} = response;
Admin
That's a pretty good solution, except the name is TRWTF. A Set is an unordered collection; the concepts of "iterating over a set in reverse order" or "removeAt" are completely meaningless. What this is actually describing is a List collection.
Admin
Well, at least they're not doing premature optimization.
Admin
Premature optimization is the root of all evil.
This, however, would not be premature. Frankly, it's overdue.
Admin
"Iterate over the items" != "Iterating over the blacklist". There are two collections being used here, only the blacklist is loaded into a set.
Admin
Shut the fuck up
Admin
TRWTF is JavaScript in a time/performance sensitive environment.
Admin
Mason, the items to be checked are in a list; the blacklist is in a Set.
Admin
I think the language is the least of their worries when they use solutions like that.
Admin
Even if the developer didn't use a set for the blacklist, that's an object that has the same keys as the item tags, and boolean values. The existing code only removes items if both blacklist[blacklistElement] is true and item.tag === blacklistElement. In other words: if blacklist[item.tag] is true. That alone makes looping over the blacklist complete nonsense:
function getFilteredItems() { var items = getItems(); var blacklist = config.getBlacklist(); items.toArray().forEach(function (item) { if (blacklist[items.tag]) { items.remove(item); } }); return items; }
Still not as efficient as the set and iterating backwards solution, but still a lot better than what this developer produced.
Admin
Looks like more badly written first draft that worked ok for the test data and was slung into production without a second thought. Sometimes it's because they can't write better, often it's because there's no time
Admin
You're still taking a copy of the items, then working out which ones to remove, which is an O(n) operation itself. It would be better, and similar in terms of performance to the suggested method, to create a new list, and iterate over the original items list to determine which ones to add to the new list.
Admin
Re: "A set is an unordered collection, and a list is an ordered collection"
There is, of course, useful to have ordered sets, which are not ordered lists because there are no duplicates in ordered sets.
Admin
What about iterating over the items and copying the items that would be kept to an empty list? This should be O(n log(n))
Admin
The issue probably is here is that items.forEach() will fail when you change the collection while running a foreach over the same collection ( the items.remove call). By making an array of it first, the .remove and the .foreach are not on the same collection, so the loop will finish without crashing.