OOP?
firestorm.v1
Posts: 94
I'm having problems wrapping my brain around the Object Oriented Programming (OOP) that is used on the propeller and I am hoping that someone can clarify or serve to smack me upside the head if need be.
My background is not impressive at all, just some basic, pascal and PHP web coding however none of them are declared as "object oriented". I believe that all these languages are "linear"?
Are these "objects" similar to includes in php? (another file/container that makes more code available to the proc) Do all included objects require another cog or can they just be a function repository?
Thank you for your help. Any suggestions are appreciated.
My background is not impressive at all, just some basic, pascal and PHP web coding however none of them are declared as "object oriented". I believe that all these languages are "linear"?
Are these "objects" similar to includes in php? (another file/container that makes more code available to the proc) Do all included objects require another cog or can they just be a function repository?
Thank you for your help. Any suggestions are appreciated.
Comments
Objects are basically a function repository, but there are some objects which require a cog (sometimes two). It depends on the object.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Are you addicted to technology or Micro-controllers..... then checkout the forums at Savage Circuits. Learn to build your own Gizmos!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
about cogs and objects
best regards
Stefan
Think of an OBJECT as a BLACK BOX with Inputs and Outputs.
·
You can Put things into the box and it then churns and does something and then outputs something….or….does some action.
·
If you now have many black boxes that do various things and you put them together to build a SYSTEM where you MAY use the outputs
of some of the boxes as input to other boxes or to have some of the boxes do some things and others do other things THEN….you have a system.
·
So you can think of your system as having used OBJECTS in unison to do a complex ACTION.
·
You may even think of your NEW SYSTEM in itself as a NEW object which others may use as PART of their even more complex systems.
·
Thus an object is an ACTION PERFORMING system that performs its actions depending on how you pass it certain commands or parameters
and its actions could be a combination of giving you·back new values and/or doing something physical (e.g. driving a motor or reading a thermometer).
·
In Spin an object is a FILE.
In the file there are FUNCTIONS· (methods)
There·are also VARIABLES and DATA
·
Now the object may (as I said above) be in itself a collection of other objects all encapsulated within the new object. So the file may use other files.
·
In your program you indicate to the compiler that you want to use this file. BUT…you also give this object a NAME· (not the file name a different name).
This name is then used to·access the ACTIONS of the object.
·
For example lets take the FullDuplexSerial object. It is a file on the hard drive called FullDuplexSerial.SPIN.
·
You use it in your program by saying
·
Obj
·· Debug : “FullDuplexSerial”
·
The above is telling the compiler to use the file by the name given but to also to NAME the object DEBUG.
·
Now the new object called Debug can be used to do things. For example you can transmit over the serial lines a character
by saying Debug.Tx(n) where n is the Ascii code of the character.
So how does this work?? Well, the object has a METHOD in it …..we do not need to know·how it DOES its works….
we just need to know·how to USE IT. So we know that the method is called TX() and that it needs to be given the Ascii
code of the character to be transmitted.
·
So then by just saying Debug.Tx(ascii_code) we are using the BLACK BOX to do what we want.
·
Most objects usually require certain actions for you to START them working (just like for example plugging power to it
and switching on/off some switches). So you have to do that.
·
In Spin many objects have a Start() method that you need to call before you can use the object. So in our example we
would do Debug.Start(31,30,0 115200)…..what does that mean??? Well, in this PARTICULAR CASE it means use the
Pins 31 and 30 for receiving and transmitting and use mode 0 and use the baud rate 115200.
·
But each object has different actions and different starting methods with different required parameters.
·
Likewise each METHOD· (ie. Function or action performing code)· requires parameters and may give back values.
·
So that is it…..objects are really a COLLECTION of subroutines ENCAPSULATED inside a FILE along with any
Variables·and other DATA they need as a group. The variables cannot be accessed from outside the object so in this
way you have achieved hiding the variables.
·
Now many people who are really too STRICT about things may say all sorts of nonsense about Inheritance, Polymorphism,
Overloading and all sorts of JARGON that yes is good stuff and is needed in some situations but is not at all PERTINENT
to the Propeller and SPIN which is a MICROPROCESSOR MICROCONTROLLER and not a computer and thus SPIN
needs to be EFFICIENT and EFFECTIVE and SMALL. Thus all these high-ideals of STRICT OOP are not relevant or
needed and just serve to complicate and BLOAT things and have no place or use in a microcontroller programming language.
·
So to summarize:
SPIN’s objects are files that ENCAPSULATE some variables and Methods (functions or subroutines) that ACCOMPLISH tasks
(e.g send/receive serial data).
·
These files may themselves also use other files.
·
You use the object by giving it a name and indicating what file it is.
·
You utilize the object’s actions by using the object’s name you specified with a Dot and the name of the Method (subroutine/function )
and passing it the right parameters. If the method returns a value (i.e. like a function) then you use the value in an expression just like
any other function.
·
e.g.
·
Debug.Tx(“h”[noparse];)[/noparse]
X := Debug.Rx
·
·
That is all there is to it…..do not get waylaid by unnecessary terms and jargon.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Samuel
www.RobotBASIC.com
Post Edited (SamMishal) : 1/5/2010 9:56:48 PM GMT
subroutines or "Drivers". They are reusable subroutines and drivers in the same languages (spin,pasm) as the
programs, and are separated only for easy re-use. You CAN copy and paste them into a program,
and get the same result but there are many reasons to prefer not to. It seems a lot easier not to,
unless you really want a single-file program, which is my preference too on other platforms, since
I very much dislike relying on dependencies, DLLs, libraries, black boxes, etc. Almost every propeller
object is open source and well commented.
More, or stop reading me now.
Precompiled binaries May be used for Your own convenience,
for example, to use your whole completed programs in PropDOS or femtoBASIC,
without connecting a Propeller to a PC and recompiling them every single time you use them.
In a few cases, unique tools other than Propeller Tool may have been used to generate the code,
so no source exists and Propeller Tool can only program the Propeller with the precompiled binary file.
Some games may have been done that way. These rare exceptions are whole programs, not re-usable objects.
Also, the Hydra drivers were once copyrighted only for the Hydra, and not allowed on the forums,
which may also be why some games are only posted in binary. That restriction has been removed.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Post Edited (Leon) : 1/7/2010 2:33:50 PM GMT
Leon,
I'm not sure about that. For example, on page 10 of the Propeller Education Labs book....
www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf
I've heard people debate this issue in the past. For me, thinking about Objects as subroutines finally made the whole thing sensible... but I'm a slacker from the age of FORTRAN, so I have no idea what people are arguing about when they debate whether or not SPIN is an OOP or precisely what an object is.
I really cannot agree with this point of view. Mathematically functions are something you can apply to one or more variables and produce a result. Functions have a form like r = f(x, y, z). So if the thing you have written does not return a result it is not a function it is only a procedure. Some programming languages do enforce the distinction about that.
Collectively functions and procedures are very similar and end up being called subroutines, functions or procedure interchangeably.
But methods in Spin and more object oriented languages can change the internal state of something, the object to which they belong, that normal procedures cannot. In fact Spin does not really have normal stand alone procedures as we see in Pascal or C etc. So I believe they are more correctly called methods. They define the methods you can apply to an object.
Moving on. we can see a confusion between "object" and "class". Seems to me that when you write a new Spin "object" it actually more correctly called a "class". Why? because you can instantiate many similar objects from it when you use it in your program. In fact until you actually use it there are no objects in existence.
Now of course I think Parallax correctly avoided calling them "classes" as in this modern world of object oriented programming that term has a whole host of other meaning.
I guess they could have called them "templates" but that term is also heavily overloaded now.
All in all I think "objects" and "methods" is just fine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
For object it says:
So far, Parallax is using the word object in the right way. (or maybe it should be class)
Let's take a look at instance:
Now we see that an OOP language should support the creation of instances at runtime. SPIN does not support dynamic memory location by default, so it is not an OOP language. Actually there are not that many microcontrollers that support OOP. One that does: the Javelin Stamp.
Bottom line is that OOP on a microcontroller is not really necessary. It brings along a lot of overhead for a (relatively) small program. (I had a Javelin Stamp and I liked it, very easy to use, but it just isn't fast!)
Did you ever noticed that it is possible to use PHP 5 as an OOP language? php.net/manual/en/language.oop5.php
Post Edited (Robot Freak) : 1/7/2010 7:35:28 PM GMT
Spin is not OOP in any modern sense of the term.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
For sure I can write a C++ program that only has instances of classes created statically when my program is loaded and staying around until it quits. They are still instances of objects generated from classes.
I could argue that the Prop does indeed create instances at run time. Just once after reset when the loader fills memory from EEPROM or download.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
The "class" is the description of the "object".
The "object" is the abstract "thing" (could be anything) that you created.
I think the main reason that Parallax uses "object" for both of them is to keep it easy for the new users.
Using OOP in the right way is not a trivial task at all!
My point is that an OOP language (C++ is one) can also create objects dynamically. SPIN can't do that.
What SPIN -kind of- does, is calling a function with an extra parameter specifying what memory block it should be using now.
OOP languages should also support garbage collection to wipe out the objects and strings that aren't used any more. SPIN doesn't do that. (Javelin Stamp neither)
Post Edited (Robot Freak) : 1/7/2010 7:50:44 PM GMT
I would have said that "class" is the description of all similar objects that can be created from that class. No matter if any objects have actually been created or not. The "class" as a description still stands. That to me is pretty abstract. Like we have "cookie cutters" even if there are no "cookies" yet.
Then to me "object" is not abstract at all. It is what comes into existence as a real pattern in real memory somewhere. It is the "cookie"
It's almost essential to use "object" for both "class" and "instance/object" in Spin. As I say these terms are already overloaded enough in the CS world.
You are for sure right, "Using OOP in the right way is not a trivial task at all".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Java is part of my Electronics study and I liked it a lot, in contradiction to almost all other students who believe that Java is the language of the aliens
I think that is because it was their first programming language (and not mine).
heater,
I'm confused: if I were coffee-machine-based rather than coffee-machine-oriented, would that position me closer to or farther away from the coffee machine?
Then perhaps it's a POOP language: Pseudo Object-Oriented Programming ???
If you were "coffee-machine-oriented" you would always be heading toward a coffee machine[noparse]:)[/noparse]
"POOP" chuckle, that's cruel.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
I was just thinking about the BSoD feature and wondering if it is is patented.
It always seemed to work well for Bill.
I've been to a public demonstration of Windows that emphasized the feature.
How hard Is it to make a "window" with the Graphics object?
Would it's small code size prove it to be Pseudo-Code?
We could probably sell a lot of Propeller apps if they start up with a BSoLife that says,
"General failure reading hard drive..."
"Windows has performed an illegal operation and must be shut down."
"EraserheadBabyVirus Removed. Press any key to continue."
Attitude:Attempted to make up one of those jokes that are extra funny because they are true.
C++, Java et al SHOULD NOT be used as a FIRST languages.....they have served to DISSUADE more people
and drive them away from programming than anything else....but some might argue that that is a good thing.....
·
Teaching BEGINNERS who have never programmed with Java or C++ is a CRIME committed by BENIGHTED
institutions and teachers....A CRIME I SAY.....A CRIME......·
·
I have seen more people running out of programming classes shouting and screaming and pulling their hair and
ducking for cover and not being able to sleep for days afterwards than I have seen in a Psychiatric Ward.
And all due to benighted attempts to teach them Java and C++.·
·
A person who does not know a variable from a function does not need to know about INSTANTIATION,
OVERLOADING, ENCAPSULATION, INHERITANCE, TEMPLATES, and so on and so forth.
·
A person who does not know what a variable is does not appreciate variable scoping.
A person who has not yet written 10 lines of code does not appreciate CLASSES and OBJECTS
and Data Encapsulation and so forth.
·
A person who has to write 100 lines of code and utilize 20 libraries and instantiate 10 classes just to
make a window that has a red square follow the mouse pointer around the screen is going to give up
and say "this is not for me" much quicker than a person who would do the same in 20 lines of code and
THAT IS IT.....
·
Read this document and have a look at two programs that do what I describe above....one is written
in Java (67 lines) and the other in RobotBASIC (17 lines) that do exactly what I described above.
·
Compare the two programs and see which do you think would be more likely to not have 90% of a class
room run out screaming and ducking for cover when you teach them the code.
What you need to teach beginners is a language that can do LOTS of interesting and REWARDING
things that GRAB the ATTENTION and maintain INTEREST as early as possible in the learning
process yet can do all that with as LITTLE as possible of effort and deep understanding.
You do not want to BORE the hapless students to death before they can do a SIMPLE GRAPHICAL
and amusing GAME....... people these days are all about INSTANT GRATIFICATION and very little
desire to put effort into anything.....so if you can satisfy that and keep them in for the long haul until they
are able to appreciate the power and benefits of advanced languages then you have it right.
·
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Samuel
www.RobotBASIC.com
Post Edited (SamMishal) : 1/7/2010 10:54:45 PM GMT
Because what we need is to spoon feed people in tiny chunks so they never have to learn to concentrate or apply themselves to get a result.
Unfortunately I suspect that is a HUGE part of the problem with the up and comers today. Everyone panders to them, so they expect everything broken down into bite sized pieces that they don't have to concentrate on for more than 30 seconds.
It takes away that huge reward at the end when they say "Damn, that was really hard, but I got it to work!".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
I agree, Sam.
I had no problem learning things like FORTRAN, PBASIC, etc. and found it almost fun.
But when I encountered all that business about INSTANTIATION, etc. when trying to learn an OOP one day, I totally choked. And when I encountered the Propeller and heard SPIN was an OOP, I totally balked. Luckily for me, I came across a description of "an Object" in the Propeller Education Manual as being something like a subroutine. Suddenly all my fears of OOPitude fell away and I was able to get a toe hold on SPIN. I'm still a total newb at programming but I'm guessing you have to have something akin to an "ear" for OOPishness to learn an OOP as a first language. The rest of us, however - those of us who number among the unwashed masses who do not possess that OOPish "ear" - are probably best served by the pablum of PBASIC.
ya think?
Heater's interpretation of OOP is a good answer to this thread's topic question. Enjoy, and Happy New Year.
I think this is a very good description of what a SPIN "object" really is. The general lack of documentation and comments in the Object Exchange (OBEX) makes it impossible to run these objects without going through at least some of the code to see how to interface your Main program to them. Without eyeballing the code in most of the objects, you never quite know what the limitations of the objects will be or what sort of values they will return, so they are anything but a "black box". Gray, green, purple, stroboscopic lemon with orange stripes, maybe, but certainly not black.
I have designed a lot of systems even from bootstrap, that is, by burning PROMS by flipping switches, and having both
entirely self-written tool chains and various reasonably programmable computers from the near and distant past.
With that in mind, I consider it an outrageous expectation that this generation should not even be able to program their
own games, and must do more work than it takes to design a fully functional game system, just to produce a small part of
the most boring and redundant and disposable applications and systems yet devised! What is the reward in that, besides
Carpal Tunnel Syndrome? Game programming is more advanced than any other kind, because the programmer must perform
the thrillingly divine act of creating worlds with only language!
Only fools would blame their own children for the world they brought them into.
Besides me, Who would write and share their own dream world on a free 3D display in their own free time?
In what programming environment? MY only choice now is Propeller. Anyone for any OS?
(About 2 years ago I started making a raycaster for Hydra, and it started working as a posted demo,
but then a medical problem interfered.)
It is called a BLACK-BOX·....it is from a crashed airplane and the bright orange box which is the real color
of the data logger for commercial airplanes is called the black box.
If you have a black box that you do not know how to use and you open it up to see what is inside and figure out how to use it
it is still a black box.
A black box is a term used to mean something that is meant to be used without HAVING to know how its internals work....but if
it does not come with a manual or good description of how it should be used then it is a BADLY DOCUMENTED black box....but a
black box nevertheless....since that is the TERM....
Some people have coined the term WHITE-BOX or GLASS-BOX to refer to code that you CAN look into if you want to.....so maybe
SPIN objects can be termed as GLASS-BOXES.....HOWEVER....the idea is that (if they are well documented) you can use them without
having to worry about HOW they do their work just WHAT they do and WHAT they need to be given to do it.....
You are right many of the objects in the OBEX are badly documented....and you DO have to "open up the box" to look inside and
try to figure out how to use it.....
We can only be thankful that·the people who made those GLASS-BOXES have made them and that they are USEFUL, USABLE and FREE....
Moreover....Black or Glass or Gray or whatever...they are Objects and can be used in a Spin program. Also one can make his OWN objects
and use them too..... they are Procedures/Subroutines/Functions + Variables+Data all packaged up and can be used as an OBJECT.
Used Cars used to be called used cars....now they call them PRE-OWNED CARS....that does not make them any less USED
just because their name was made more PC or more MARKETABLE.....they are cars that have been USED by someone else
and are not NEW and you are buying a USED CAR whether you name it a SPACE SHIP or DAISY or anything else you want to
name it...it is a used car.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Samuel
www.RobotBASIC.com
Post Edited (SamMishal) : 1/8/2010 11:06:56 AM GMT
You probably don't remember much about it but as a small child you were not expected to know how to read and write before you could utter your first word(s) and get a positive response from someone. You were not expected to know how to spell or know anything about grammar or even get the pronunciation right. No, a simple "ma-ma", or whatever your first recognizable utterance was, was enough for your parents eyes to light up and cause them to shower you with praise and encouragement. BINGO! you got a positive response, connections were made in your brain, you realized this "sound thing", which you later learned was a language, could be quite useful. Before long you moved on to "I want..", "mine", "telly on" and all those other annoying things kids come out with[noparse]:)[/noparse]
Had your parents responded by reprimanding you for "not making a correct sentence" or "incorrect pronunciation" eventually you may have just given up on the whole idea and remained dumb your entire life.
Sam and I are just proposing that the same baby steps should be available in introducing people, especially the young, to computers and programming.
There are some key concepts in programming. Like variables, assignments, conditionals, loops, subroutines, etc that are the corner stone of the whole thing. When your first programming attempts to get your head around such things are bogged down with compilers, header files, classes, weird syntax etc etc you totally miss the fundamental point of the first lessons. Those indecipherable error messages that come out of C++ or Java on your first mistake are like your mother slapping you around the head when you first uttered "m-ama".
When you first are introduced to the idea of variables, say "A" and "B", and the first idea of what you can do with them say "=" or "+" or "-" and how you can get the result, say "print" what you want is to be able to write is:
A = 2
B = 3
PRINT A + B
and get a result immediately. And nothing else. Many of our, now not so young, career programmers were exactly started off like that with BASIC on a C64 or whatever.
Not long ago my son, aged 11, had that same "wow" feeling when I showed him Python for the first time. He could immediately type simple stuff and get a result. "Amazing", he said, "I have to tell our maths teacher about this". Had we been fighting with editing and compiling even simple C I belive that magic moment would have been lost.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
I used to hold the same views about education as you. However, my experience in teaching people have taught me a few things that made me change my mind about many things.
Heater said ALL I wanted to say and more, so there is no need to repeat it. But here is an anecdote that might illustrate one of the points even more.
I wanted to foster the love of Literature in my nephew by giving him Great Expectations by Charles Dickens when he was 5. I could not for the life of me understand why he did not seem to be enjoying the experience at all. I personally read ALL Dickens' books by the time I was 10. He was even put off reading altogether. Then I gave him a copy of Asterix In Britain by Underzo & Guscinny and he took to those comics like a bookworm and relished reading TinTin by Herg
and that the hard and boring and redundant and proprietary and expensive and expiring "consumable" programming,
while it appears profitable and creates lots of work, is actually a burden to the world,
holding back and rolling back progress.
If the Propeller or Propeller II was made instead of the 8051 in 1980, I think we would have had a Holodeck in 1990,
be on our way to Jupiter from the space station in 2001, making steel and oxygen on Mars now,
and all without Macs or PCs, and most of us would consider 2D video and movies like 8-track tapes.
At least you responded in a manner exceeding my expectations [noparse]:)[/noparse]
Sam you're not a complete idiot obviously.
Good luck staying out of that coffin long enough to propagate your legacy.
Time to move on. I have better things to do.
At least all this great entertainment was not a complete waste of my time.
Good luck to the hobbyists.