Hacker News new | ask | show | jobs
by tomc1985 2074 days ago
I mean, that isn't exactly hideous code. Sometimes you need to check a variety of different conditions in sequence, and I don't think a switch statement works here.

So what if they're different types? It's not like your passing those variables to functions right there. And are we really so robotic that we can't understand different types in a conditional?

Except the recursive function bit. Why bother if its always false...

2 comments

> It's not like your passing those variables to functions right there

Yes it did. Case blocks had several lines.

>So what if they're different types?

It makes it hard to read and destroys expectation of what possible cases there are. It makes it hard to test as a lot of test preparation/mocking is necessary.

>Except the recursive function bit. Why bother if its always false...

Yea, that the point! Because there was no test for it

Wait, so what's the remedy for the different types issue then? Should he coerce all these diverse types into one type just to do the comparison? That just seems wasteful.

Assuming he has to do the check that way, of course.

Better question is "Why are they gating all this crap here like that? What is the presumed set of expected outcomes?". This code is bordering somewhere on the line between sabotage and incompetence and it smells really bad.
My solution was to change the checks into single methods and move one god-decision-making-method into classes that are components with their own logic.
> I mean, that isn't exactly hideous code

It is. When you read it in isolation here, it's fine. If you have to read pages and pages of it and you have to concentrate/have half your brain working on the logic of the code, you don't want to annoy your brain with details like these.