CodeSOD: Answer the Questions on this Test
Jake works in Python. Python is a very flexible language, and Jake has some co-workers who like to exploit it as much as possible.
Specifically, they're notorious for taking advantage of how any symbol can be redefined, as needed. Is int a built-in function? Yes. But what if you want to have a variable called int? No problem! Just go ahead and do it. Python won't mind if you do int = int(5).
Sure, any linter will complain about the possible confusion, but do you really think this developer checks the linter output?
Now, this particular block of code happens to be a test, which Jake provided because it's one of the more head-scratching versions of this pattern, but it's representative of this approach.
def test_parameters(self, name, value, float = True): fcb = read_parameters(SERVER_ADDRESS) type = '' if valid_key(): type = 'float' if type == 'float': self.assertTrue(float) else: self.assertFalse(float) if float: self.assertEqual(global_name, name) default = fcb.get_default(name) self.assertEqual(default, value) range = fcb.get_range(name) ...
type, float and range are all built-in types in Python. Using variables with that name are not a great choice, but honestly, that's little stuff compared to the general weirdness of this test.
First, we have the pattern where we set a variable and then immediately check its value. It's probably a case where they indented incorrectly, but honestly, it's a little hard to be sure.
global_name is one of the rare things that has a vaguely accurate name, as it's actually a global variable. In a test. That's definitely a bad idea.
But the real problem, and the real WTF here, is: what is this test about? Are we checking whether or not parameters are properly assigned their type? Are we checking that the name matches up with a global variable? How is that global variable getting set? Does it tie into the mysterious no-parameter valid_key method? If this is what one test looks like, what does the rest of the code look like?
There are a lot of questions that this block opens up, but the real question is: do I want the answer to any of those questions?
Probably not.
[Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more.