What is a deferred procedure?
Author |
Message |
Cezna
|
Posted: Sun Jun 06, 2010 1:18 pm Post subject: What is a deferred procedure? |
|
|
What exactly is a deferred procedure.
I am reading this tutorial: http://compsci.ca/v3/viewtopic.php?t=18779, and it mentions deferred procedures, but I have no idea what that is.
I looked in the Turing help files (the F10 help section, I mean), and the example there made no sense at all.
I am sure there is a simple explanation, so could someone maybe explain it and possibly give me a demonstration or an example of a situation where you would use a deferred procedure? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Sun Jun 06, 2010 3:08 pm Post subject: RE:What is a deferred procedure? |
|
|
Imagine a class for a shape, with subclasses for types of shapes (square, triangle, etc). If you were to create an "Area" method for the Shape class (so you can override it in the subclasses), what would be in it? There is no right answer cause Shape is an abstract concept, an idea, not an explicit object. This is what the deferred qualifier is for, to tell Turing that the class is abstract, and that to use it you need to make a subclass. |
|
|
|
|
|
Cezna
|
Posted: Mon Jun 07, 2010 5:42 am Post subject: RE:What is a deferred procedure? |
|
|
That's pretty much what the tutorial I was reading said, but I guess I don't really understand what a class is.
I thought I did, but if it was what I thought it was, then this stuff wouldn't make sense, so I must be confused on that point.
Could you maybe clarify this a little (I know it's not part of the question, but I am superbly confused at this point). |
|
|
|
|
|
chrisbrown
|
Posted: Mon Jun 07, 2010 10:13 am Post subject: Re: RE:What is a deferred procedure? |
|
|
Cezna @ Mon Jun 07, 2010 5:42 am wrote: I guess I don't really understand what a class is.
This might be a better starting point |
|
|
|
|
|
Cezna
|
Posted: Mon Jun 07, 2010 10:51 am Post subject: RE:What is a deferred procedure? |
|
|
I knew there must be a tutorial on classes somewhere.
Thanks for the help. |
|
|
|
|
|
chrisbrown
|
Posted: Mon Jun 07, 2010 12:23 pm Post subject: RE:What is a deferred procedure? |
|
|
Just a heads up: don't be frstrated if you dont understand them right away; it's one of those "AHA!" moments that you just have to work towards. Classes are a huge aspect of software design though, so they are worth the effort and will benefit you greatly in the future. |
|
|
|
|
|
TerranceN
|
Posted: Mon Jun 07, 2010 3:05 pm Post subject: RE:What is a deferred procedure? |
|
|
I completely agree with chrisbrown, Back when I was just beginning to learn about objects, I was using BlitzBasic and using the very limited 'type's (like Turing's 'record's). Through my code, you could see me slowly get better with them, though it took about a semester before I really started to understand the basics (no inheritance polymorphism and abstract types). It took me another semester to get good with inheritance and polymorphism in Turing. So don't worry if this doesn't just make sense like if statements. |
|
|
|
|
|
Cezna
|
Posted: Tue Jun 08, 2010 5:34 am Post subject: RE:What is a deferred procedure? |
|
|
Alright, I'll take a look at it, but I expect it's going to be a while before I start using anything like this (I'm still currently using those 'records' that TerranceN mentioned...) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Tue Jun 08, 2010 8:12 pm Post subject: Re: What is a deferred procedure? |
|
|
Don't worry, I was busy with other stuff at that time so I'm sure anyone could have learned faster during the summer. If you understand records, next work on creating functions that use that record, such as (for a player object) UpdatePlayer, DrawPlayer, etc, that take an instance of that record to edit as its first parameter. You will have to use the var keyword for this:
Turing: | % Define a type
type Vector2:
record
x : real
y : real
end record
% Define a constructor (it builds objects of type Vector2)
fcn NewVector2 (newX : real, newY : real) : Vector2
var newVector2 : Vector2
newVector2.x := newX
newVector2.y := newY
result newVector2
end NewVector2
% Define a function closely related to Vector2
fcn Length (object : Vector2 ) : real
result sqrt(object.x** 2 + object.y** 2)
end Length
% Define another function closely related to Vector2, notice the var keyword.
% This means the variable is passed instead of a copy and should be used when
% you need to edit values of the object sent. This also means you cannot pass
% 'Anonymous' objects to a var parameter, it MUST be a variable
proc PlusEquals (var object : Vector2, object2 : Vector2 )
object.x + = object2.x
object.y + = object2.y
end PlusEquals
% Allows us to neatly do complex things
var velocity : Vector2 := NewVector2 (1, 3)
PlusEquals (velocity, NewVector2 (2, 1)) % Add (2, 1) ending up with (3, 4)
put Length (velocity ) % Should output 5 if correct
|
All simple classes are, are an encapsulation of what we are doing. Instead of passing the object to the functions, the functions belong to each instance(each created version, even 'anonymous' ones) of the class (so they know what object to do stuff on).
Hope that makes things easier. |
|
|
|
|
|
Monduman11
|
Posted: Tue Jun 08, 2010 8:15 pm Post subject: RE:What is a deferred procedure? |
|
|
all i have to say Terrance is WOW, whenever i look at your coding it looks like a different language lol, guess i still have a lot to learn |
|
|
|
|
|
Cezna
|
Posted: Wed Jun 09, 2010 6:53 pm Post subject: RE:What is a deferred procedure? |
|
|
oh, I meant to say that I do know how to use records, and use them often when making all of my uber-fail particle engines and mind-numbingly boring games
But if records are to be used as an example to emphasize a lack of knowledge (as I interpreted your mention of them above), I should probably learn something a little more advanced, namely classes. |
|
|
|
|
|
TerranceN
|
Posted: Wed Jun 09, 2010 7:38 pm Post subject: Re: RE:What is a deferred procedure? |
|
|
Monduman11 @ Tue Jun 08, 2010 8:15 pm wrote: all i have to say Terrance is WOW, whenever i look at your coding it looks like a different language lol, guess i still have a lot to learn
There is always a lot more for everyone to learn (knowledge is limitless after all), the fact that you have broadened your horizons enough to realize that there is a lot more to learn is is a good thing. Some people will take a computer science course, never go outside the necessary (ie. only learn stuff they are taught in class) and think they have learned all there is to programming (that came out sounding more harsh than I intended, but w/e).
Cezna wrote:
oh, I meant to say that I do know how to use records, and use them often when making all of my uber-fail particle engines and mind-numbingly boring games
But if records are to be used as an example to emphasize a lack of knowledge (as I interpreted your mention of them above), I should probably learn something a little more advanced, namely classes.
Don't be so hard on yourself. IMO, the only failure in the programs and games you make for learning and fun is thinking that they are failures (if you were kidding then sorry for misinterpreting). Anyway, I didn't mean that records are a lack of knowledge, you could make a great game without objects, or even records (just look at Roller Coaster Tycoon, it's coded in mostly assembly), objects just help make code easier to write and understand to a human being. Finally, don't learn stuff because it is advanced, learn it because you are interested in it (and you clearly are considering you are the one who started this thread). |
|
|
|
|
|
Cezna
|
Posted: Wed Jun 09, 2010 8:07 pm Post subject: RE:What is a deferred procedure? |
|
|
I was kidding about the games (90% kidding), and think nothing of the now relevant apology in your above post, I sounded like a whiner even to myself.
As for the reassurances, thanks for the self esteem boost
Don't know what IMO means (hope it wasn't a typo, as that would make me feel like a skadoucher/jerk, whichever you prefer).
And finally, on the closing note of your post, I am very interested in classes, as you correctly assumed, and you can bet I will be reading that link posted above through about 42 times in the next few days, and eagerly await incorporating the new knowledge into my next program. |
|
|
|
|
|
|
|