Actions, Objects, and Context
Nouns
Nouns describe things: objects.
- The noun itself carries some description of the thing: “rabbit”
- That description can be extended through adjectives: “dark rabbit”
Nouns have a limited context. They give you a concept of a thing at a particular snapshot in time. Without more context, they are limited.
Think of full sentences:
- car
- What does this mean? It doesn’t convey much information without more context.
- If you Google “car”, you get a lot of very broad results – but does it help you solve your problem?
- move car
- Full context, assuming a car can move. Grammatically limited, but gives a broader idea.
- You can Google “move car” and it gives very specific, contextually useful results.
Verbs
Verbs describe an action.
- The verb itself carries some description of some degree of change or ownership: “hopping”
- That description can be extended to give you a different resulting action: “quickly”
Verbs have a limited context. They give you a concept of an action being performed. But, they don’t tell you what the action is being performed on.
Think of full sentences:
- move
- Some context, but move what?
- move car
- Full context, but the verb can be applied to many different nouns.
Context
Context provides the missing link that chains together nouns and verbs – objects and actions.
- An object describes the state of something, but a static state is of limited use.
- A verb describes some useful transformation, but you don’t know what it’s being applied to.
Context can also be chained to further describe the full environment.
“dark rabbit hopping quickly uphill”
- Gives a broad description of the environment.
- Note how most of the context describes modifications of the action.
- “rabbit quickly” doesn’t make sense.
- “dark rabbit” gives a sense of identification, to pick out an object from a crowd.
- “rabbit uphill” gives a sense of position in space, but little else.
- “hopping uphill” gives you a more focused description of what’s going on.
- It provides an action, a sense of position, and carries implications for how that action is performed.
- “uphill” can mean both a position at some point in time, as well as a modification of how the “hopping” action is performed.
What Does All This Word Play Have to Do with Software?
Verbs describe a series of functional operations, or transformations that are taking place. Nouns describe a state of an object at some point in time.
When you’re developing software, which of these two you choose to focus on will have major implications on the form of your code.
You can think of verbs as Declarative Programming. (AKA functional programming)
You can think of objects as Object Oriented Programming. (AKA imperative programming)
Objects are useful things, but they don’t make sense as a group unless under certain contexts:
- car, rabbit, mouse – these objects are interesting on their own, but together as a group, they don’t make much sense.
- car, car, car – this provides a little more context; we know we’re talking about a collection of cars. But it’s the action we perform on the collection itself that is usually the interesting part.
In code, this might look like:
List<Car> cars = new List[] { car1, car2, car3 };
Actions ultimately mean nothing without an object to perform the action upon, but they can be combined in interesting ways:
- paint move smash – we don’t know what object we’re acting upon, but this gives the sense that we’re painting something, moving it, then smashing it. All we need is an object to apply to the chain to get an interesting result.
- We can apply the same set of operations to many different objects, if we like: cars, boxes, or rabbits (poor rabbits!)
In code, this might look like:
Paint(obj); Move(obj); Smash(obj); // or, if each operation returned an intermediate result: obj.Paint().Move().Smash();
Which looks more like a useful piece of code to reuse in a library? The list example itself would need to be converted to an action to be reused (e.g., “GetListOfCars()”).
Conclusion
Both actions and objects are important. But, approaching design as different kinds of actions that can be applied allows you to leverage and reuse the same code to perform many different tasks – standard libraries are usually designed from an actionable perspective, which is what makes them so powerful. Objects tend to only be specifically interesting at their start and end point of a transformation – the particular snapshots in time that you really care about.
Another way to think about it is that objects describe a static state, but actions are required to both build an initial state and to perform transitions between states.
You must be logged in to post a comment.