Enterprise software development gets a bad rap, especially here, because "good code" isn't really a goal of an enterprise. Solving business problems is. And no enterprise is more enterprise than a government, and no government is more government than the US Federal government.

Which brings us to today's anonymous submitter, who wanted to keep up on current events in US politics. While watching some recent videos of Senate proceedings, our submitter got bored watching (as one would), they pulled up the browser tools. And that's where our WTF comes from.

So, in this code sample, each Senate committee has a different Akamai URL and ID for its videos. This is how the developer chose to represent that:

var streamInfo = new Array ( ["ag", "76440", "https://ag-f.akamaihd.net", "2036803", "agriculture"], ["aging", "76442", "https://aging-f.akamaihd.net", "2036801", "aging"], ["approps", "76441", "https://approps-f.akamaihd.net", "2036802", "appropriations"], ["armed", "76445", "https://armed-f.akamaihd.net", "2036800", "armedservices"], …, ["arch", "", "https://ussenate-f.akamaihd.net/"], ["uscp", "", "", "2043685", "uscp"], ["cio", "", "", "2043686", "cio"] );

Snipped for brevity. Ah, arrays containing arrays (where the inner arrays are really objects). That's always fun. What's extra fun is the way they search this.

for (var i = 0; i <streamInfo.length; i++) { for (var j = 0; j < streamInfo[i].length; j++){ if (comm === false ){ break; }else if (streamInfo[i][j] === comm) { var streamNum = streamInfo[i][j+1]; var streamDomain = streamInfo[i][j+2]; var streamID = streamInfo[i][j+3]; var msl3 = streamInfo[i][j+4]; break; }else { var streamArch = streamInfo[i][j+2]; break; } } }

The outer loop, quite reasonably, iterates across the array. The inner loop then iterates across the inner array. Well, it sort of would, if not for the fact that every branch in the loop breaks out of it. Because the goal isn't to loop at all, the goal is to check the first field in the inner array, and see if it matches the committee we're searching for. Then we populate some variables with the results- which has the added benefit of doing some variable hoisting which means that those variables exist in some larger scope, helping with the lack of readability. And I have no idea what's happening with streamArch, which points to the same field as streamDomain, but because of the outer loop, gets reset every time, meaning it'll just be an empty string, which is the last thing in the array.

As our submitter put it: "US Federal procurement hits the expected quality level."

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!