Hacker News new | past | comments | ask | show | jobs | submit login

They don't "do nothing" - they define structure that can then be used to handle more implementation later. It's a ridiculous, contrived example, and you know that.

Yes – this code is stupid if all you need to implement is a single line with the ability for a player to hit a monster. But that's never what you are implementing, is it?




If you want to delay the hit, i.e. transactioning / buffering / delaying: This is sound engineering! But that part is not even included in above boilerplate. It would be:

    struct PlayerMonsterWeaponHit {
        Player player;
        Monster monster;
        Weapon weapon;
    }

    Array<PlayerMonsterWeaponHit> playerMonsterWeaponHits;

    doTheActualFrigginHit(Player player, Monster monster, Weapon weapon) {
        playerMonsterWeaponHits.emplace(player, monster, weapon);
    }
In case it isn't obvious you can do that with either implementation, the above OOP boilerplate or the above imperative 1 line of code.

> Yes – this code is stupid if all you need to implement is a single line

No, it's stupid because it doesn't do anything. The data structures are only for temporaries that will never have any other use. In the end it's going to be PlayerMonsterWeaponHit. So the other classes are just stupid, and no amount of context will change that.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: