Exceptions are nice, but…


Mech Retriever Dev Blog

It’s important to restructure your code as you go–partly because the code you don’t write is important.

For example, a lot of times it makes sense to have your code throw exceptions when it encounters a bad state.  But if you can, it’s always better to make it so the code cannot enter that state, so that you don’t have to worry about the condition in the first place.

This is primarily driven by object design–specifically, how you design the “public interface,” or variables and methods that other objects can see, though internal implementations can affect it too.  For example, when I changed the BattleScreenDriver to use one View per player instead of using one View for all, I no longer needed to supply a player argument for commands to the driver (e.g. Move) and so didn’t need to check to make sure players didn’t call moves out of turn.

A weird mantra I almost espouse sometimes is “try to avoid writing code,” which seems odd for a developer to say, but what I really mean is that you should try to avoid writing unnecessary code.

Like, Share, Subscribe, or Tweet us!

Check us out on Youtube or Deviantart!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s