I heard someone once referenced as saying something to the effect that people who learned how to program in procedural methods would never make the transition to Object Oriented Programming (OOP).
I don’t believe this is true. We can do anything we put our minds and effort to!
Working in the OO realm is both very much the association between things (objects) as well as the things (objects) themselves. Once you learn to think like this, your writing will reflect this concept. The code begins to become an extension of thought, and once thought is ordered in line with the syntax of the language, things will more readily be written into existence.
I want to draw on a parallel with learning a spoken language. Why do immersive courses have some of the highest success rates for students emerging with not only a strong grasp on the language, but more importantly, on the conveyance of thoughts and ideas through the contraints and filters of cultural aspects?
Let’s say there are two people learning to speak Spanish. In this example, the first person, “Bob” is learning in a standard classroom environment. The second person, “Dave” is learning by being placed in a home in Mexico. While Bob has access to all forms of media, what Bob lacks is the cultural impression which has given rise to the language. Dave, while lacking any formal text, has all of the cultural impressions constantly surrounding him.
Both will likely begin to piece things together, slowly compiling useful phrases and words into their knowledgebase. The difference is Dave will always be in a position of need based learning, while Bob has the luxury of putting off the necessary by falling back to his native language. In other words, if Bob needs to use the restroom in a restauarant, he simply needs to fall back and ask “Where is the bathroom”? Dave will likely at first fumble on his first attempt, crudely and very un-natively forcing out “Dónde - está - el - baño”?. Bob will mutter these words to himself at home, over and over. Maybe he’ll take a trip to a location where Spanish is spoken and try out his new phrase. Over time both Bob and Dave will have compiled a list of phrases and words.
The big difference is that Dave will have the distinct advantage of association and context. Within a month, where is the bathroom sounds like “Permíso, Dondesta el bano” (dropping the “con” and stringing donde and esta together)? Dave has begun to master context. When, where and how it sounds right. The words are conveyances of ideas, with little importance placed anymore on the individual words themselfs. Bob is likely still stuck on the words.
With that, learn to begin to see your code not as a list of words and instructions, but as conveyances for ideas.
When you see
class Box
attr_accessor :a, :b, :c, :d
def initialize(a,b,c,d)
@a = a
@b = b
@c = c
@d = d
end
end
You will go from reading and associating what a, b, c, d are within the context, to simply seeing a box with four sides. It would be ok, and arguably very important, to ask yourself questions at this point: “Where is the top and bottom”? “Couldn’t they all be the same size or only two sizes”? to a likely conclusion “Oh, it’s a box without a top or bottom, that for some reason needs to identify it’s sides to the world”.
So if you grew up like Bob, learn to think like Dave. You have the grammar, now just seek the context.