Thoughts on Terminal and Object Orientated Programming

Chengzhou (James) Jiang
6 min readMay 21, 2020

--

Hi my name is Chengzhou Jiang. You can call me James. I just started learning programming, and I just want to share some of my thoughts and experience that you may also find useful. These are some points that I hope someone could have told when I first learned it, and they are the keys for me to understand the concepts.

If you are also a beginner just like me, or if you are a very experienced programmer and if you can recall when you first learned programming, one of the first things you may have struggled was to understand what a terminal is. Terminal is just a more annoying way to replace your mouse. Instead of hovering your mouse on a folder on your desktop called “Childhood_Photos” and double-click with the left button, you type in your terminal something like”cd Desktop/Childhood_Photos/”, enter, and type ”open .” Using a mouse is way easier for this task, but using the terminal is closer to the real process of how you open a folder. The fact that terminal is more fundamental means that terminal is capable of doing most things a mouse can do, but not vise versa. As a programmer, we need to do a lot of things that are easier to do with the terminal, not the mouse. Instead of talking to a foreigner through a translator, you can do better at communication if you know the foreign language yourself.

For me, the moment of enlightenment happened when I was playing minecraft. If you have played this game, you know the moment you see a creeper in your house that you have built for over an hour. The creeper twinkles like a shiny star over the galaxy on a clear summer night, and half of your house is gone. Your chest is broken, all the items dropped, and will disappear in 5 minutes. If you don’t play this game, this is the moment you want to rage quit because your real life is better. However, there is a way to escape. You can change the game mode to creative mode. Nothing will be gone, and you can rebuild your house in 5 minutes. All you need to do is type t, enter, a window pops up and you type /change gamemode creative, enter. And this is a terminal. This is something I don’t know how to do with my mouse. Without that, your diamonds are jeopardized as well as your best enchantments.

Some people call this cheating. I call this programming. Cheating is bad. Don’t cheat.

The second thing I want to talk about is Object Oriented Programming. One thing that really confused me and most online sources couldn’t explain very well was the question “what is an object?”. A question that now I wish someone could have asked me earlier when I was learning is “What is an object in real life?” I think everyone can answer this question. The computer in front of me is an object. The keyboard on my laptop is an object. My roommate is an object, etc.. Then I understood what it means by “Object Oriented Programming is trying to imitate real life”. You are creating a world in a programming file. It starts nothing, then you start to add new objects to this world to make this world more interesting. Say you want a cat, but your roommate is allergic to cats and also your landlord doesn’t allow pets. It’s very sad, but you want a cat so badly that you create a file on your desktop, called “a_new_world_cats.rb”. You open up the file and you start to create the world. In your world, you want a person, the protagonist. So you created your first object, or class. Then you want a cat, since that’s the purpose of creating this world. So now you have a second object, or class cat. Now, since you are the creator, you can create the cat whatever you want your cat to be. But on the other hand, your cat can’t do anything until you say so. Now you think about it. What makes a cat a cat? The object you just created is a cat but it can’t Meow, it won’t jump on your head, and it won’t die etc., until you say so. Then you ask yourself, what is the purpose of creating this world? If your answer is I want to hug my cat! Then you don’t need your cat to be able to jump on your head, you don’t need your cat to die, but you want your cat to be able to hug you and Meow. So you open up the file and create new methods under the cat class hug, and Meow. So in your world, a cat can only hug and Meow. If your answer is I want my cat to do my math homework. Then you need to add in your cat class a method called “doing math homework”. You need to teach your cat everything necessarily to do your math homework, and everything you teach is the content in the “doing math homework” method. Again, this cat in the world you created doesn’t need to know how to Meow or how to jump, but it is still an object called a cat. Compared to the real world object cat, who seems to be capable of infinite tasks, the cat you created is very simple. And the cat object you created and the cat object the other programmers created for a different purpose is also very different, even though they are the same object “cat” in real life.

Having this in mind, and if you look at the 4 principles of Object Orientated Programming, encapsulation, abstraction, inheritance, and polymorphism, it should make more sense. These principles are basically rules that you need to follow as a creator of your world.

Encapsulation. The real world is encapsulated. You don’t know anything about your cat without interaction. When you are at work, you may be worried if your cat is eating properly. You don’t know because you and your cat are encapsulated. However after you come home, you can see your cat running around and the cat bowl is empty and now you know that your cat ate properly. You are still encapsulated from your cat but through some interaction, you can know about your cat. Object Orientated Programming is imitating real life, so your created objects should work the same way. All the methods in the cat class are encapsulated so that the person class won’t know. However, in the person class, you can write methods like “feed the cat” that can generate interaction, so as a person, you have some clues about the cat. Without such interaction, the person shouldn’t know anything about the cat.

Abstraction. The real world is abstract. If you are like me, I don’t understand almost everything that I use everyday. I don’t know how cell phones work. I don’t know how cars work. I don’t know how my body managed to stop the blood after I accidentally cut my finger. But it is OK. We are living in a world that’s impossible to understand why everything works. The more important skill is having the precise expectation of how they work and knowing how to use them. Each inventor understands how that specific technology works, but there is no one who understands every technology. Same phenomenon appears in coding, when the world you created became so large and complicated that knowing how to use the methods becomes more important than knowing why these methods work. Take the “feed the cat” interaction method for example. You want to hug your cat. To do that, you need to let the person “feed the cat”, which makes the cat full, which makes the cat happy, which makes the cat want to play with you, which makes it hug you. This process is very long and complicated, and you may forget how it actually works some day. But what you should never forget is that feeding the cat would make it hug you.

Inharentence. As a creator, you realize that cats alone are not enough to keep you satisfied so you decide to create some other animals. After you create 5 other animals — dogs, pigs, cows, chicken and sheep, you realize they share a lot in common. They all need to eat. They all sleep. They all die. So instead of repeating the same method 5 more times, you can create an animal class, and every animal you create shares the same method at birth from the animal class. This is inharentence.

Polymorphism. After you create the animal class, you may ask, what if only the cats Meow? You can do so by creating its own methods in the cat class. This is Polymorphism.

--

--