skull

Robert Tamayo

R
B
blog
skull

Are You Thinking, or Do You Just Think You're Thinking?

There is no such thing as "thinking in React". There is no "thinking in JavaScript"; there isn't even a "thinking in code". If you think that you are thinking in React, you only think you are thinking.

That's true by definition. If I am thinking in React, then technically React is doing the thinking. I am just the machine implementing React in order to think.

People say this often when describing how best to learn a second language. They say you aren't supposed to think in English and then translate it to Spanish before you say it. You are supposed to think in Spanish. The common belief is that language can really affect how you think about the world. For example, in Spanish, you "have hunger", but in English, you "are hungry".  In a Spanish speaker's worldview, they see hunger fundamentally differently than an English speaker would. In the Object Oriented Programming world, this is a huge distinction, and is-a vs has-a is one of the first things people learn about.

Consider this distinction in programming terms. Let's implement a Human who is hungry in both Spanish and English:

// Spanish
class Human {
    Hunger hunger;
}
// English
class Human extends Hungry {}

It's actually much easier to work with the Spanish implementation than the English one. The Spanish one can be reused, and different attributes can be added to it without affected the original Human object. We can refactor the Hunger reference to be an array of Attributes instead, and let Hunger be a subclass of Attribute. In this way we can easily check the attribute list to see if the Human currently has any of cold, hunger, thirst, and so on. In the English version, I would have to recreate the object each time, and if it had multiple attributes, it would require classes with all of the different variations.

But let's be realistic. Neither implementation would pass code review, because the attributes should be private and either stored as an array of Attributes or a bunch of boolean values, and the hasHunger() or isHungry() check should return a boolean, with the implementation details behind a black box. 

Clearly boolean language was influenced by English speakers, because were it influenced by Spanish speakers the standard getter would be hasBoolean() instead. The result would be the same. And that's the point.

That's becuase you don't actually think in English. Or Spanish. You don't think in React. You translate all of the "real" thought, whether you call it metathought, or whatever happens in what I call "the place before thought", into a language for the purpose of communicating with another entity that also understands it. I communicate with the machine through Java to tell it to check if the enemy isAngry(). This "place before thought" is what is actually doing the thinking. The real thinking. The place before thought is where you hear Spanish and don't think "perro, dog", but rather just hear "perro" and know what's going on. The place before thought is what I'm trying to talk to when I talk to someone. I am getting things from my place before thought to theirs. That's why people can be talking to each other in different languages, and no meaning is lost between the answer "Yes, I'm hungry" and the question "Tienes hambre?" The place before thought is the black box, where the private members cannot be accessed directly, but only by getter functions.

Back to "Thinking in React". Don't get caught in that mindset when learning a new framework or a new language. Don't think in React. Think in the fundamental principles. React manages state. Think in managing state. How do YOU need to use and manage state? Forget about React while thinking about the problem. React is result of people thinking about managing state. They came up with a framework for doing so, a language. Now they say "setState()". 

What if you thought about managing state? What language or framework would you come up with? For me, it's usually none. I think about the problem and solve the problem. I start from the place before thought and work my way outward from there.
Comments:
Leave a Comment
Submit