Discussion Forums  >  BT.com Website, Account Questions

Replies: 7    Views: 182

Feather
I hate code!
Profile
Posts: 22
Reg: Oct 22, 2013
San Diego
7,720
12/14/13 02:08 PM (7 years ago)

Definitions and terms for the going insane...

Hi all,

So MrVanBeveren and I are currently trying to work through a few books on Objective-C. It's going well so far but we've hit a few snags. These books explain minimally what the terms are they are using, and sometimes, they don't explain them at all. Paragraphs become written in Chinese as we start reading things with terms that we don't understand.

If anyone could help with the definitions were having trouble with it would mean the world to us. We've read, "A class describes the behavior of an object" and "An object is an instance of a class". That's great, but now we don't understand either word and we're just as confused as we were. (IE: so a object is an instance of a class, but what the heck is a instance or a class!) The books tends to describe new terms with new terms, (or terms were still not 100% on) so we don't understand it.

What we do understand: variables, local / global variables, float, int, char (types of variables), if statement, while loop, functions, frameworks, return, include, nslog.. and a few others.

What we don't understand:

1. Class (a .m file?)
2. Object (data? data inside a variable?)
3. Instance variable (we know what variable is)
4. Method (another word for function?)
5. Argument (the code inside a function?)
6. The heap
7. Pass (send?)
8. why would you use struct?
9. Stack, pop stack (the order of how the code is run?)

@Smug has been helping us too, but I hate bothering him all the time (we don't want to take advantage of his kindness), David already does enough of that (:

Is it possible that someone here could explain those terms to us in the most simplistic manner possible, without using more terms to describe them (unless you described the other terms beforehand!). And if you can take it one step further.. even provide a line of code to show the example?

I know this is a lot of us to ask, so I understand if you can only give basic answers. If someone already answered here.. feel free to put your own answer, it might help us if we read multiple ways of describing the terms.. we're working hard to learn Objective-C and we spend 3 hours a day on it now!

Thanks!

~Samantha~
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
12/14/13 02:29 PM (7 years ago)
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
12/14/13 02:39 PM (7 years ago)
3. Instance variable is just a variable that is attached to a class or object.
Class: car
instance variable: color

object with variable: nissan.color = yellow.

4. Yes a method is a function but once again it is attached to an class or object. The method tells the object to do something
class method: drive()
object with method: nissan.drive()
or [nissan drive];

Hope I am not adding to your confusion. OOP has a steep learning curve but is very rewarding once it clicks.
 
Stobe
buzztouch Evangelist
Profile
Posts: 1527
Reg: Mar 04, 2011
Fredericksburg,...
24,670
like
12/14/13 06:52 PM (7 years ago)
Many different ways to learn these terms with different analogies.

Here's a cute one:

http://blog.momswithapps.com/2013/01/26/object-oriented-programming-terminology-with-cats/
 
Jake Chasan
Veteran developer
Profile
Posts: 1684
Reg: May 13, 2011
location unknow...
29,640
like
12/14/13 09:49 PM (7 years ago)
Here are some definitions:

1. Class (a .m file?) - A block of code called by a "main" function, this has "inherited' methods from other files (or classes)
2. Object (data? data inside a variable?) - A variable with various properties which can be accessed. "Instances" of these variables are created. Think of an object as a person. David and Sam are both people, but they are not the same person.
3. Instance variable (we know what variable is) - A variable that is attached to an object. Think of this as a person's coat. Both Sam and David have a coats, but they are different colors.
4. Method (another word for function?) - Another word for a function. Methods can either be "Class" (does not require an object to access) or "Instance" (requires an instance of a class [an object] to access)
5. Argument (the code inside a function?) - like a parameter, what is passed into the method
6. The heap - the part of the ram which holds objects
7. Pass (send?) - send, either by value or by reference
8. why would you use struct? - to possibly create an enumerated type (you will probably not have to use this)
9. Stack, pop stack (the order of how the code is run?) - the list of method on the ram

Does this help?

Jake
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
12/14/13 11:17 PM (7 years ago)
A class is a description of an object and resides in code only. When the program runs and when a command to create the object in memory is executed, the operating system allocates a portion of the memory to the representation of the class. That "portion of the memory" is called "instance of the class". Technically, the system creates a pointer, a normal variable which points to the portion of the memory where the instance resides.

In time, there may be many such "portions of the memory" and there must be a way to know which will be accessed and/or executed upon. The fastest way for the computer to know what to execute next is to create a "heap". Consider taking four books and putting them one on another. When you want to read them, the easiest way would be to take the topmost book and read it. Once you read it, take it away from the "heap". What was the second book from from top is now the first book on the heap. Now let computer always execute only the first element of the heap, because the hardware works fastest that way. To make the analogy complete, now imagine that you have four books randomly placed in the room, and that you have only four tiny pieces of paper on the heap. Taking an element of the heap now will not fetch you a book, but just its location in the room. If you want to read the book, you go to the place where the book is. Once finished reading that book, you return to the heap to see what to do next.

Now, let us turn back to the computer without analogy with books. There will be a piece of memory in which the heap will reside. Elements of the heap are addresses. The computer looks only to the heap and executes only one on the top. Why? Because it is fastest way hardware wise. The address on the heap may lead to another piece of memory where the instance of the object resides. The object is a mixture of data and code (the methods you write in the OO programming language became the code in the instance of the object). Once the instance is executed, a return statement will always be executed in its end, which will turn the control to the operating system, and it will do "its thing", which is go again to the heap (actually, to the top of the heap), assess the address there and repeat the entire procedure.

In the early days of computing, the most frequent error in programming was to take too much space on the heap. That resulted in so-called "stack overflow", meaning that the program tried to take all the space that the system had for stack. Which is exactly why the most popular site for programmers is called SO, short for StackOverflow... If you were a programmer, you would instinctively know what the site is for, and if you were not, you couldn't care less!

Hope that it sheds some light for you!
 
peterj
Apple Fan
Profile
Posts: 113
Reg: Jun 19, 2011
location unknow...
6,630
like
12/15/13 07:13 AM (7 years ago)
The tutorials at raywenderlich.com were also helpful for me. If you have an iPhone, iPad, or a mac you might consider watching a few of the lectures in Stanford's CS106a "Programming Methodologies" class on iTunes University. If you raised an eyebrow at the title, don't worry; it aims to teach new people how to be good programmers. Watching the first few lectures gave me that "a-ha" moment that nadthevlad is talking about.
 
CSSZiegler
I hate code!
Profile
Posts: 173
Reg: May 30, 2012
Monsey, New Yor...
12,930
like
12/16/13 10:54 AM (7 years ago)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.