You are at home and you are getting ready to go to the concert of the year! Shoes? Check. Wallet? Check. Cell phone? Check. You are about to walk out the door, but wait. Keys! Where did you put them? You search the house frantically, and 10 minutes later you find them. On the floor. Under a pile of clothes… Now you are late picking up your date. How could have you prevented this situation? By putting your keys where they are supposed to go. In the key bowl. Think of your house as your IDE. If you keep your house organized, you will know where all of your Objects are, and you will encounter fewer issues(bugs) when you are trying to find something.
One way that I have discovered to be a very helpful way to keep my IDE clean is commenting what each “end” is ending. Doing so, you will know exactly where everything should be going, and you will have fewer errors due to having end in the wrong place. Writing lots of comments is like writing labels on everything in your house so you or someone else visiting can find whatever they need.
Adapting from Procedural Programming to Object Oriented Programming is another way to keep your house(IDE) clean. You have a bunch of kitchen items in your house, and you are getting ready to set the table for dinner. Take a look of what you have in your house in the code below.
items = [“cats”, “Raspberry Pi”, “plate”, “knife”, “spatula”, “pot”, “pan”, “forks”, “can of black beans”, “etc.”]
Looking at the code above, I can see that we have forks somewhere in the house. But where? Dinner might get cold before you are able to find a fork to eat with! This is Procedural Programming, where all of your code is dumped into your house(IDE). Let’s get organized.
class Kitchen
def silverware_drawer silverware = [“forks”, “knifes”, “spoons”] end #of silverware
def pantry food = [“can of black beans”, “pasta”, “tomato soup”] end #of pantry
def cabinet cabinet_items = [“plates”, “bowls”, “cups”] end #of cabinet
end #of class Kitchen
Okay! Lets find the tomato soup because it is a cold day. Tomato soup is food, and you can see that it is stored in the food array. Great. Now we know that we have tomato soup, but where can you find it? The pantry. Where is the pantry? In the Kitchen. You know exactly where everything is, and what the purpose of everything is.
Keeping your silverware in the silverware drawer, food in the pantry, and cups in the cabinet is Object Oriented. The silverware drawer(object) has one purpose. Store silverware. Same with the pantry, and cabinet. Each are objects and serve a specific purpose.
Keeping a clean house(IDE) is essential to keep your life(program) in order. Stay organized and label everything, so you, or any of your guests will be able to know how your house(IDE) works. =)