• bvs23bkv33 (unregistered)

    that's racist

  • P (unregistered)

    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.

  • (nodebb)

    Last time I was this early, people still used compiled, static typed, unmanaged languages for high performance.

  • WTFguy (unregistered)

    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."

  • my name is missing (unregistered)

    High performance and javascript is certainly "interesting". So is the view from falling off of a cliff.

  • Scott (unregistered)

    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.

  • Structuring (unregistered)

    Can't you just use destructuring?

    const {field, ...output} = response;

  • masonwheeler (github)

    This is a relatively simple task, and one that has, in other variations, already been implemented in the codebase. Some of those proprietary enhancements are faster implementations of types like Set, so the basic approach would be:

    1. Load the blacklist into a Set
    2. Iterate over the items in reverse order
    3. Check if each item is in the set, and if so, remove it from the list using removeAt

    The Set is fast. By iterating in reverse order, you can change the length of the list without disrupting the for loop. removeAt is a direct access, which is also fast. Since performance is a concern, this is a pretty good solution.

    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.

  • PMF1 (unregistered) in reply to WTFguy

    Well, at least they're not doing premature optimization.

  • Not Donald Knuth (unregistered)

    Premature optimization is the root of all evil.

    This, however, would not be premature. Frankly, it's overdue.

  • qw3ry (unregistered) in reply to masonwheeler

    "Iterate over the items" != "Iterating over the blacklist". There are two collections being used here, only the blacklist is loaded into a set.

  • Shut the fuck up (unregistered) in reply to P

    Shut the fuck up

  • STrRedWolf (unregistered)

    TRWTF is JavaScript in a time/performance sensitive environment.

  • Simon (unregistered) in reply to masonwheeler

    Mason, the items to be checked are in a list; the blacklist is in a Set.

  • Fizzlecist (unregistered) in reply to STrRedWolf

    I think the language is the least of their worries when they use solutions like that.

  • Rob (unregistered)

    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.

  • Same Old Same Old (unregistered)

    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

  • Chris (unregistered) in reply to Rob

    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.

  • (nodebb) in reply to qw3ry

    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.

  • Solomon Ucko (google)

    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))

  • Stephan (unregistered)

    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.

Leave a comment on “A Blacklisted Senior”

Log In or post as a guest

Replying to comment #:

« Return to Article