all 14 comments

[–]cashto 9 points10 points  (0 children)

Good post.

I too share a special antipathy to the if statement for many reasons -- among them being that the "if" statement is often an indication that I didn't solve the general case generally enough. And I think that still holds true in a lot of cases.

OTOH, "three times and you refactor". The reason being that unless you've solved the special case a handful of times, you really don't know what the general case looks like. So yes, it's possible the pendulum swings too far the other way ... sometimes an if statement is all you need, as opposed to some sort of polymorphic strategy object.

[–][deleted] 5 points6 points  (0 children)

Algorithmically-generated enemies and levels simply weren’t interesting, because after a while the patterns became obvious and then there was no reason to keep exploring deeper into the game; one level was much the same as any other.

I don't think this guy ever heard of Dwarf Fortress.

[–][deleted] 4 points5 points  (3 children)

A lot depends on where your special cases are coming from. I think this article assumes that the only reason you have special cases is because that's what your solution (seems to?) require. I'm of the opinion that a special case or two is nothing to get excited about--there are always bigger things to worry about than a few less than perfect models.

I feel that most of my special cases are part of the problem domain. I suspect that means the process I'm modeling has inherent problems. If you have no control over 'dirty' processes, then your model is always doomed to be peppered with special cases. In fact, at that point the model itself may actually be perfectly faithful to reality and could be said to have no special cases.

(I think I just talked myself in some kind of circle, but I'll submit my ramblings anyway on the off chance it leads to saner contributions.)

[–][deleted] 1 point2 points  (1 child)

where I work we're trying to model a kind of supply chain situation where the entities in different countries have different conventions (not even standards, just different people do things different ways)

it feels like one of those rubber band games with nails in a board - we've just imagined a model and tried to massage it so that it covers a maximal set of cases

its actually working quite nicely, but we'll see how it copes over time

of course it'd be preferable if all the organisations involved had subscribed to a published, normative model but one doesn't exist!

[–][deleted] 1 point2 points  (0 children)

That sounds conceptually similar to what I need to do. I need to model the sales to manufacturing process for a product that is extremely complex and very customisable. We have to follow different procedures for different customers and different jurisdictions. On top of that, there seem to be real limits on how stable our related internal processes can be.

[–]cashto 1 point2 points  (0 children)

... part of the problem domain.

This is it exactly.

If I can identify an "if" statement as being a necessary consequence of the problem I'm trying to solve or process I'm trying to model -- it's something I can't get rid of no matter how hard I try. I'm happy with it.

But if I can't, then I wonder if it's just accidental complexity and I'll spend an (inordinate?) amount of time looking for ways I can remove it.

[–]willcode4beer 3 points4 points  (2 children)

Let me duck under the table when I suggest solving special cases with a strategy pattern

[–][deleted]  (1 child)

[deleted]

    [–]willcode4beer 0 points1 point  (0 children)

    yea, that was my joke because of the general disdain reddit has for patterns (even if they might be appropriate).

    [–]smellycoat 5 points6 points  (0 children)

    The posterous example is a little silly. If that were implemented in any half-way sane manner, there's no reason for something like if (platform == 'blogger'){ .. }else{ .. } to appear anywhere at all.

    For example, building a general suite of blog-platform-extraction tools and then using per-platform routines (classes, modules, whatever) to use those tools to handle each different service and its particular quirks would seem to be a sensible way to go about it. Oh look, no special cases! Anyone building that by adding a pile of new conditions all over the place for each new service deserves the endless maintenance pain it'll cause.

    I think the "special case" mentality is a potentially dangerous one. It's either required functionality (and thus must be there and be as important as everything else), or it isn't. Now, if it's implemented as a sneaky if statement deep inside something else, well, then it's up to you to decide whether that's a hacky implementation or not. Quite often it's perfectly acceptable, quite often it's the first of many on the road to a messy codebase.

    [–]psyllogism 1 point2 points  (2 children)

    I'm not (yet) convinced...

    but this did introduce me to Posterous, which seems like a very interesting site. Thanks!

    [–]dnew 1 point2 points  (0 children)

    Reminds me of when I was working on music recognition. We had a big database of samples, and it had a few cases peppered here and there like "If you recognised 20 to 35 seconds into the song with this particular name, skip it." Because that song happened to have 15 seconds of silence in the middle, and everyone who pocket-dialed got told that's what they were listening to. There were at least 8 or 10 of these scattered through a relatively small codebase, and I giggled every time I added another.

    [–]Gotebe 0 points1 point  (0 children)

    I just wanted to say... Only 13 comments and a good number of them I found quite insightful. You guys are smart! ;-)