Usually, when writing or explaining code to others, someone inevitably claims "Oh, I don't think like a computer". My response is usually the same. We created the computers, so really, don't computers think like us?
The conundrum of human thought is that it is naturally very disorganized. We like to believe that we navigate our thoughts clearly and directly. When these thoughts are under scrutiny of others they often fall apart.
Try the following exercise with a friend: ask them for instructions on how to make a peanut butter sandwich. When they say "Open the jar", bang the jar against the counter quizzically until they clarify it should be twisted. Only after many comical attempts can you achieve the desired result. Whether this is a coding application, scientific methodology, or even a basic cooking task, mapping your thoughts to an exact sequence of actions will lead one awry.
However, it is not only the precision of the instructed task to the mapping, but the meaning behind the task as well. For what reason are we opening the jar? If the goal is the peanut butter sandwich, we may need to check if there is suitable bread first. Is the sandwich for now, or later? If the latter, would anyone have an allergy? Are we able to find a suitable alternative to feed ourselves? We should always check our end goal first before we begin on the path of instructing specific tasks.
I refer to "Semantic Coding" as the alignment of meaning of your code to the solution presented. A solution can be clear, concise, and efficiently executed and still not be a suitable solution for a problem. My favorite example is the pharmacy layout. Often times, the cold and flu medication is laid out in front of the cash register, which is also conveniently near where perscriptions are filled. This serves three purposes:
- Customers can pick up their medication and pay right away
- Customers may imulsively pick up cold medicine as part of point of placement purchase
- Customers can pick up their medication as well as immediate symptom relief
However, there is a critical semantic misalignment with this situation. Many medications are immunosuppressants, so if someone wishes to have their prescription filled, they are immedately directed to the most dangerous region in the building: where people are coughing and sneezing.
When you have a clear and well-laid out solution, take a moment to consider if it aligns with your overall goal.