Programming 101

1 view
Skip to first unread message

Yasmine Mustafa

unread,
Oct 27, 2009, 6:04:19 PM10/27/09
to learn...@googlegroups.com
Hi All,

It's been a little difficult keeping up virtually. However, I'm extremely committed to learning the fundamentals of programming so I had a friend (he actually came from Etsy) take me through an example I didn't understand in Chapter 3 earlier today. Before he explained to me what I did wrong, he decided to explain the core of programming in his own words to help me wrap my head around it. I don't know if anyone else is in the same boat but I come from a business background and have no technical experience whatsoever. Anyway, his two-minute explanation helped me so much, I decided to send it along in case someone else can benefit from it (see below). We talked via Gchat so I tried to clean it up as best as I could. 

Best,

Yasmine

-------------------------------------------------------------------------------------------------------------------------

To make programming easier, people structure programs after how the world is structured. The world is full of objects - they have certain characteristics and can do certain actions. Here's an example: Take a cat. A cat as fur (it's long or short), it has a color, it has a certain number of legs and it can do certain actions. It can eat, sleep, purr, meow, etc. In programming you create blueprints that will create these objects for you. Those are called classes, just like blueprints tell how to build a house. Classes in programming tell how to build an object. The attributes or variables of that class give the object its characteristics. The methods or functions of that class give that objects its actions and behaviors. 

The next part about programming is drilling down a littler further. Those attributes have certain types - lists, integers, floating numbers, strings of text. The actions or methods of a class/object modify or notify the value of those attributes. Here is a real example:
class Cat:
legs = 4
def getNumberOfLegs():
return legs

Here I have created a blueprint for making "cats" inside of my program. It has an attribute - to represent the number of legs, my cat has this is in integer 4. Then I define an action for the cat, asking it how many legs it has. It will then tell me when I ask it (return legs) and if you can understand that, the rest is just details on how to do that in a more advanced way. The last part to all of this is controlling how information flows through a program. It's called "Flow control" and it's like getting directions to a party. If the light is green, go through the intersection, cross 5 more roads, when you come to the stop sign, turn right. That's flow control and you use it to make your program dynamic so it has some logic to it. Here's an example
if cat.isHungry():
cat.feed("Some food")
if the cat is hungry, feed the cat some food
now you really know everything

The following discusses syntax and how/when it should be used: 
It varys from language to language, but they're all VERY closely related. Think of it like romance languages. Spanish and Italian are REALLY close, but different languages. So are PHP and Python. Here's how you know when to use different syntax: 
  • when you want your object to do an action, you use parenthesis
  • when you define a new action/behavior for your object, you use parenthesis
  • when you're looking at a single attribute, you don't use them
For example: 
Can you do things with your legs? Sure you can. You can run(), walk() kick() stomp(). But if you're just looking at your legs, are they doing anything? Nope. You're looking at your.legs. Ex. cat.legs, dog.legs. 


Reply all
Reply to author
Forward
0 new messages