Inform: A brief note on encapsulation

I need to recap earlier chapters, but I’m currently reading the chapter on Advanced Actions and this bit just grabbed me in that “just blog this immediately” sort of way.

12.10. Action variables And we will want the photographing action to have the player use the best-quality camera which comes to hand. We will give the action a variable called the ‘camera photographed with’, thus:

The photographing action has an object called the camera photographed with.

Every action’s variables must be named differently from those of all other actions, because there are some “before” rules (for instance) which take effect for many different actions, and which might need access to any of their variables. So action variables should be named in a way marking out to which action they belong. The best way to do this is to include the past participle of the action name – just as “camera photographed with” contains the past participle “photographed” of the action “photographing”.
A stuffy OOP programmer could look down his nose at this – why, you’re asking me to simply name global variables with an identifier???!?! What about encapsulation?!!! And yet, the solution results in totally reasonable, fully comprehensible English. After all, language isn’t encapsulated. Oh, sure, there are some things we understand best within a particular context, or meanings that change depending on context. But nothing’s stopping me from referring to calipers while in a kitchen. The English language has no mechanism for programming’s encapsulation, and yet somehow we get by.


Posted

in

by

Tags: